diff --git a/html_attribute.py b/html_attribute.py index 9a258e4..cf0bb51 100644 --- a/html_attribute.py +++ b/html_attribute.py @@ -9,6 +9,7 @@ import markdown from markdown import postprocessors +from markdown import serializers import xml.etree.ElementTree as etree @@ -312,6 +313,17 @@ def _add_meta(self, element): element.remove(e) element.append(body) + def _tohtml(self, element): + # return etree.tostring(root, encoding="unicode", method="xml") + # return etree.tostring(root, encoding="unicode", method="html") + old_RE_AMP = serializers.RE_AMP + try: + serializers.RE_AMP = re.compile(r'&') + output = self._markdown.serializer(element) + finally: + serializers.RE_AMP = old_RE_AMP + return output + def run(self, text): text = '<{tag}>{text}'.format(tag=self._markdown.doc_tag, text=text) try: @@ -328,7 +340,7 @@ def run(self, text): self._iterate(root, self._adjust_url) self._add_meta(root) - output = etree.tostring(root, encoding="unicode", method="xml") + output = self._tohtml(root) if self._markdown.stripTopLevelTags: try: start = output.index('<%s>' % self._markdown.doc_tag) + len(self._markdown.doc_tag) + 2