-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: make text available to all span tree nodes #55
Conversation
Codecov Report
@@ Coverage Diff @@
## master #55 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 7 7
Lines 113 115 +2
Branches 23 23
=========================================
+ Hits 113 115 +2
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code LGTM
Can you be more specific though regarding real-world use cases of that addition? I'm not sure I really get it/where this is preferred to text
from the serializer 馃
Are there considerations regarding node typing also?
- https://github.com/prismicio/prismic-richtext/blob/master/src/types.ts#L35
- https://github.com/prismicio/prismic-richtext/blob/master/src/types.ts#L108-L109
- https://github.com/prismicio/prismic-richtext/blob/master/src/types.ts#L124-L126
(@prismicio/types for reference: https://github.com/prismicio/prismic-types/blob/master/src/fields.ts#L115-L146, those describe the API node type and shouldn't be changed)
Yep, I probably should have included that in the original message. 馃槅 This lets an HTML serializer use the span's text contents in its output. For example, one could use it to assign an ID to a piece of text. Input (assume the bolded text is a label with the name "anchor"):
Output: <p>This text contains <span id="anchor">a label</span> with an ID. This could also be used for links. Output: <p>This text contains <PrismicLink href={theResolvedLink} anchor={anchor}>a link</PrismicLink> with an ID.</p> It could also be used to add automatic slugs to spans, just like we can do with headings. Headings can do that today because they have access to the block's text. Spans cannot do it today because they do not have access to its parent's text. <p>This text contains <span id="a-label">a label</span> with an ID.</p> Or titles:
<p>This text contains <span title="Hello reader">a label</span> with an ID.</p> While the syntax shown here is not necessarily the most optimal way of performing these tasks, they sufficiently demonstrate that a span could manipulate its text if it has access to it. (Credit to @chamois-d-or for the idea and asking if this was possible)
No, there shouldn't be any. The nodes are already typed with |
OK, got it thank you! So this type was wrong essentially as text would have always been I'll let you merge/release |
Basically, yes. The tree node that was provided to any span serializer function (label, strong, em, etc.) would never receive the With this PR, the types are more correct. Thanks for the review! 馃檪 |
Types of changes
Description
This PR makes the
text
property available to all span tree nodes. This is helpful when a span's text is needed to compute its serialized output. Without this PR, spans do not have any contextual information, only their start, end, own node data, and children.See the following examples to see the difference in children nodes before and after this PR. Note that the
text
property is absent in thestrong
node.Before (
key
properties omitted):After (
key
properties omitted):Checklist:
馃悋