-
Notifications
You must be signed in to change notification settings - Fork 61
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(helpers): support attribute shorthand for map serializer #321
Conversation
Codecov ReportAll modified lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #321 +/- ##
========================================
Coverage 99.96% 99.96%
========================================
Files 50 50
Lines 6087 6251 +164
Branches 301 332 +31
========================================
+ Hits 6085 6249 +164
Misses 2 2
☔ View full report in Codecov by Sentry. |
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.
Looks really great to me! I left a couple of small comments.
Do you have any ideas on how we could share shorthand logic between rich text renderers? Maybe a set of helpers that could be exported from @prismicio/client/richtext
? I don't think we would want to build the shorthand functionality into the low-level rich text functions like serialize()
.
src/lib/serializerHelpers.ts
Outdated
if (typeof value === "boolean") { | ||
result.push(key); | ||
} else { | ||
result.push(`${key}="${value}"`); |
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.
Do you think we should escape value
in case it contains "
?
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.
Maybe! I'll run some test to check if we can put it there
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.
Done :)
Types of changes
Description
This PR allows
asHTML
to be configured with aclass
shorthand for individual tags. It saves developer keystrokes by removing boilerplate in the common case of applying a classname to the default block element.The above
serializer
value is equivalent to the following:The shorthand and existing inline serializer syntax can coincide in the
serializer
prop.Attributes other than
class
are supported too.Checklist: