Preserve paragraph structure when line comments separate inline text#9
Open
colluca wants to merge 1 commit into
Open
Preserve paragraph structure when line comments separate inline text#9colluca wants to merge 1 commit into
colluca wants to merge 1 commit into
Conversation
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.
Problem
When a
// line commentsits on its own line between two sentences with no blank line, the compiled diff output incorrectly introduces a paragraph break between them.First sentence. // a comment Second sentence.Typst compiles the original correctly as one paragraph. The diff output breaks it into two.
Root cause
typst_syntaxtokenises\n// comment\nas three CST nodes:Space("\n"),LineComment(…),Space("\n"). Becausemarkup.exprs()dropsLineCommentnodes (they carry no semantic content), both surroundingSpace("\n")nodes are exposed to the iterator.typdiff concatenates their raw text into the paragraph buffer, producing
"first sentence.\n\nsecond sentence.". When that string is written to the diff output file and compiled by Typst, the bare\n\nis aParbreak— a paragraph break that was never in the original source.Note: this does not affect Typst itself, which processes the AST directly through its layout engine and never reconstructs source text from individual nodes.
Fix
Split
Expr::Spaceout of the combined inline arm and skip aSpace("\n")node when it would append\nto a buffer already ending with\n. This is always safe: bare\n\nin source is always tokenised as aParbreaktoken, never as two consecutiveSpacenodes — so two adjacentSpace("\n")in the expression iterator can only arise from a dropped comment between them.