mirror of
https://git.sr.ht/~tsileo/microblog.pub
synced 2025-06-05 21:59:23 +02:00
Fix code highlight
This commit is contained in:
@ -16,9 +16,12 @@ def highlight(html: str) -> str:
|
||||
for code in soup.find_all("code"):
|
||||
if not code.parent.name == "pre":
|
||||
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(
|
||||
phighlight(code.text, lexer, _FORMATTER), "html5lib"
|
||||
phighlight(code_content, lexer, _FORMATTER), "html5lib"
|
||||
).body.next
|
||||
pre = code.parent
|
||||
pre.replaceWith(tag)
|
||||
|
Reference in New Issue
Block a user