Repository navigation
Render until the output stops changing - #597
faresrafat3 wants to merge 2 commits into
Conversation
|
Hi @hukkin — following up on this PR. It fixes the fixed-point rendering issue where |
|
Thanks for the review @hukkin! I've addressed the feedback. The PR now renders until the output stops changing, which fixes the fixed-point rendering issue where |
Escaping can depend on where word wrapping split a paragraph, so a
single render pass may produce text that the next pass formats
differently. With a small --wrap, three passes are sometimes needed,
but only two were performed. The result was that a file mdformat had
just written failed --check, and a second mdformat run changed it again:
$ printf 'A * * b\n' > test.md
$ mdformat --wrap 5 test.md && cat test.md
A *
\* b
$ mdformat --check --wrap 5 test.md
Error: File "test.md" is not formatted.
Rendering now repeats until the output is unchanged (bounded, so a
pathological input cannot loop forever). Two passes still cover almost
every input; across the CommonMark spec fixtures with --wrap=5, four
cases need three.
The comment says 'two passes are enough for most inputs; a few need a third', but the loop cap was 9 - an unexplained magic number. 3 matches the documented behavior and keeps the safety net for pathological inputs.
d53e81f to
00d9eda
Compare
|
Rebased this onto current The diff is unchanged: The reason for the rebase is the commit author. The commits were made with an email The CI run for this pull request is waiting for a maintainer to approve the workflow |
|
Closing this to stop keeping a pull request open in a repository that has not merged anything since 2025-10-16. The patch is unchanged and the branch stays; if mdformat resumes, reopen and I will rebase it against whatever master looks like then. The change itself: render until the output stops changing, so a formatter pass cannot oscillate between two states. |
Fixes #588.
Escaping can depend on where word wrapping split a paragraph, so a single
render pass may produce text that the next pass formats differently. With a
small
--wrap, three passes are sometimes needed, but only two wereperformed, so a file mdformat had just written failed
--checkand a secondrun changed it again:
Root cause
For that input the render passes are:
Pass 1 breaks the line after
A * *, so on pass 2 the second asterisk is atthe end of a text token and loses the whitespace neighbour that had kept it
unescaped. Pass 2 then escapes it, and pass 3 escapes the first one too
because it is now adjacent to the backslash.
mdformat.text()only ran twopasses, so it returned the pass-2 output, which is not a fixed point.
Changes
_api.text()now renders repeatedly until the output is unchanged, with abound of 9 iterations so a pathological input cannot loop forever. This makes
"what mdformat writes" and "what
--checkaccepts" the same thing.Verification
The reported command sequence now settles on the first run and
--checkpasses:
A regression test covers exactly this (
test_check__after_format_with_small_wrap).I measured how many passes the CommonMark spec fixtures actually need, to check
that the loop is not papering over a deeper problem:
keepno605So two passes cover everything except one case at
--wrap=5, which is why thebug only shows up at small wrap widths.
Full suite:
4283 passed, 5 skipped(4282 before, plus the new test).