Skip to content

Commit ca73a6d

Browse files
committed
Add a hack so we don't break MkDocs
1 parent cc9865c commit ca73a6d

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

markdown/htmlparser.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,30 @@
9393
blank_line_re = re.compile(r'^([ ]*\n){2}')
9494

9595

96+
class _HTMLParser(htmlparser.HTMLParser):
97+
"""Handle special start and end tags."""
98+
99+
def parse_endtag(self, i):
100+
start = self.rawdata[i:i+3]
101+
c = ord(start[-1])
102+
if len(start) < 3 or not (65 <= c <= 90 or 97 <= c <= 122):
103+
self.handle_data(self.rawdata[i:i + 2])
104+
return i + 2
105+
return super().parse_endtag(i)
106+
107+
def parse_starttag(self, i: int) -> int: # pragma: no cover
108+
# Treat `</>` as normal data as it is not a real tag.
109+
if self.rawdata[i:i + 3] == '</>':
110+
self.handle_data(self.rawdata[i:i + 3])
111+
return i + 3
112+
113+
return super().parse_starttag(i)
114+
115+
116+
# Overwrite our custom one for people like MkDocs that pull it in
117+
htmlparser.HTMLParser = _HTMLParser
118+
119+
96120
class HTMLExtractor(htmlparser.HTMLParser):
97121
"""
98122
Extract raw HTML from text.

0 commit comments

Comments
 (0)