From aadf7a1a2318bf022c3b6d787168cf312e86e138 Mon Sep 17 00:00:00 2001 From: Arthur Souza Rodrigues Date: Thu, 8 Jan 2026 22:30:32 -0500 Subject: [PATCH] feat: add support for (highlight) and (underline) tags Adds support for two HTML5 semantic elements: 1. tag - represents inserted text, rendered with underline - Added to FONT_STYLES mapping to 'underline' (same as ) 2. tag - represents highlighted text, rendered with yellow background - Uses w:shd shading element with yellow (#FFFF00) fill color - Consistent with the package's existing background-color mechanism These tags are commonly used in markdown-to-HTML converters and document editing applications. --- html4docx/constants.py | 1 + html4docx/h4d.py | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/html4docx/constants.py b/html4docx/constants.py index 2638462..0c1b410 100644 --- a/html4docx/constants.py +++ b/html4docx/constants.py @@ -31,6 +31,7 @@ 'em': 'italic', 'i': 'italic', 'u': 'underline', + 'ins': 'underline', # HTML5 insertion element - underline like 's': 'strike', 'sup': 'superscript', 'sub': 'subscript', diff --git a/html4docx/h4d.py b/html4docx/h4d.py index 5184e16..ef758ba 100644 --- a/html4docx/h4d.py +++ b/html4docx/h4d.py @@ -1681,6 +1681,19 @@ def handle_data(self, data): font_name = constants.FONT_NAMES[tag] self.run.font.name = font_name + # Handle tag with yellow background highlight + if tag == 'mark': + shd = OxmlElement('w:shd') + shd.set(qn('w:val'), 'clear') + shd.set(qn('w:color'), 'auto') + shd.set(qn('w:fill'), 'FFFF00') # Yellow - default color + r_pr = self.run._element.get_or_add_rPr() + # Remove existing shading if present + existing_shd = r_pr.find(qn('w:shd')) + if existing_shd is not None: + r_pr.remove(existing_shd) + r_pr.append(shd) + if 'style' in attrs and (tag in ['div', 'li', 'pre']): style = utils.parse_dict_string(attrs['style']) self.add_styles_to_run(style)