aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2015-02-11 20:35:22 +0000
committerMichael Williamson <mike@zwobble.org>2015-02-11 20:35:22 +0000
commitcf88802a397505ec3644114bfdfa174c43408cef (patch)
tree3933fcef763015ca193ff3a9502f844abfac8260
parentb5b09219daf76bf6dfec7284e7678aa8f8ba1bf8 (diff)
Extract common code for generating HTML IDs
-rw-r--r--mammoth/conversion.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/mammoth/conversion.py b/mammoth/conversion.py
index 0b73eeb..de616ea 100644
--- a/mammoth/conversion.py
+++ b/mammoth/conversion.py
@@ -107,16 +107,15 @@ class DocumentConverter(object):
if hyperlink.anchor is None:
href = hyperlink.href
else:
- href = "#{0}-{1}".format(self._id_prefix, hyperlink.anchor)
+ href = "#{0}".format(self._html_id(hyperlink.anchor))
html_generator.start("a", {"href": href})
self._convert_elements_to_html(hyperlink.children, html_generator)
html_generator.end()
def _convert_bookmark(self, bookmark, html_generator):
- html_generator.start("a", {"id": "{0}-{1}".format(self._id_prefix, bookmark.name)}, always_write=True)
+ html_generator.start("a", {"id": self._html_id(bookmark.name)}, always_write=True)
html_generator.end()
-
def _convert_tab(self, tab, html_generator):
@@ -212,10 +211,13 @@ class DocumentConverter(object):
def _note_html_id(self, note):
- return "{0}-{1}-{2}".format(self._id_prefix, note.note_type, note.note_id)
+ return self._html_id("{0}-{1}".format(note.note_type, note.note_id))
def _note_ref_html_id(self, note):
- return "{0}-{1}-ref-{2}".format(self._id_prefix, note.note_type, note.note_id)
+ 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)
def _document_matcher_matches(matcher, element, element_type):