NLdoc.Conversion.Reader.Docx.AST.RunProperties.Highlight (NLdoc.Conversion.Reader.Docx v1.5.5)

View Source

Normalizes DOCX w:highlight values (ECMA-376 ST_HighlightColor) to an internal representation and exposes their RGB hex values.

This module is responsible for:

  • Parsing raw w:val strings from run properties (e.g. "yellow", "darkBlue", "none") to internal atoms via t/0 using parse/1.
  • Converting those atoms to lowercase RGB hex strings (or nil for :none) via to_hex/1, for use in downstream rendering or style normalization.

Invalid or unknown highlight values are mapped to nil by parse/1, allowing callers to treat them as “no highlight” or handle them explicitly upstream.

Summary

Functions

Parses an ST_HighlightColor string value to its internal atom representation.

Returns the lowercase hex RGB value for a highlight atom, or nil for :none.

Types

t()

@type t() ::
  :none
  | :black
  | :blue
  | :cyan
  | :green
  | :magenta
  | :red
  | :yellow
  | :white
  | :dark_blue
  | :dark_cyan
  | :dark_green
  | :dark_magenta
  | :dark_red
  | :dark_yellow
  | :dark_gray
  | :light_gray

Functions

parse(color)

@spec parse(color :: term()) :: t() | nil

Parses an ST_HighlightColor string value to its internal atom representation.

Examples

iex> alias NLdoc.Conversion.Reader.Docx.AST.RunProperties.Highlight
iex> Highlight.parse("yellow")
:yellow
iex> Highlight.parse("not-a-color")
nil

to_hex(atom)

@spec to_hex(highlight :: t() | nil) :: String.t() | nil

Returns the lowercase hex RGB value for a highlight atom, or nil for :none.

Examples

iex> alias NLdoc.Conversion.Reader.Docx.AST.RunProperties.Highlight
iex> Highlight.to_hex(:none)
nil
iex> Highlight.to_hex(:black)
"#000000"
iex> Highlight.to_hex(:blue)
"#0000ff"
iex> Highlight.to_hex(:cyan)
"#00ffff"
iex> Highlight.to_hex(:green)
"#00ff00"
iex> Highlight.to_hex(:magenta)
"#ff00ff"
iex> Highlight.to_hex(:red)
"#ff0000"
iex> Highlight.to_hex(:yellow)
"#ffff00"
iex> Highlight.to_hex(:white)
"#ffffff"
iex> Highlight.to_hex(:dark_blue)
"#000080"
iex> Highlight.to_hex(:dark_cyan)
"#008080"
iex> Highlight.to_hex(:dark_green)
"#008000"
iex> Highlight.to_hex(:dark_magenta)
"#800080"
iex> Highlight.to_hex(:dark_red)
"#800000"
iex> Highlight.to_hex(:dark_yellow)
"#808000"
iex> Highlight.to_hex(:dark_gray)
"#808080"
iex> Highlight.to_hex(:light_gray)
"#c0c0c0"