Repository navigation
Conversation
The `...` document-end marker was tested against the *previous* line,
because `start`/`maximum` are only moved onto the current line after the
test. Two things followed, both silent:
A block whose last line was `...` was dropped entirely, so the front
matter leaked into the document as visible text:
MarkdownIt().use(front_matter_plugin).render("---\ntitle: a\n...\n")
before '<hr />\n<p>title: a\n...</p>\n'
after ''
And where it did parse, the marker stayed in the token content, so
`content` was `'title: a\n...'` rather than `'title: a'`, unlike the
dashed form.
Move the test to after the per-line refresh and mark the line consumed.
`auto_closed` is only read at `state.line = nextLine + (1 if
auto_closed else 0)`, so setting it is what stops the marker being
re-parsed as content.
`test_all` could not catch either half: the front_matter token is
hidden, so only the rendered output is asserted, and a dropped block
renders as visible text rather than failing. The new tests assert the
token itself.
pytest tests -q 514 passed
|
Hi — picking this back up. Head is Recap: front matter closed by the YAML The repo's own workflows on this PR look like they haven't run (third-party One thing worth settling early: this is a one-line judgement in |
Summary
Front matter closed by the YAML
...document-end marker was not parsed correctly. Two distinct silent failures, both reproduced againstmainat519953d:The two forms should be equivalent. Instead, when
...closed the block:front_mattertoken was produced at all, and the front matter leaked into the rendered document as visible text (an<hr />plus a paragraph). This happens when...is the last line.token.contentwas'title: a\n...'instead of'title: a', unlike the dashed form which excludes its terminator.Root cause
mdit_py_plugins/front_matter/index.py, in the search loop:start/maximumare only moved ontonextLineafter the...test, so the test inspects linenextLine - 1. The content slice further down is computed asstate.src[state.bMarks[startLine + 1] : state.eMarks[nextLine - 1]], i.e. as if the closer were onnextLine. The check is exactly one line out of phase with the slice, which is why the two symptoms differ: at end-of-document the loop runs off the end andreturn Falsediscards the block, while with a body after it the marker survives intocontent.Fix
Move the test to after the per-line refresh, and set
auto_closedso the line is consumed rather than re-parsed as content.auto_closedis read only atstate.line = nextLine + (1 if auto_closed else 0).token.mapfor the dotted form becomes[0, 3], matching the dashed form.Tests
tests/test_front_matter.pygains two tests, both red before the fix:test_token_content_excludes_the_closer, parametrized over---and..., asserting the token content isa: 1in both cases.test_dots_closer_on_the_last_line, asserting the...-at-EOF render equals the---render (both empty).The existing
test_allcannot see either half of this: thefront_mattertoken ishidden=True, so onlymd.render()is asserted, and a dropped block renders as visible text rather than failing. The dotted case was otherwise only covered by theshould parse until triple dotsfixture, which asserts rendered output and so never inspectedcontent.Relation to #155
#155 also edits this line, adding
marker_chr == "-"to the same condition, but it leaves the check in the same position — so that branch does not have this bug fixed. The two changes compose: applying this fix on top of #155 moves the gated test onto the correct line. I have not rebased onto #155 because the conflict is a single line and the ordering is a maintainer decision; happy to rebase if you would rather land it after #155.Separate observation, not changed here
The comment two lines above says "unclosed block should be autoclosed by end of document" while the code does
return False, discarding the block. That contradiction predates this PR and changing it would alter behaviour for genuinely unclosed input, so I have left it alone.