Explorar el Código

Handle English language for blockquotes

master
David Larlet hace 4 meses
padre
commit
be771a47c9
Se han modificado 1 ficheros con 18 adiciones y 1 borrados
  1. 18
    1
      site.py

+ 18
- 1
site.py Ver fichero

@@ -54,7 +54,24 @@ class MarkRenderer(mistune.HTMLRenderer):
return "<mark>" + text + "</mark>"


class ImgsWithSizesRenderer(MarkRenderer):
class BlockquoteLanguageRenderer(MarkRenderer):
"""Sets the English language attribute for blockquotes with `[en]` prefix."""

def _get_language(self, text):
if text.startswith("<p>[en] "):
return "en", text.replace("<p>[en] ", "<p>")
else:
return None, text

def block_quote(self, text):
language, text = self._get_language(text)
if language:
return f'\n<blockquote lang="{language}">\n{text}</blockquote>\n'
else:
return f"<blockquote>\n{text}</blockquote>\n"


class ImgsWithSizesRenderer(BlockquoteLanguageRenderer):
"""Renders images as <figure>s and add sizes (useful for lazy loading)."""

def paragraph(self, text):

Cargando…
Cancelar
Guardar