Fix code highlight
parent
368dd30e8f
commit
4080d1432e
|
@ -66,6 +66,7 @@ _RESIZED_CACHE: MutableMapping[tuple[str, int], tuple[bytes, str, Any]] = LFUCac
|
||||||
# TODO(ts):
|
# TODO(ts):
|
||||||
#
|
#
|
||||||
# Next:
|
# Next:
|
||||||
|
# - DB models for webmentions
|
||||||
# - allow to undo follow requests
|
# - allow to undo follow requests
|
||||||
# - indieauth tweaks
|
# - indieauth tweaks
|
||||||
# - API for posting notes
|
# - API for posting notes
|
||||||
|
|
|
@ -16,9 +16,12 @@ def highlight(html: str) -> str:
|
||||||
for code in soup.find_all("code"):
|
for code in soup.find_all("code"):
|
||||||
if not code.parent.name == "pre":
|
if not code.parent.name == "pre":
|
||||||
continue
|
continue
|
||||||
lexer = guess_lexer(code.text)
|
code_content = (
|
||||||
|
code.encode_contents().decode().replace("<br>", "\n").replace("<br/>", "\n")
|
||||||
|
)
|
||||||
|
lexer = guess_lexer(code_content)
|
||||||
tag = BeautifulSoup(
|
tag = BeautifulSoup(
|
||||||
phighlight(code.text, lexer, _FORMATTER), "html5lib"
|
phighlight(code_content, lexer, _FORMATTER), "html5lib"
|
||||||
).body.next
|
).body.next
|
||||||
pre = code.parent
|
pre = code.parent
|
||||||
pre.replaceWith(tag)
|
pre.replaceWith(tag)
|
||||||
|
|
Loading…
Reference in New Issue