update @ Thu Dec 19 02:30:32 EET 2024

Signed-off-by: Ari Archer <ari@ari.lt>
This commit is contained in:
Arija A. 2024-12-19 02:30:32 +02:00
parent e84c4086a4
commit cebf073902
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG key ID: A50D5B4B599AF8A2
2 changed files with 9 additions and 4 deletions

File diff suppressed because one or more lines are too long

View file

@ -32,7 +32,7 @@ from mistune.renderers.html import HTMLRenderer
from mistune.util import safe_entity from mistune.util import safe_entity
from pygments import highlight from pygments import highlight
from pygments.formatters import HtmlFormatter, html from pygments.formatters import HtmlFormatter, html
from pygments.lexers import get_lexer_by_name, guess_lexer from pygments.lexers import get_lexer_by_name, guess_lexer, TextLexer
from readtime import of_markdown as read_time_of_markdown # type: ignore from readtime import of_markdown as read_time_of_markdown # type: ignore
from readtime.result import Result as MarkdownResult # type: ignore from readtime.result import Result as MarkdownResult # type: ignore
@ -888,9 +888,14 @@ class BlogRenderer(HTMLRenderer):
return f'<audio controls title="{mistune.escape(alt)}"> <source src="{text}" type="{type}" {alt} /> </audio>' return f'<audio controls title="{mistune.escape(alt)}"> <source src="{text}" type="{type}" {alt} /> </audio>'
def block_code(self, code: str, info: typing.Optional[str] = None) -> str: def block_code(self, code: str, info: typing.Optional[str] = None) -> str:
try:
lexer = get_lexer_by_name(info) if info else guess_lexer(code)
except Exception:
lexer = TextLexer()
return highlight( return highlight(
code, code,
get_lexer_by_name(info) if info else guess_lexer(code), lexer,
HtmlFormatter(linenos="table", linenostart=1), HtmlFormatter(linenos="table", linenostart=1),
) )