Keep changed code blocks inside a fence - #63
Open
tanghong123 wants to merge 1 commit into
Open
Conversation
When a code block differed between the two inputs, postprocess() assigned the unified diff to pre.textContent, which replaces every child of the <pre> and so drops its <code>. Pandoc's HTML reader only treats <pre> as a code block when it wraps a <code>, so on the way back to Markdown the block was read as a paragraph: the fence was lost, the lines were reflowed together, and smart punctuation rewrote the contents, turning --config into an en dash and "world." into curly quotes. Build the <code> child explicitly instead. convert() also rendered the intermediate HTML with Pandoc's default syntax highlighting on. Pandoc then emits one <span> per code line and keeps the newlines as text nodes between them, which node-htmldiff discards, so a changed block carrying a language tag collapsed onto a single line even with the <code> restored. Pass --no-highlight for the intermediate conversion only; the final render is a separate Pandoc call and still highlights, so ``` diff output stays colourised. --no-highlight is deprecated in Pandoc 3.10 in favour of --syntax-highlighting=none but is kept here for compatibility with older releases; happy to switch if you would rather require a newer Pandoc. With both changes, `pandiff test/old.md test/new.md` reproduces the committed test/diff.md apart from the image paths that the test harness supplies through its extract-media and resource-path options.
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.
Fixes #62.
Two small changes in
src/index.ts.1.
postprocess()dropped the<code>child of<pre>.Assigning the unified diff to
pre.textContentreplaces every child of the<pre>, including its<code>. Pandoc's HTML reader only treats<pre>as a code block when it wraps a<code>, so the block round-tripped back as a paragraph — fence lost, lines reflowed, and smart punctuation rewriting the contents, so--configrendered as–configand"world."as“world.”. That last part is what makes this more than cosmetic: a command copied out of a diff can be silently wrong.print(“Hello”) -print(“world.”) +print(“world!”) print(“Lorem ipsum
dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt”)