Commit 3ae5f072ee3ea0f39d54a7c8a9bc275034f3b4d0

Authored by Miguel Barão
1 parent 939be670
Exists in dev

update to new mistune 3.0.0rc4

Showing 1 changed file with 27 additions and 0 deletions   Show diff stats
aprendizations/renderer_markdown.py 0 → 100644
... ... @@ -0,0 +1,27 @@
  1 +
  2 +# third party libraries
  3 +import mistune
  4 +from mistune.plugins.math import math
  5 +
  6 +from pygments import highlight
  7 +from pygments.lexers import get_lexer_by_name
  8 +# from pygments.formatters import HtmlFormatter
  9 +from pygments.formatters import html
  10 +
  11 +class HighlightRenderer(mistune.HTMLRenderer):
  12 + def block_code(self, code, info=None):
  13 + if info:
  14 + lexer = get_lexer_by_name(info, stripall=True)
  15 + formatter = html.HtmlFormatter()
  16 + return highlight(code, lexer, formatter)
  17 + return '<pre><code>' + mistune.escape(code) + '</code></pre>'
  18 +
  19 + def image(self, text, url, title=None):
  20 + text = mistune.escape(text, quote=True)
  21 + title = mistune.escape(title or '', quote=True)
  22 + return (f'<img src="/file/{url}" alt="{text}" title="{title}"'
  23 + f'class="img-fluid">')
  24 +
  25 +md_to_html = mistune.create_markdown(renderer=HighlightRenderer(), plugins=[math])
  26 +# FIXME error "argument HighlightRenderer cannot be assigned to parameter
  27 +# renderer of type str. HighlightRenderer is incimpatible with str"
... ...