Browse Source

Handle English language for blockquotes

master
David Larlet 4 years ago
parent
commit
be771a47c9
1 changed files with 18 additions and 1 deletions
  1. 18
    1
      site.py

+ 18
- 1
site.py View File

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

Loading…
Cancel
Save