summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-07-03 15:35:12 +0100
committerMichael Williamson <mike@zwobble.org>2016-07-03 15:42:11 +0100
commit9ac6745ae4257c8f73c2c5682e1ce74407e1d886 (patch)
tree6a571628cf40500a6f2f42bc22fc627f74194fde
parent92b00aeb4c1d0ab49507cbd4ad9a25e30a1ac724 (diff)
Change formatting of comments to match Word
-rw-r--r--mammoth/conversion.py10
-rw-r--r--tests/conversion_tests.py4
-rw-r--r--tests/mammoth_tests.py8
3 files changed, 13 insertions, 9 deletions
diff --git a/mammoth/conversion.py b/mammoth/conversion.py
index b40b0e2..d58fe6a 100644
--- a/mammoth/conversion.py
+++ b/mammoth/conversion.py
@@ -214,14 +214,14 @@ class _DocumentConverter(documents.ElementVisitor):
comment = self._comments[reference.comment_id]
self._comment_count_by_initials[comment.author_initials] += 1
count = self._comment_count_by_initials[comment.author_initials]
- label = "{0} {1}".format(_comment_author_label(comment), count)
+ label = "[{0}{1}]".format(_comment_author_label(comment), count)
self._referenced_comments.append((label, comment))
return [
# TODO: remove duplication with note references
html.element("a", {
"href": "#" + self._referent_html_id("comment", reference.comment_id),
"id": self._reference_html_id("comment", reference.comment_id),
- }, [html.text("[{0}]".format(label))])
+ }, [html.text(label)])
]
html_path = self._find_html_path(
@@ -244,7 +244,11 @@ class _DocumentConverter(documents.ElementVisitor):
])
]
return [
- html.element("dt", {"id": self._referent_html_id("comment", comment.comment_id)}, [html.text(label)]),
+ html.element(
+ "dt",
+ {"id": self._referent_html_id("comment", comment.comment_id)},
+ [html.text("Comment {0}".format(label))],
+ ),
html.element("dd", {}, body),
]
diff --git a/tests/conversion_tests.py b/tests/conversion_tests.py
index 2aec1c1..74a1d10 100644
--- a/tests/conversion_tests.py
+++ b/tests/conversion_tests.py
@@ -469,8 +469,8 @@ def comment_references_are_linked_to_comment_after_main_body():
],
)
expected_html = (
- '<p>Knock knock<sup><a href="#doc-42-comment-4" id="doc-42-comment-ref-4">[TP 1]</a></sup></p>' +
- '<dl><dt id="doc-42-comment-4">TP 1</dt><dd><p>Who\'s there? <a href="#doc-42-comment-ref-4">↑</a></p></dd></dl>'
+ '<p>Knock knock<sup><a href="#doc-42-comment-4" id="doc-42-comment-ref-4">[TP1]</a></sup></p>' +
+ '<dl><dt id="doc-42-comment-4">Comment [TP1]</dt><dd><p>Who\'s there? <a href="#doc-42-comment-ref-4">↑</a></p></dd></dl>'
)
assert_equal(expected_html, result.value)
diff --git a/tests/mammoth_tests.py b/tests/mammoth_tests.py
index 8ad9b33..4390544 100644
--- a/tests/mammoth_tests.py
+++ b/tests/mammoth_tests.py
@@ -188,10 +188,10 @@ def relationships_are_handled_properly_in_footnotes():
def when_style_mapping_is_defined_for_comment_references_then_comments_are_included():
expected_html = (
'<p>Ouch' +
- '<sup><a href="#doc-42-comment-0" id="doc-42-comment-ref-0">[MW 1]</a></sup>.' +
- '<sup><a href="#doc-42-comment-2" id="doc-42-comment-ref-2">[MW 2]</a></sup></p>' +
- '<dl><dt id="doc-42-comment-0">MW 1</dt><dd><p>A tachyon walks into a bar. <a href="#doc-42-comment-ref-0">↑</a></p></dd>' +
- '<dt id="doc-42-comment-2">MW 2</dt><dd><p>Fin. <a href="#doc-42-comment-ref-2">↑</a></p></dd></dl>'
+ '<sup><a href="#doc-42-comment-0" id="doc-42-comment-ref-0">[MW1]</a></sup>.' +
+ '<sup><a href="#doc-42-comment-2" id="doc-42-comment-ref-2">[MW2]</a></sup></p>' +
+ '<dl><dt id="doc-42-comment-0">Comment [MW1]</dt><dd><p>A tachyon walks into a bar. <a href="#doc-42-comment-ref-0">↑</a></p></dd>' +
+ '<dt id="doc-42-comment-2">Comment [MW2]</dt><dd><p>Fin. <a href="#doc-42-comment-ref-2">↑</a></p></dd></dl>'
)
with open(test_path("comments.docx"), "rb") as fileobj: