Add outerHTMLStrip and handle template tag encapsulation #3343
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.
Description
This is a possible enhancement Jeremy Howard suggested. When doing
outerHTMLoob swaps there are situations where you may want to replace an element on the page with multiple nodes and this is currently not possible withouterHTMLoob swaps as they can only replace it with a single node. This proposed change would add a new swap typeouterHTMLStripthat strips the encapsulating tag during swap like all the inner swap styles do but performs aouterHTMLswap to replace the target with all the inner contents of the oob tagged element.While I found you can do this sometimes with the following response currently:
Which will have the same results but it is much harder to discover or understand than just being able to control the tag stripping of the outerHTML swap
To implement this feature I just add this new
outerHTMLStripswap style support by letting this swap style be detected as a non inline swap style which means the parent of the swap data becomes the content itself instead of a wrapping fragment so it uses inner content for the swap and then we just remove the word "Strip" from the swap style to allow it to be processed as outerHTML.Another related fix I've included is to get the none inline swaps inner content assignment has a bug where template tags are broken as they have .content and not normal inner content nodes. So just adding support for template.content and falling back to the old way if its not a template solves this issue
This allows more generic use of oob swaps in templating libraries as you can just use template tags like this now:
This allows you to ignore the troublesome tables issues that are a real pain to debug as template tags can contain any element type and you don't have to match the encapsulating tag to be the perfect
tag type to match the content type to avoid issues.Existing wrapping use cases work the same as before after this change it just adds more template tag support.
Possible Changes:
The swap name
outerHTMLStripcould be renamed to something else if a better alternative name can be foundCould split this into two separate PR's
Also I found
Corresponding issue:
#3316
Testing
Added new tests and ran full test suite
Checklist
masterfor website changes,devforsource changes)
approved via an issue
npm run test) and verified that it succeeded