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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.