Keep Markup: preserve nested empty markup - #4122
Open
dyk1454683243-sudo wants to merge 1 commit into
Open
dyk1454683243-sudo wants to merge 1 commit into
dyk1454683243-sudo wants to merge 1 commit into
Conversation
Fixes PrismJS#1640 Wrapping a parent keep-markup element cleared its original empty children, then the after-highlight walk reinserted those zero-width ranges at the same text offset — as siblings after the parent. Record the keep-markup ancestor and append empty descendants to it when the walk would place them outside that ancestor. Co-authored-by: David <dyk1454683243-sudo@users.noreply.github.com>
✅ Deploy Preview for dev-prismjs-com ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This branch has not been deployed
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 #1640
Keep Markup flattened nested zero-length markup (tags with empty
textContent) out of their parents:<x><y></y></x>→<x></x><y></y><x>a<y></y></x>→<x>a</x>(child dropped; with following text it became<x>a</x><y></y>)Mid-stream empties with text on both sides (
<x>a<y></y>b</x>) and sibling empties (x<a></a><b></b>y) already survived.Cause
before-highlightrecords text offsets. Parents are reinserted first. Wrapping a parent doesinnerHTML = '', which detaches stored empty children. The child's empty range sits at the same text offset as the parent'sposClose(or at the start of the following text), soRange#insertNodeplaces it after the parent.Fix
Record each node's keep-markup ancestor while walking the original tree. After highlighting:
appendChildit to the ancestor instead.posClose, no later text inside it), append to the ancestor the same way.Sibling empties, contentful last markup, order, double-highlight, and no-clone behavior are unchanged.
Tests
<x><y></y></x>,<x>a<y></y></x>, multiple empty children, deeper nest<x>a<y></y>b</x>)<x><y></y></x>foo,<x>a<y></y></x>b)Related
Shares empty-range care with #1618 / #4121 (empty markup as the last child of
<code>is still dropped on this branch; that last-child survival is #4121). This PR does not close #1618.