Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,26 @@ Release History
**Updates**

- Fix Pypi Workflow.
- [`PR #48 <https://github.com/dfop02/html4docx/pull/48>`_] Add support for common CSS properties on text for: <h>, <p> and <span> | `Lynuxen <https://github.com/Lynuxen>`_

**Fixes**

- None
- Fixes `#46 <https://github.com/dfop02/html4docx/issues/46>`_: background-color style property highlights the whole paragraph instead of a single word
- Fixes `#47 <https://github.com/dfop02/html4docx/issues/47>`_: text-decoration style property for underline is not applied

**New Features**

- Add support for HTML Comments. | [Dfop02](https://github.com/dfop02)
- Add support for text-align,line-height, margin-left, margin-right, text-indent for paragraphs
- Add support for the following text properties (applies to \<span\>, \<p\> and \<h\> tags):
- font-weight: ('bold', 'bolder', '700', '800', '900', 'normal', 'lighter', '400', '300', '100')
- font-style: ('italic', 'oblique', 'normal'')
- text-decoration: ('underline', 'line-through') ('solid', 'double', 'dotted', 'dashed', 'wavy'), and the longhand properties (text-decoration-*)
- text-transform: ('uppercase', 'lowercase', 'capitalize')
- font-size
- font-family
- color
- background-color: Paragraph and run highlight colors can now differ. Partial support on what can be used as a color.


1.1.0 (2025-11-01)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ My goal in forking and fixing/updating this package was to complete my current t
- Fix Ordered and Unordered Lists | [TaylorN15](https://github.com/TaylorN15) from [PR](https://github.com/dfop02/html4docx/pull/16)
- Fixed styles was only being applied to span tag. | [Dfop02](https://github.com/dfop02) from [PR](https://github.com/dfop02/html4docx/issues/40)
- Fixed bug on styles parsing when style contains multiple colon. | [Dfop02](https://github.com/dfop02)
- Fixed highlighting a single word | [Lynuxen](https://github.com/Lynuxen)

**New Features**
- Add Witdh/Height style to images | [maifeeulasad](https://github.com/maifeeulasad) from [PR](https://github.com/pqzx/html2docx/pull/29)
Expand All @@ -202,6 +203,7 @@ My goal in forking and fixing/updating this package was to complete my current t
- Add support to table cells style (border, background-color, width, height, margin) | [Dfop02](https://github.com/dfop02)
- Being able to use inline images on same paragraph. | [Dfop02](https://github.com/dfop02)
- Refactory Tests to be more consistent and less 'human validation' | [Dfop02](https://github.com/dfop02)
- Support for common CSS properties for text | [Lynuxen](https://github.com/Lynuxen)

## Known Issues

Expand Down
61 changes: 60 additions & 1 deletion html4docx/constants.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# values in inches
from docx.enum.text import WD_UNDERLINE

INDENT = 0.25
LIST_INDENT = 0.5
MAX_INDENT = 5.5 # To stop indents going off the page
MAX_INDENT = 5.5 # To stop indents going off the page

# Style to use with tables. By default no style is used.
DEFAULT_TABLE_STYLE = None
Expand Down Expand Up @@ -48,6 +50,19 @@
'xx-large': '32px'
}

FONT_UNDERLINE = {
'underline',
'line-through',
}

FONT_UNDERLINE_STYLES = {
'solid': WD_UNDERLINE.SINGLE,
'dashed': WD_UNDERLINE.DASH,
'dotted': WD_UNDERLINE.DOTTED,
'wavy': WD_UNDERLINE.WAVY,
'double': WD_UNDERLINE.DOUBLE,
}

STYLES = {
'ul': 'List Bullet',
'ul2': 'List Bullet 2',
Expand Down Expand Up @@ -79,6 +94,50 @@
'0': '0px',
}

GENERIC_FONT_STYLES = {
'serif': 'Times New Roman',
'sans-serif': 'Arial',
'monospace': 'Courier New'
}

# Paragraph-level styles (ParagraphFormat)
PARAGRAPH_FORMAT_STYLES = {
'text-align': '_apply_alignment_paragraph',
'line-height': '_apply_line_height_paragraph',
'margin-left': '_apply_margins_paragraph',
'margin-right': '_apply_margins_paragraph',
'text-indent': '_apply_text_indent_paragraph',
}

# Run-level styles (affect text formatting within runs)
PARAGRAPH_RUN_STYLES = {
'font-weight': '_apply_font_weight_paragraph',
'font-style': '_apply_font_style_paragraph',
'text-decoration': '_apply_text_decoration_paragraph',
'text-decoration-line': '_apply_text_decoration_paragraph',
'text-decoration-style': '_apply_text_decoration_paragraph',
'text-decoration-color': '_apply_text_decoration_paragraph',
'text-transform': '_apply_text_transform_paragraph',
'font-size': '_apply_font_size_paragraph',
'font-family': '_apply_font_family_paragraph',
'color': '_apply_color_paragraph',
'background-color': '_apply_background_color_paragraph'
}

RUN_STYLES = {
'font-weight': '_apply_font_weight_to_run',
'font-style': '_apply_font_style_to_run',
'text-decoration': '_apply_text_decoration_to_run',
'text-decoration-line': '_apply_text_decoration_line_to_run',
'text-decoration-style': '_apply_text_decoration_style_to_run',
'text-decoration-color': '_apply_text_decoration_color_to_run',
'text-transform': '_apply_text_transform_to_run',
'font-size': '_apply_font_size_to_run',
'font-family': '_apply_font_family_to_run',
'color': '_apply_color_to_run',
'background-color': '_apply_background_color_to_run'
}

def default_borders():
return {
"top": {"size": DEFAULT_BORDER_SIZE, "color": DEFAULT_BORDER_COLOR, "style": DEFAULT_BORDER_STYLE},
Expand Down
Loading