Slate/HTML serializers designed for Payload CMS #1508
Replies: 2 comments 3 replies
-
A config for Payload CMS is now included in the package: https://www.npmjs.com/package/slate-serializers. This works for anyone using Payload CMS that hasn't customised the Slate editor. If you've added your own configuration to the Slate editor, https://www.npmjs.com/package/slate-serializers can also be configured to work with your schema. |
Beta Was this translation helpful? Give feedback.
-
This is great, thanks @thompsonsj ! |
Beta Was this translation helpful? Give feedback.
-
I've been working on Slate to HTML and HTML to Slate serializers that contain the features we might need for working with Payload data.
I'm posting here in case anyone has any ideas on how it can be improved or thoughts about the way it works.
https://github.com/thompsonsj/slate-serializers
I've built on a lot of the work out there on serializers to include the following:
htmlparser2
instead of theDOMHandler
object in order to ensure this can be run in Node.js as well as browser environments.linkType
attribute on links to distinguish between custom and internal links, and we can make sure this data is included.linkType
attribute).As a proof of concept, it is working pretty well, and I like the idea of a simple set of serializers that can be used anywhere. I've struggled to find comprehensive pre-built serializers out there. e.g.
slate-html-serializer
aims to cover use cases by ensuring users provide their own schema/rules, but it looks like it's deprecated: ianstormtaylor/slate#3899.The motivation for this comes from work I'm doing on a CrowdIn plugin, which localizes Payload CMS content through CrowdIn. For this, it would be useful if Slate JSON can be converted to HTML and back. The reason is that it is much easier to localize a HTML document in CrowdIn compared to a Slate JSON object, especially for longer content. I think integration with localization tools will be invaluable for larger sites.
Beta Was this translation helpful? Give feedback.
All reactions