Skip to content

Commit

Permalink
Hotfix - Properly support codefences within callouts (again) - resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
sondregronas committed Mar 5, 2024
1 parent f341be5 commit b4b69b0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Expand Up @@ -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"
Expand Down
9 changes: 3 additions & 6 deletions src/mkdocs_callouts/utils.py
Expand Up @@ -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)

Expand Down
9 changes: 2 additions & 7 deletions tests/test_plugin.py
Expand Up @@ -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)


Expand Down

0 comments on commit b4b69b0

Please sign in to comment.