瀏覽代碼

Handle English language for blockquotes

master
David Larlet 4 月之前
父節點
當前提交
be771a47c9
共有 1 個文件被更改,包括 18 次插入1 次删除
  1. 18
    1
      site.py

+ 18
- 1
site.py 查看文件

@@ -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…
取消
儲存