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.
Addresses issue #123.
Implementation is how you'd expect: using a recursive function to process each
<tspan>
in turn, the base case being when a child is simply a plain#text
element. The context of the parent element is passed down to each child.Note browsers seem to treat text chunks in a linear manner. That is to say that setting the
x
/y
attribute of a nested<tspan>
will impact any subsequent<tspan>
s, regardless of whether they're a child, sibling or at a higher level. This effectively means that the collection ofTextChunk
s can be stored as a 1D array, rather than a tree. See the third and fourth tests in the new spec SVG.Things are complicated by the correct trimming of text when
xml:space = "default"
. In particular, spaces need to be consolidated across elements in eachTextChunk
and betweenTextChunk
s. Browsers also treatxml:space
differently:xml:space
can be freely changed and all child elements inheritxml:space
once set topreserve
cannot be set back todefault
in any child elementThis PR uses the Chrome convention.