Quellcode durchsuchen

Handle English language for blockquotes

master
David Larlet vor 4 Jahren
Ursprung
Commit
be771a47c9
1 geänderte Dateien mit 18 neuen und 1 gelöschten Zeilen
  1. 18
    1
      site.py

+ 18
- 1
site.py Datei anzeigen

@@ -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):

Laden…
Abbrechen
Speichern