feature: preserve html inside target elements #28
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.
Summary
previously, all HTML inside the target element was stripped away when the text was split.
With this feature, HTML elements inside the target element(s) will be preserved when splitting text. This will make it possible to:
Example
Result
Limitations
1. Not fully compatible with splitting text into lines
If the content of a nested element spans multiple lines, it's not possible wrap each line and preserve the nested element. GSAP's plugin has the same limitation. There might be a way to solve this in the future. But for now, this feature will have the caveat that splitting lines is not fully supported.
However, nested elements can be used when splitting lines, as long as there are no line breaks in the nested elements.
TODO
Right now, when split lines is enabled, nested elements are always treated as a word boundary. This results in unwanted white space when nested elements do not align with a word boundary.
For example:
<p id="target"><em>foo</em>, barr</p>. In this case, there should be no space after theem; it should be immediately followed by a",". Another example is nested elements that wrap part of a word:<p id="target"><em>Some</em>thing</p>.We use the
offsetTopof each word to detect natural line breaks in the text. If theoffsetTopof a nested element is slightly different than the previous word, it will trigger a line break. This often results in unwanted line breaks, especially with nested elements such as<button>. It should be possible to include nested elements that have padding/height/borders etc.For #3