File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change 9393blank_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+
96120class HTMLExtractor (htmlparser .HTMLParser ):
97121 """
98122 Extract raw HTML from text.
You can’t perform that action at this time.
0 commit comments