diff --git a/memium/destination/ankiconnect/anki_prompt.py b/memium/destination/ankiconnect/anki_prompt.py index fa1fb13..45bee6b 100644 --- a/memium/destination/ankiconnect/anki_prompt.py +++ b/memium/destination/ankiconnect/anki_prompt.py @@ -4,7 +4,7 @@ import genanki -from memium.utils.markdown_parser import markdown_parser +from memium.utils.markdown_parser import to_html @dataclass(frozen=True) @@ -14,8 +14,8 @@ class AnkiPrompt(ABC): uuid: int # UUID is a unique identifier for the prompt, used for scheduling. If a new prompt is added with the same uuid, it will be treated as an update to the existing prompt. Otherwise, they will be interpreted as separate prompts. edit_url: str | None - def _field_to_markdown(self, field: str) -> str: - return markdown_parser(field) + def _to_html(self, field: str) -> str: + return to_html(field) @property @abstractmethod diff --git a/memium/destination/ankiconnect/anki_prompt_cloze.py b/memium/destination/ankiconnect/anki_prompt_cloze.py index 71cc9b1..7fba0a4 100644 --- a/memium/destination/ankiconnect/anki_prompt_cloze.py +++ b/memium/destination/ankiconnect/anki_prompt_cloze.py @@ -37,6 +37,6 @@ def to_genanki_note(self) -> genanki.Note: return genanki.Note( guid=str(self.uuid), model=self.genanki_model, - fields=[self._field_to_markdown(self.text), "", " ".join(self.tags), str(self.uuid)], + fields=[self._to_html(self.text), "", " ".join(self.tags), str(self.uuid)], tags=self.tags, ) diff --git a/memium/destination/ankiconnect/anki_prompt_qa.py b/memium/destination/ankiconnect/anki_prompt_qa.py index f27f00e..2da1cb4 100644 --- a/memium/destination/ankiconnect/anki_prompt_qa.py +++ b/memium/destination/ankiconnect/anki_prompt_qa.py @@ -80,8 +80,8 @@ def to_genanki_note(self) -> genanki.Note: guid=str(self.uuid), model=self.genanki_model, fields=[ - self._field_to_markdown(self.question), - self._field_to_markdown(self.answer), + self._to_html(self.question), + self._to_html(self.answer), self._extra_field_content, str(self.uuid), ], diff --git a/memium/utils/markdown_parser.py b/memium/utils/markdown_parser.py index d9dee34..a1a6319 100644 --- a/memium/utils/markdown_parser.py +++ b/memium/utils/markdown_parser.py @@ -7,7 +7,7 @@ class MarkdownParser(Protocol): def __call__(self, markdown: str) -> str: ... -def markdown_parser(markdown: str) -> str: +def to_html(markdown: str) -> str: return Markdown( output_format="html", extensions=["legacy_em", "fenced_code", "tables", "nl2br"] ).convert(markdown) diff --git a/memium/utils/test_markdown_parser.py b/memium/utils/test_markdown_parser.py index 304aefa..5d252aa 100644 --- a/memium/utils/test_markdown_parser.py +++ b/memium/utils/test_markdown_parser.py @@ -3,7 +3,7 @@ import pytest -from .markdown_parser import markdown_parser +from .markdown_parser import to_html @dataclass(frozen=True) @@ -22,12 +22,12 @@ class Ex: ], ) def test_markdown_parser(example: Ex): - assert markdown_parser(example.given) == f"

{example.then}

" + assert to_html(example.given) == f"

{example.then}

" def test_code_block_parsing(snapshot: str, tmp_path: pathlib.Path): contents = pathlib.Path(__file__).parent / "code_block.md" - parsed = markdown_parser(contents.read_text()) + parsed = to_html(contents.read_text()) path = tmp_path / "test.htm" path.write_text(parsed) assert parsed == snapshot