aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mammoth/conversion.py3
-rw-r--r--mammoth/documents.py6
-rw-r--r--mammoth/docx/body_xml.py4
-rw-r--r--tests/docx/body_xml_tests.py6
4 files changed, 19 insertions, 0 deletions
diff --git a/mammoth/conversion.py b/mammoth/conversion.py
index e05cccc..2262392 100644
--- a/mammoth/conversion.py
+++ b/mammoth/conversion.py
@@ -201,6 +201,9 @@ class _DocumentConverter(documents.ElementVisitor):
self._html_generator.append(note_generator)
self._html_generator.end()
+ def visit_comment_reference(self, reference):
+ return []
+
def _visit_all(self, elements):
return lists.flat_map(self.visit, elements)
diff --git a/mammoth/documents.py b/mammoth/documents.py
index 93b080c..5d9830e 100644
--- a/mammoth/documents.py
+++ b/mammoth/documents.py
@@ -182,4 +182,10 @@ class Comment(object):
comment = Comment
+@cobble.data
+class CommentReference(Element):
+ comment_id = cobble.field()
+
+comment_reference = CommentReference
+
ElementVisitor = cobble.visitor(Element)
diff --git a/mammoth/docx/body_xml.py b/mammoth/docx/body_xml.py
index c493c4b..fe75f7c 100644
--- a/mammoth/docx/body_xml.py
+++ b/mammoth/docx/body_xml.py
@@ -334,6 +334,9 @@ def _create_reader(numbering, content_types, relationships, styles, docx_file, f
return note_reference
+ def read_comment_reference(element):
+ return _success(documents.comment_reference(element.attributes["w:id"]))
+
def alternate_content(element):
return read_child_elements(element.find_child("mc:Fallback"))
@@ -364,6 +367,7 @@ def _create_reader(numbering, content_types, relationships, styles, docx_file, f
"v:imagedata": read_imagedata,
"w:footnoteReference": note_reference_reader("footnote"),
"w:endnoteReference": note_reference_reader("endnote"),
+ "w:commentReference": read_comment_reference,
"mc:AlternateContent": alternate_content,
"w:sdt": read_sdt
}
diff --git a/tests/docx/body_xml_tests.py b/tests/docx/body_xml_tests.py
index e35110f..c56cfc5 100644
--- a/tests/docx/body_xml_tests.py
+++ b/tests/docx/body_xml_tests.py
@@ -577,6 +577,12 @@ class ReadXmlElementTests(object):
assert_equal("4", footnote.note_id)
@istest
+ def comment_reference_has_id_read(self):
+ comment_reference_xml = xml_element("w:commentReference", {"w:id": "4"})
+ comment_reference = _read_and_get_document_xml_element(comment_reference_xml)
+ assert_equal(documents.CommentReference("4"), comment_reference)
+
+ @istest
def ignored_elements_are_ignored_without_message(self):
element = xml_element("w:bookmarkEnd")
result = _read_document_xml_element(element)