Skip to content

Commit

Permalink
Hotfix for blockquoted callouts #13
Browse files Browse the repository at this point in the history
  • Loading branch information
sondregronas committed Feb 27, 2024
1 parent af9cbff commit f341be5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 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.0"
version = "1.13.1"
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
6 changes: 5 additions & 1 deletion src/mkdocs_callouts/utils.py
Expand Up @@ -110,6 +110,9 @@ def _convert_block(self, line: str) -> str:
if match:
# Store the current indent level and add it to the list if it doesn't exist
indent_level = match.group(2).count('>')
# Guard clause to prevent non-callout blocks from being converted (e.g. code blocks)
if 1 not in self.indent_levels and indent_level != 1:
return line
if indent_level not in self.indent_levels:
self.indent_levels.append(indent_level)
return self._parse_block_syntax(match)
Expand Down Expand Up @@ -151,7 +154,8 @@ def convert_line(self, line: str) -> str:
if line is not a block syntax, it will return _convert_content.
"""
# Toggle in_codefence if line contains a codefence
if re.match(r'^\s*```', line):
# (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)
Expand Down
23 changes: 23 additions & 0 deletions tests/test_plugin.py
Expand Up @@ -306,4 +306,27 @@ def test_content_tabs():
# Example:
mkdown = '> [!NOTE]\n\t=== "test"\n\t\t> [!NOTE]\n\t\t> Text'
result = '!!! note\n\t=== "test"\n\t\t!!! note\n\t\t\tText'
assert (convert(mkdown) == result)


def test_callout_within_blockquotes():
# https://github.com/sondregronas/mkdocs-callouts/issues/13
mkdown = '> > [!NOTE]\n> > Text'
result = '> > [!NOTE]\n> > Text'
assert (convert(mkdown) == result)

mkdown = '> ```\n> > [!NOTE]\n> > Text\n> ```'
result = '> ```\n> > [!NOTE]\n> > Text\n> ```'
assert (convert(mkdown) == result)


def test_invalid_callout_syntax_within_blockquote():
# This is incorrect syntax for a callout within a codefence within a blockquote,
# but it's still valid markdown and should be preserved
mkdown = '> ```\n> [!NOTE]\n> Text\n> ```'
result = '> ```\n> [!NOTE]\n> Text\n> ```'
assert (convert(mkdown) == result)

mkdown = '> > [!NOTE]\n> > Text'
result = '> > [!NOTE]\n> > Text'
assert (convert(mkdown) == result)

0 comments on commit f341be5

Please sign in to comment.