From b4b69b0fe4dc84ec4878546cf8720cc681f2d01a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sondre=20Gr=C3=B8n=C3=A5s?= Date: Tue, 5 Mar 2024 12:44:08 +0100 Subject: [PATCH] Hotfix - Properly support codefences within callouts (again) - resolve #14 --- pyproject.toml | 2 +- src/mkdocs_callouts/utils.py | 9 +++------ tests/test_plugin.py | 9 ++------- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index bfd9824..c8e2a1e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "mkdocs-callouts" -version = "1.13.1" +version = "1.13.2" keywords = ["mkdocs", "mkdocs-plugin", "markdown", "callouts", "admonitions", "obsidian"] description = "A simple plugin that converts Obsidian style callouts and converts them into mkdocs supported 'admonitions' (a.k.a. callouts)." readme = "README.md" diff --git a/src/mkdocs_callouts/utils.py b/src/mkdocs_callouts/utils.py index c85bf47..1ae91f5 100644 --- a/src/mkdocs_callouts/utils.py +++ b/src/mkdocs_callouts/utils.py @@ -156,13 +156,10 @@ def convert_line(self, line: str) -> str: # Toggle in_codefence if line contains a codefence # (If a line contains '```' before any meaningful content, it's a codefence) if re.match(r'^\s*(?:>\s*)*```', line): - # TODO: Might be _almost_ impossible to do, but at the moment having a codefence containing - # callout syntax inside a callout block will convert the callout syntax within the codefence. - # (Extremely unlikely scenario, but still) self.in_codefence = not self.in_codefence - if self.in_codefence: - # Reset the indent levels if the callout is inside a codefence - self.indent_levels = list() + if self.in_codefence and self.indent_levels: + return self._convert_content(line) + elif self.in_codefence: return line return self._convert_block(line) or self._convert_content(line) diff --git a/tests/test_plugin.py b/tests/test_plugin.py index ed0099e..b53c917 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -272,14 +272,9 @@ def test_callout_in_codeblocks(): assert (convert(mkdown) == result) -# TODO: We could handle this edgecase, but it's probably not worth the effort -@pytest.mark.xfail def test_callout_in_codeblocks_within_callout(): - # A codefence within a callout containing a callout will still be converted - # Though it's probably not worth the effort to handle this edgecase in the parser - # Given how unlikely it is to occur in practice - mkdown = '> [!INFO]\n> ```\n> [!INFO]\n> ```' - result = '!!! info\n\t```\n> [!INFO]\n\t```' + mkdown = '> [!INFO]\n> ```\n> > [!INFO]\n> ```' + result = '!!! info\n\t```\n\t> [!INFO]\n\t```' assert (convert(mkdown) == result)