summaryrefslogtreecommitdiff
path: root/mammoth/conversion.py
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2024-06-13 12:16:25 +0100
committerMichael Williamson <mike@zwobble.org>2024-06-13 12:16:25 +0100
commit4a779b8d4fe83a80d99324a947b714c76468a88f (patch)
tree71e9cd15e8a76beb4d7ec4145234ae70ec4c8dae /mammoth/conversion.py
parent0d5b27652c119dfaf99fae5f4e624c9efec408b5 (diff)
Support style mapping for highlights
Diffstat (limited to 'mammoth/conversion.py')
-rw-r--r--mammoth/conversion.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/mammoth/conversion.py b/mammoth/conversion.py
index bdc8687..33f61cc 100644
--- a/mammoth/conversion.py
+++ b/mammoth/conversion.py
@@ -109,6 +109,10 @@ class _DocumentConverter(documents.element_visitor(args=1)):
def visit_run(self, run, context):
nodes = lambda: self._visit_all(run.children, context)
paths = []
+ if run.highlight is not None:
+ style = self._find_style(Highlight(color=run.highlight), "highlight")
+ if style is not None:
+ paths.append(style.html_path)
if run.is_small_caps:
paths.append(self._find_style_for_run_property("small_caps"))
if run.is_all_caps:
@@ -354,9 +358,19 @@ class _DocumentConverter(documents.element_visitor(args=1)):
return "{0}{1}".format(self._id_prefix, suffix)
+@cobble.data
+class Highlight:
+ color = cobble.field()
+
+
def _document_matcher_matches(matcher, element, element_type):
if matcher.element_type in ["underline", "strikethrough", "all_caps", "small_caps", "bold", "italic", "comment_reference"]:
return matcher.element_type == element_type
+ elif matcher.element_type == "highlight":
+ return (
+ matcher.element_type == element_type and
+ (matcher.color is None or matcher.color == element.color)
+ )
elif matcher.element_type == "break":
return (
matcher.element_type == element_type and