Skip to content

Commit

Permalink
html_attribute: "serializers.RE_AMP" を弄って試行錯誤
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Nov 20, 2024
1 parent f4d5657 commit 6ce6118
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion html_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import markdown
from markdown import postprocessors
from markdown import serializers

import xml.etree.ElementTree as etree

Expand Down Expand Up @@ -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}</{tag}>'.format(tag=self._markdown.doc_tag, text=text)
try:
Expand All @@ -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
Expand Down

0 comments on commit 6ce6118

Please sign in to comment.