From f13d7d907a140cc150e5de0f7d1e9ccea832f4af Mon Sep 17 00:00:00 2001 From: Conner Beckstrand Date: Wed, 29 Apr 2026 03:26:38 -0500 Subject: [PATCH] Fixed - prevents underline from being stripped on whitespaces. --- pydocx/export/html.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pydocx/export/html.py b/pydocx/export/html.py index 18e3ea53..e208ebdd 100644 --- a/pydocx/export/html.py +++ b/pydocx/export/html.py @@ -497,7 +497,17 @@ def export_run_property_underline(self, run, results): 'class': 'pydocx-underline', } tag = HtmlTag('span', **attrs) - return self.export_run_property(tag, run, results) + + # Added function to apply underline to whitespace. + def preserve_spaces(items): + for item in items: + # If the item is only whitespace, convert it to a space entity + if is_only_whitespace(item) and hasattr(item, 'replace'): + yield item.replace(' ', ' ') + else: + yield item + + return self.export_run_property(tag, run, preserve_spaces(results)) def export_run_property_caps(self, run, results): attrs = {