Repository navigation
fix: preserve jsdoc markdown hard breaks - #800
Conversation
31276af to
2cc1107
Compare
…lash Adding a backslash depended on guessing the markdown structure, and guessing wrong added a visible backslash (ex. at the end of a paragraph, before a block tag, after a heading, or in example code). Kept spaces are invisible when they don't do anything, so only a narrow check is needed: - keep two spaces when text that isn't a block tag follows on the next line - don't keep them in fenced code, where a fence only closes with the same marker that's at least as long and has nothing after it, or in an example without a fence - don't treat indented lines as code, so nested list items keep them - look at the next line with a peekable iterator instead of scanning every later line, and borrow the lines instead of allocating them
|
Warning This comment is AI generated. I pushed a change to this PR (e9338e4) that keeps the two trailing spaces of a hard line break instead of converting them to a backslash. WhyConverting to
Trailing spaces are invisible when they don't do anything, so keeping them where they aren't needed doesn't change how the comment renders. That means the check can stay small instead of trying to parse Markdown. What it does nowIn JSDoc comments only, a line ending in two or more spaces keeps exactly two when:
Indented lines are no longer treated as code, so nested list items keep their hard breaks. Non-JSDoc block comments are unchanged.
The specs in |
Refs denoland/deno#31831.
JSDoc is commonly rendered as Markdown, but the TypeScript formatter currently trims two trailing spaces from non-final JSDoc lines. That removes Markdown hard line breaks. The Markdown plugin normalizes the same input to a backslash hard break, so this applies the same normalization to JSDoc lines while keeping non-JSDoc block comments on the existing trimming behavior.
The regression coverage also guards the main edge cases from the narrower behavior:
Tests:
cargo test --test specs issue031831cargo test --test specs JSDocComments_Allcargo test --test specs CommentBlocks_Allcargo test