aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mammoth/documents.py15
-rw-r--r--tests/conversion_tests.py19
2 files changed, 31 insertions, 3 deletions
diff --git a/mammoth/documents.py b/mammoth/documents.py
index 5d9830e..2767f86 100644
--- a/mammoth/documents.py
+++ b/mammoth/documents.py
@@ -12,6 +12,7 @@ class HasChildren(Element):
@cobble.data
class Document(HasChildren):
notes = cobble.field()
+ comments = cobble.field()
@cobble.data
class Paragraph(HasChildren):
@@ -68,10 +69,12 @@ class Image(Element):
self.open = open
-def document(children, notes=None):
+def document(children, notes=None, comments=None):
if notes is None:
notes = Notes({})
- return Document(children, notes)
+ if comments is None:
+ comments = []
+ return Document(children, notes, comments=comments)
def paragraph(children, style_id=None, style_name=None, numbering=None):
return Paragraph(children, style_id, style_name, numbering)
@@ -180,7 +183,13 @@ class Comment(object):
author_name = cobble.field()
author_initials = cobble.field()
-comment = Comment
+def comment(comment_id, body, author_name=None, author_initials=None):
+ return Comment(
+ comment_id=comment_id,
+ body=body,
+ author_name=author_name,
+ author_initials=author_initials,
+ )
@cobble.data
class CommentReference(Element):
diff --git a/tests/conversion_tests.py b/tests/conversion_tests.py
index 287d844..0b5421b 100644
--- a/tests/conversion_tests.py
+++ b/tests/conversion_tests.py
@@ -426,6 +426,25 @@ def footnotes_are_included_after_the_main_body():
assert_equal(expected_html, result.value)
+@istest
+def comments_are_ignored_by_default():
+ reference = documents.comment_reference("4")
+ comment = documents.comment(
+ comment_id="4",
+ body=[_paragraph_with_text("Who's there?")],
+ )
+ document = documents.document(
+ [documents.paragraph([
+ _run_with_text("Knock knock"),
+ documents.run([reference])
+ ])],
+ comments=[comment],
+ )
+ result = convert_document_element_to_html(document, id_prefix="doc-42-")
+ expected_html = '<p>Knock knock</p>'
+ assert_equal(expected_html, result.value)
+
+
def _paragraph_with_text(text):
return documents.paragraph(children=[_run_with_text(text)])