diff options
| -rw-r--r-- | NEWS | 2 | ||||
| -rw-r--r-- | mammoth/conversion.py | 2 | ||||
| -rw-r--r-- | tests/conversion_tests.py | 8 | ||||
| -rw-r--r-- | tests/mammoth_tests.py | 6 |
4 files changed, 10 insertions, 8 deletions
@@ -2,6 +2,8 @@ * Remove deprecated convert_underline argument. +* Generated IDs no longer insert a hyphen after the ID prefix. + * The default ID prefix is now the empty string rather than a random number followed by a hyphen. diff --git a/mammoth/conversion.py b/mammoth/conversion.py index 8a5766c..8fe6e4e 100644 --- a/mammoth/conversion.py +++ b/mammoth/conversion.py @@ -235,7 +235,7 @@ class _DocumentConverter(documents.ElementVisitor): return self._html_id("{0}-ref-{1}".format(note.note_type, note.note_id)) def _html_id(self, suffix): - return "{0}-{1}".format(self._id_prefix, suffix) + return "{0}{1}".format(self._id_prefix, suffix) def _document_matcher_matches(matcher, element, element_type): diff --git a/tests/conversion_tests.py b/tests/conversion_tests.py index cc7f97b..0ffee8e 100644 --- a/tests/conversion_tests.py +++ b/tests/conversion_tests.py @@ -274,7 +274,7 @@ def docx_hyperlink_with_href_is_converted_to_anchor_tag(): def docx_hyperlink_with_internal_anchor_reference_is_converted_to_anchor_tag(): result = convert_document_element_to_html( documents.hyperlink(anchor="start", children=[documents.Text("Hello")]), - id_prefix="doc-42", + id_prefix="doc-42-", ) assert_equal('<a href="#doc-42-start">Hello</a>', result.value) @@ -283,7 +283,7 @@ def docx_hyperlink_with_internal_anchor_reference_is_converted_to_anchor_tag(): def bookmarks_are_converted_to_anchors_with_ids(): result = convert_document_element_to_html( documents.bookmark(name="start"), - id_prefix="doc-42", + id_prefix="doc-42-", ) assert_equal('<a id="doc-42-start"></a>', result.value) @@ -369,7 +369,7 @@ def footnote_reference_is_converted_to_superscript_intra_page_link(): footnote_reference = documents.note_reference("footnote", "4") result = convert_document_element_to_html( footnote_reference, - id_prefix="doc-42" + id_prefix="doc-42-" ) assert_equal('<sup><a href="#doc-42-footnote-4" id="doc-42-footnote-ref-4">[1]</a></sup>', result.value) @@ -388,7 +388,7 @@ def footnotes_are_included_after_the_main_body(): ) result = convert_document_element_to_html( document, - id_prefix="doc-42" + id_prefix="doc-42-" ) expected_html = ('<p>Knock knock<sup><a href="#doc-42-footnote-4" id="doc-42-footnote-ref-4">[1]</a></sup></p>' + '<ol><li id="doc-42-footnote-4"><p>Who\'s there? <a href="#doc-42-footnote-ref-4">↑</a></p></li></ol>') diff --git a/tests/mammoth_tests.py b/tests/mammoth_tests.py index 1b97a1a..201df70 100644 --- a/tests/mammoth_tests.py +++ b/tests/mammoth_tests.py @@ -153,7 +153,7 @@ def footnotes_are_appended_to_text(): '<li id="doc-42-footnote-2"><p> Fin. <a href="#doc-42-footnote-ref-2">↑</a></p></li></ol>') with open(test_path("footnotes.docx"), "rb") as fileobj: - result = mammoth.convert_to_html(fileobj=fileobj, id_prefix="doc-42") + result = mammoth.convert_to_html(fileobj=fileobj, id_prefix="doc-42-") assert_equal([], result.messages) assert_equal(expected_html, result.value) @@ -167,7 +167,7 @@ def endnotes_are_appended_to_text(): '<li id="doc-42-endnote-3"><p> Fin. <a href="#doc-42-endnote-ref-3">↑</a></p></li></ol>') with open(test_path("endnotes.docx"), "rb") as fileobj: - result = mammoth.convert_to_html(fileobj=fileobj, id_prefix="doc-42") + result = mammoth.convert_to_html(fileobj=fileobj, id_prefix="doc-42-") assert_equal([], result.messages) assert_equal(expected_html, result.value) @@ -179,7 +179,7 @@ def relationships_are_handled_properly_in_footnotes(): '<ol><li id="doc-42-footnote-1"><p> <a href="http://www.example.com">Example</a> <a href="#doc-42-footnote-ref-1">↑</a></p></li></ol>') with open(test_path("footnote-hyperlink.docx"), "rb") as fileobj: - result = mammoth.convert_to_html(fileobj=fileobj, id_prefix="doc-42") + result = mammoth.convert_to_html(fileobj=fileobj, id_prefix="doc-42-") assert_equal([], result.messages) assert_equal(expected_html, result.value) |
