docx_parser_converter.docx_to_html.converters.style_converter module

class docx_parser_converter.docx_to_html.converters.style_converter.StyleConverter[source]

Bases: object

A converter class for converting DOCX style properties to CSS style attributes.

static convert_all_caps(all_caps: bool) str[source]

Converts the all caps property to CSS style.

static convert_bold(bold: bool) str[source]

Converts bold property to CSS style.

Parameters:

bold (bool) – The bold property.

Returns:

The CSS style string for bold.

Return type:

str

Example

The output style might look like:

font-weight:bold;
static convert_color(color: str) str[source]

Converts color property to CSS style, ensuring hex codes include a ‘#’ and mirroring underline color.

Parameters:

color (str) – The color property.

Returns:

The CSS style string for color.

Return type:

str

Example

The output style might look like:

color:#FF0000;
static convert_doc_margins(margins: DocMargins) str[source]

Converts document margins to CSS style.

Parameters:

margins – The document margins.

Returns:

The CSS style string for document margins.

Return type:

str

Example

The output style might look like:

padding-top:36pt;padding-right:36pt;padding-bottom:36pt;padding-left:36pt;padding-top:18pt;padding-bottom:18pt;margin-left:18pt;
static convert_font(font: FontProperties) str[source]

Converts font properties to CSS style.

Parameters:

font (FontProperties) – The font properties.

Returns:

The CSS style string for font.

Return type:

str

Example

The output style might look like:

font-family:Arial;
static convert_highlight(color: str) str[source]

Converts highlight color to CSS background color.

Parameters:

color (str) – The DOCX highlight value (named color or hex string).

Returns:

The CSS background-color style.

Return type:

str

static convert_indent(indent: IndentationProperties) str[source]

Converts indentation properties to CSS style.

Parameters:

indent (IndentationProperties) – The indentation properties.

Returns:

The CSS style string for indentation.

Return type:

str

Example

The output style might look like:

margin-left:36pt;margin-right:36pt;text-indent:36pt;
static convert_italic(italic: bool) str[source]

Converts italic property to CSS style.

Parameters:

italic (bool) – The italic property.

Returns:

The CSS style string for italic.

Return type:

str

Example

The output style might look like:

font-style:italic;
static convert_justification(justification: str) str[source]

Converts justification property to CSS style.

Parameters:

justification (str) – The justification property.

Returns:

The CSS style string for justification.

Return type:

str

Example

The output style might look like:

text-align:left;
static convert_size(size_pt: float) str[source]

Converts font size property to CSS style.

Parameters:

size_pt (float) – The font size in points.

Returns:

The CSS style string for font size.

Return type:

str

Example

The output style might look like:

font-size:12pt;
static convert_small_caps(small_caps: bool) str[source]

Converts the small caps property to CSS style.

static convert_spacing(spacing: SpacingProperties) str[source]

Converts spacing properties to CSS style.

Parameters:

spacing (SpacingProperties) – The spacing properties.

Returns:

The CSS style string for spacing.

Return type:

str

Example

The output style might look like:

margin-top:12pt;margin-bottom:12pt;line-height:18pt;
static convert_text_position(offset_pt: float) str[source]

Converts DOCX text position (baseline shift) to CSS relative positioning.

static convert_underline(underline: str | None, strikethrough: bool = False, double_strikethrough: bool = False) str[source]

Converts underline and strikethrough properties to CSS style, mapping ST_Underline values to CSS equivalents and optionally combining strikethrough settings.

Parameters:
  • underline (Optional[str]) – The underline property.

  • strikethrough (bool) – Whether strikethrough should be applied.

  • double_strikethrough (bool) – Whether double strikethrough should be applied.

Returns:

The CSS style string for text decoration.

Return type:

str

static convert_underline_color(color: str) str[source]

Converts an explicit underline color to CSS style.

static convert_vertical_align(vertical_align: str | None, text_position_pt: float | None = None) str[source]

Converts DOCX vertical alignment values (superscript/subscript) to CSS. Falls back to the legacy text-position baseline shift when no vertical-align CSS is produced.