Major Changes
-
#4174 by @felixfeng33 – #### New Features
- Added support for math type deserialization
- Added default underline mark serialization as
<u>underline</u> - Improved serialization process:
- Now uses a two-step process:
slate nodes => MDAST nodes => markdown string - Previously: direct conversion from Slate nodes to markdown string
- Results in more reliable and robust serialization
- Now uses a two-step process:
- New node filtering options:
allowedNodes: Whitelist specific nodesdisallowedNodes: Blacklist specific nodesallowNode: Custom function to filter nodes
- New
rulesoption for customizing serialization and deserialization rules, including custom mdx support - New
remarkPluginsoption to use remark plugins
Breaking Changes
Deserialization
- Removed
elementRulesandtextRulesoptions- Use
rules.key.deserializeinstead - See nodes documentation
- Use
Example migration:
export const markdownPlugin = MarkdownPlugin.configure({ options: { disallowedNodes: [SuggestionPlugin.key], rules: { // For textRules [BoldPlugin.key]: { mark: true, deserialize: (mdastNode) => ({ bold: true, text: node.value || '', }), }, // For elementRules [EquationPlugin.key]: { deserialize: (mdastNode, options) => ({ children: [{ text: '' }], texExpression: node.value, type: EquationPlugin.key, }), }, }, remarkPlugins: [remarkMath, remarkGfm], }, });
- Removed processor in
editor.api.markdown.deserialize- Use
remarkPluginsinstead
- Use
Serialization
- Removed
serializeMdNodes- Use
editor.markdown.serialize({ value: nodes })instead
- Use
- Removed
SerializeMdOptionsdue to new serialization process- Previous process:
slate nodes => md - New process:
slate nodes => md-ast => md
- Previous process:
- Removed options:
nodesbreakTagcustomNodesignoreParagraphNewlinelistDepthmarkFormatsulListStyleTypesignoreSuggestionType
Migration example for
SerializeMdOptions.customNodesandSerializeMdOptions.nodes:export const markdownPlugin = MarkdownPlugin.configure({ options: { rules: { // Ignore all `insert` type suggestions [SuggestionPlugin.key]: { mark: true, serialize: (slateNode: TSuggestionText, options): mdast.Text => { const suggestionData = options.editor .getApi(SuggestionPlugin) .suggestion.suggestionData(node); return suggestionData?.type === 'insert' ? { type: 'text', value: '' } : { type: 'text', value: node.text }; }, }, // For elementRules [EquationPlugin.key]: { serialize: (slateNode) => ({ type: 'math', value: node.texExpression, }), }, }, remarkPlugins: [remarkMath, remarkGfm], }, });