-
Notifications
You must be signed in to change notification settings - Fork 5
Add serializer customization to plugin #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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -95,6 +95,12 @@ module.exports.options = { | |
| watch: { | ||
| default: false, | ||
| runtimeParameter: 'watch' | ||
| }, | ||
| serializers: { | ||
| marks: { | ||
| annotations: [], | ||
| }, | ||
| types: {}, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @rudietuesdays, thanks for the PR! Really appreciated. |
||
| } | ||
| }; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,13 +17,19 @@ function convertBlockToHTML({ blocks, cache, entriesById, options, visitedIds }) | |
| return blockToHTML.h('img', { src: normalizedImage.url }); | ||
| }; | ||
|
|
||
| const allSerializers = { | ||
| types: { | ||
| ...options.serializers.types, | ||
| image: imageSerializer | ||
| }, | ||
| marks: { | ||
| ...options.serializers.marks | ||
| } | ||
| } | ||
|
Comment on lines
+20
to
+28
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rudietuesdays as noted before and although you have added the This means that if user runs Sourcebit without providing these options, these lines will throw an exception because serializers will be undefined: I suggest getting the options in a safely manner like If you want to know more about how Sourcebit merges options here is the code in Sourcebit that loads plugin options from config and merges it with |
||
|
|
||
| return blockToHTML({ | ||
| blocks, | ||
| serializers: { | ||
| types: { | ||
| image: imageSerializer | ||
| } | ||
| } | ||
| serializers: allSerializers, | ||
| }); | ||
| } | ||
|
|
||
|
|
||
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.
I think the
parsePluginOptionsfunction (defined here) doesn't recursively merge default values of nested properties. It only looks at the rootdefaultvalue of every root option.So I guess the right way would be specifying a single
defaultobject with possible properties:You can also set the
serializersoptions to be an empty object, like thedatasetandprojectIdoptions. This is fine because now the code access theserializersnested properties in a safe way, i.e.:(options.serializers && options.serializers.types):