aboutsummaryrefslogtreecommitdiff
path: root/mammoth
diff options
context:
space:
mode:
Diffstat (limited to 'mammoth')
-rw-r--r--mammoth/conversion.py15
-rw-r--r--mammoth/document_matchers.py4
-rw-r--r--mammoth/style_reader/document_matcher_reader.py6
3 files changed, 21 insertions, 4 deletions
diff --git a/mammoth/conversion.py b/mammoth/conversion.py
index c4631e1..71edaf4 100644
--- a/mammoth/conversion.py
+++ b/mammoth/conversion.py
@@ -100,7 +100,7 @@ class DocumentConverter(object):
if run.is_underline:
self._convert_underline(run_generator)
if run.is_strikethrough:
- run_generator.start("s")
+ self._convert_strikethrough(run_generator)
self._convert_elements_to_html(run.children, run_generator)
run_generator.end_all()
html_generator.append(run_generator)
@@ -111,6 +111,15 @@ class DocumentConverter(object):
if style is not None:
append_html_path(run_generator, style.html_path)
+
+ def _convert_strikethrough(self, run_generator):
+ style = self._find_style(None, "strikethrough")
+ if style is None:
+ run_generator.start("s")
+ else:
+ append_html_path(run_generator, style.html_path)
+
+
def _convert_text(self, text, html_generator):
html_generator.text(text.value)
@@ -238,8 +247,8 @@ class DocumentConverter(object):
def _document_matcher_matches(matcher, element, element_type):
- if matcher.element_type == "underline":
- return element_type == "underline"
+ if matcher.element_type in ["underline", "strikethrough"]:
+ return matcher.element_type == element_type
else:
return (
matcher.element_type == element_type and (
diff --git a/mammoth/document_matchers.py b/mammoth/document_matchers.py
index 07d5be2..9f05a8e 100644
--- a/mammoth/document_matchers.py
+++ b/mammoth/document_matchers.py
@@ -19,3 +19,7 @@ RunMatcher.element_type = "run"
class underline(object):
element_type = "underline"
+
+
+class strikethrough(object):
+ element_type = "strikethrough"
diff --git a/mammoth/style_reader/document_matcher_reader.py b/mammoth/style_reader/document_matcher_reader.py
index 56c4626..04a26c0 100644
--- a/mammoth/style_reader/document_matcher_reader.py
+++ b/mammoth/style_reader/document_matcher_reader.py
@@ -16,6 +16,8 @@ def read_document_matcher_node(root_node):
return _read_run_node(element_node)
elif element_node.expr_name == "underline":
return document_matchers.underline
+ elif element_node.expr_name == "strikethrough":
+ return document_matchers.strikethrough
def _read_paragraph_node(paragraph_node):
@@ -55,10 +57,12 @@ def _read_list_node(list_node):
return None
grammar_text = r"""
-document_matcher = paragraph / run / underline
+document_matcher = paragraph / run / underline / strikethrough
underline = "u"
+strikethrough = "strike"
+
paragraph = "p" style_id? style_name_specifier? list?
run = "r" style_id? style_name_specifier?