Repository navigation
fix: a four-space indent no longer turns a paragraph into code (#38) - #45
Merged
Merged
Conversation
w:tab emits one space, so four or more at a paragraph start produced CommonMark's indented code block. Filed as a rendering bug. It is also a TEXT LOSS bug, which the issue got wrong and this measured: doc10 of the corpus, 41,220 words main 17 lost -> 4 lost doc12 14 lost -> 14 lost (another cause) the other eleven 0 -> 0 Thirteen words recovered, none lost anywhere. The oracle re-parses docmd's own Markdown with Markdig and compares word for word against the source, and text inside a spurious code block does not come back as prose. #38 claimed the coverage check could not see this; it could. I had only checked a synthetic fixture, where one short indented paragraph round-trips cleanly, instead of a real document where those lines sit among thousands. FIRST PHYSICAL LINE ONLY. CommonMark does not let an indented code block interrupt a paragraph, so a continuation line after a hard break is a lazy continuation whatever its indentation: its whitespace is harmless and is layout the document carries. FOUR SPACES, NOT ANY. docs/deferred-work.md proposed a plain TrimStart on the first line. That was written and measured before it was kept, and it moved 1,100 lines across all 13 corpus documents of which only 25 were the defect -- the other 1,075 were indents of one to three spaces, which CommonMark ignores outright, so they rendered identically before and after. docmd's output is meant to be committed and indexed, and a reflow of every file is a cost its users pay in review. The threshold cuts it to exactly the defect: broad TrimStart 13 of 13 documents, 1,100 lines, 25 of them the bug at the threshold 4 of 13 documents, 25 lines, 25 of them the bug Deliberately NOT symmetrical with TrimTrailingHorizontalWhitespace, which is unconditional. Trailing whitespace is stripped by editors and linters on save, so leaving it makes a re-conversion look like a diff against nothing. Leading whitespace is ordinary indentation nothing strips, so that argument does not carry over. Tests pin both sides of the threshold and the scope, in the serialiser where the trim lives: ParagraphFirstLine_LosesAnIndentWideEnoughToBeCode ParagraphFirstLine_KeepsAnIndentTooNarrowToBeCode ParagraphContinuationLine_KeepsItsLeadingWhitespace CodeBlock_KeepsItsOwnIndentation AListItemsStructuralIndent_SurvivesTheTrim One test here was passing for the wrong reason and is removed. It used a HTMLPreformatted style to build what it called a code block, but md:code-block comes only from a style-map rule, so it was asserting on an ordinary indented paragraph and would have stayed green forever while testing nothing about code blocks. Only this change broke it into honesty. Still outstanding, pre-existing and not touched here: doc10's remaining 4 lost words and doc12's 14, both reported as unattributed. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018wZEgtuzaZPswykiGEBxbz
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.
Closes #38 — which filed this as a rendering bug. It is also a text-loss bug, and the issue
said the opposite. Corrected below.
It costs measured coverage
w:tabemits one space, so four or more at a paragraph start produced CommonMark's indented codeblock. docmd's oracle re-parses its own Markdown with Markdig and compares word-for-word against
the source, and text inside a spurious code block does not come back as prose:
mainThirteen words recovered, nothing lost anywhere.
#38 claimed the coverage check couldn't see this. It could. I had only checked a synthetic
fixture, where one short indented paragraph round-trips cleanly, instead of a real document where
those lines sit among thousands — the corpus-versus-fixture argument this repo makes everywhere,
demonstrated against me.
Scope: first line, four spaces
First physical line only. CommonMark does not let an indented code block interrupt a
paragraph, so a continuation line after a hard break is a lazy continuation whatever its
indentation — its whitespace is harmless and is layout the document carries.
Four spaces, not any.
docs/deferred-work.mdproposed a plainTrimStarton the first line.That version was written and measured before it was kept:
TrimStartThe other 1,075 were indents of one to three spaces, which CommonMark ignores outright — they
rendered identically before and after. docmd's output is meant to be committed and indexed, so a
reflow of every file is a cost its users pay in review, and 97.7% of it bought nothing. If you
want the full tidy it is a one-line change, and it deserves its own commit rather than riding in
on a bug fix.
Deliberately not symmetrical with
TrimTrailingHorizontalWhitespace, which is unconditional:trailing whitespace is stripped by editors and linters on save, so leaving it makes a
re-conversion look like a diff against nothing. Leading whitespace is ordinary indentation nothing
strips, so that argument does not carry over.
A real example
Rows of a code-comparative table, rendered as a monospaced block.
Tests
377 total, 376 pass, 1 skip. The threshold and the scope are pinned in the serialiser, where the
trim lives:
ParagraphFirstLine_LosesAnIndentWideEnoughToBeCodeParagraphFirstLine_KeepsAnIndentTooNarrowToBeCodeParagraphContinuationLine_KeepsItsLeadingWhitespaceCodeBlock_KeepsItsOwnIndentationAListItemsStructuralIndent_SurvivesTheTrimOne test is removed because it was passing for the wrong reason. It used an
HTMLPreformattedstyle to build what it called a code block, butmd:code-blockcomes onlyfrom a style-map rule — so it was asserting on an ordinary indented paragraph and would have
stayed green forever while testing nothing about code blocks. Only this change broke it into
honesty.
Not touched
doc10's remaining 4 lost words and doc12's 14, both pre-existing and reported as
unattributed.🤖 Generated with Claude Code
https://claude.ai/code/session_018wZEgtuzaZPswykiGEBxbz