summaryrefslogtreecommitdiff
path: root/mammoth/writers
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2015-02-08 20:28:13 +0000
committerMichael Williamson <mike@zwobble.org>2015-02-08 20:28:13 +0000
commit7aa2d2ba54ab0c2d908a4b0fbe683bce63a54f45 (patch)
tree572487ee14ab32bedad7106384cab549b98f2830 /mammoth/writers
parentd23efd5811e1ebeae915fdfb2cd8e8ede6b0f0ca (diff)
Insert anchor tags when elements have IDs in markdown writer
Diffstat (limited to 'mammoth/writers')
-rw-r--r--mammoth/writers/markdown.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/mammoth/writers/markdown.py b/mammoth/writers/markdown.py
index 771874c..07b5fc1 100644
--- a/mammoth/writers/markdown.py
+++ b/mammoth/writers/markdown.py
@@ -58,6 +58,7 @@ class MarkdownWriter(object):
start, end = _writers.get(name, _default_writer)(attributes)
self._fragments.append(start)
+ self._write_anchor(attributes)
self._element_stack.append(end)
def end(self, name):
@@ -73,6 +74,11 @@ class MarkdownWriter(object):
def as_string(self):
return "".join(self._fragments)
+
+ def _write_anchor(self, attributes):
+ html_id = attributes.get("id")
+ if html_id:
+ self._fragments.append('<a id="{0}"></a>'.format(html_id))
def _escape_markdown(value):