From 7aa2d2ba54ab0c2d908a4b0fbe683bce63a54f45 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 8 Feb 2015 20:28:13 +0000 Subject: Insert anchor tags when elements have IDs in markdown writer --- mammoth/writers/markdown.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'mammoth') 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(''.format(html_id)) def _escape_markdown(value): -- cgit v1.2.3