Conversation
An <a href> wrapping multiple <img> children (e.g. badge rows) leaked the inter-image whitespace text nodes outside the link as flanking whitespace during the Turndown HTML->markdown roundtrip, producing N-1 leading spaces before the [ for N images. The phoenix README badge row (9 images) gained 8 leading spaces on every md editor save. Fix in two parts: - convertToMarkdown preprocessing strips the whitespace text nodes between <img> siblings inside an <a href>, so the anchor's textContent is empty and Turndown's flanking-whitespace handler has nothing to bubble out. - A new imageOnlyLink Turndown rule renders such anchors directly as [  ...](href), re-emitting the single joining space inside the brackets. Adds a regression test in test/spec/md-editor-integ-test.js that builds a 5-image badges-style line, forces an HTML->markdown roundtrip via __triggerContentSync, and asserts the CM source is byte-identical with no leading whitespace.
|
| replacement(content, node) { | ||
| const href = node.getAttribute("href") || ""; | ||
| const title = node.getAttribute("title"); | ||
| const titlePart = title ? ` "${title.replace(/"/g, '\\"')}"` : ""; |
| const alt = child.getAttribute("alt") || ""; | ||
| const src = child.getAttribute("src") || ""; | ||
| const imgTitle = child.getAttribute("title"); | ||
| const imgTitlePart = imgTitle ? ` "${imgTitle.replace(/"/g, '\\"')}"` : ""; |
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.



An wrapping multiple
children (e.g. badge rows) leaked the inter-image whitespace text nodes outside the link as flanking whitespace during the Turndown HTML->markdown roundtrip, producing N-1 leading spaces before the [ for N images. The phoenix README badge row (9 images) gained 8 leading spaces on every md editor save.
Fix in two parts:
Adds a regression test in test/spec/md-editor-integ-test.js that builds a 5-image badges-style line, forces an HTML->markdown roundtrip via __triggerContentSync, and asserts the CM source is byte-identical with no leading whitespace.