Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion myst_parser/parsers/directives.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@ def _parse_directive_options(
content_lines = content.splitlines()
yaml_lines = []
while content_lines:
if not content_lines[0].lstrip().startswith(":"):
stripped = content_lines[0].lstrip()
# Stop at lines that don't start with a colon or have 3+ colons, which are colon fences
# (e.g. nested directives like `::::{other}`)
if not stripped.startswith(":") or stripped.startswith(":::"):
break
yaml_lines.append(content_lines.pop(0).lstrip()[1:])
options_block = "\n".join(yaml_lines)
Expand Down
7 changes: 7 additions & 0 deletions tests/test_renderers/test_parse_directives.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,10 @@ def test_additional_options():
)
assert len(result.warnings) == 1
assert "Unknown option" in result.warnings[0].msg


def test_colon_options_stop_at_colon_fence():
"""Options parsing should stop when encountering a colon fence (3+ colons)."""
result = parse_directive_text(Note, "", ":class: xxx\n::::{other}\ncontent\n::::")
assert result.options == {"class": ["xxx"]}
assert result.body == ["::::{other}", "content", "::::"]
Loading