refactor: make _MarkdownDocument inherit from content

This commit is contained in:
Corentin 2024-05-21 23:42:51 +02:00
parent cb2d41d571
commit 35454bfc0f
3 changed files with 4 additions and 8 deletions

View File

@ -10,7 +10,7 @@ def load_extension(context: Context) -> None:
context.add_filters(markdown=_MarkdownDocument) context.add_filters(markdown=_MarkdownDocument)
class _MarkdownDocument: class _MarkdownDocument(Content[str]):
def __init__(self, content: Content[Any]) -> None: def __init__(self, content: Content[Any]) -> None:
if not isinstance(content, Content) or not isinstance(content.data, (str, bytes)): if not isinstance(content, Content) or not isinstance(content.data, (str, bytes)):
raise ValueError("markdown filter can only accept byte or string content") raise ValueError("markdown filter can only accept byte or string content")
@ -23,11 +23,7 @@ class _MarkdownDocument:
self.__content = content self.__content = content
self.__markdown = Markdown(extensions=["full_yaml_metadata"]) self.__markdown = Markdown(extensions=["full_yaml_metadata"])
self.__html = self.__markdown.convert(data) super().__init__(content.path, self.__markdown.convert(data), content.language)
@property
def html(self) -> str:
return self.__html
@property @property
def meta(self) -> Any: def meta(self) -> Any:

View File

@ -1,4 +1,4 @@
{% with document = content | markdown %} {% with document = content | markdown %}
{{- document.html }} {{- document }}
{%- endwith -%} {%- endwith -%}

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PROJECT VERSION\n" "Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-05-21 23:32+0200\n" "POT-Creation-Date: 2024-05-21 23:42+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: fr\n" "Language: fr\n"