Repository navigation
Conversation
WrapAllHtml parsed the wrapper with the first selected node itself as the context, not its parent. With a textarea, iframe, script, style, title or xmp the wrapper became a text node and the selection was moved into it, so the element disappeared from the document. With a text or comment node it panicked. Use the parent, as WrapHtml does.
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.
WrapAllHtmlparses the wrapper HTML with the first selected node itself as the context, while the wrapper actually takes that node's place in its parent.WrapHtmlalready uses the parent.For most elements that difference is invisible, but not for elements whose content the parser reads as raw text:
The wrapper is parsed as text inside a
<textarea>context, so it becomes a text node,WrapAllNodemoves the textarea into that text node, and the textarea is gone from the document. The same happens withiframe,script,style,titleandxmp.WrapHtmlon the same input gives<div class="wrap"><textarea>hi</textarea></div>.If the first node is a text or comment node it panics instead:
The fix parses in the parent's context, like
WrapHtml. When there is no parent, or the parent is not an element (the document node above<html>), it falls back toparseHtmlas before.Added
TestWrapAllHtmlRawTextElementandTestWrapAllHtmlTextNode. The first finds 0 nodes and the second panics before the fix.go test ./...andgo vet ./...pass.