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
1 change: 1 addition & 0 deletions python/mdhtml/fill.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def _tokens(norm, tmpls):
toks = sorted(blks + inl, key=lambda t: t["start"])
groups = _groups(norm, tmpls, len(toks)) if toks else []
for i, t in enumerate(toks):
t.setdefault("source", norm[t["start"]:t["end"]])
t["extent"] = _extent(norm, t)
t["line"] = norm.count("\n", 0, t["start"]) + 1
t["group"] = None if groups is None else groups[i]
Expand Down
11 changes: 10 additions & 1 deletion tests/test_fill.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from mdhtml.fill import instantiate, fill_md
from mdhtml.fill import instantiate, fill_md, tokens
from helpers import mk_dlg, run_cli


Expand Down Expand Up @@ -56,6 +56,15 @@ def test_list_and_tree_rules():
with pytest.raises(ValueError): fill_md('Bad {{!note}}.', {})


def test_block_token_source_and_warnings():
assert tokens("{{/early}}\n")[0]["source"].strip() == "{{/early}}"
orphan = fill_md("Café\n\n{{/early}}\n", {}, strict=False)
assert orphan == "Café\n\n{{/early}}\n" and any("unpaired close marker '{{/early}}'" in w for w in orphan.warnings)
with pytest.raises(ValueError, match="unpaired close marker"): fill_md("{{/early}}\n", {})
unknown = fill_md("{{!note}}\n", {}, strict=False)
assert unknown == "{{!note}}\n" and any("unknown template token '{{!note}}'" in w for w in unknown.warnings)


def test_substitution_recursion():
assert fill_md("{{a}}\n", dict(a="See {{b}}.", b="9")) == "See 9.\n" # values are re-rendered
with pytest.raises(ValueError, match="loop"): fill_md("{{loop}}\n", dict(loop="{{loop}}"))
Expand Down
Loading