You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello. Thanks for your feedback!
Every transform in slate-to-react matches the type field against corresponding html tag, so in order for it to work, your node must have the h<level> type. Because Slate does not enforce any specific schema rules, other than children field for elements and text for leaves, I simply cannot cover every possible scenario for matchers. This is what createElementTransform, createLeafTransform, createElementNodeMatcher and createLeafNodeMatcher are for, so you can bring your own components to render Slate nodes the way that fits your own needs.
This is how you can create your custom element element matcher & transform:
import{createElement}from"react"import{createElementNodeMatcher}from"slate-to-react"exportinterfaceHeading{type: "heading"level: 1|2|3|4|5|6children: InlineDescendant[]// This would be your own type}exportconstisHeading=createElementNodeMatcher<Heading>((node): node is Heading=>(node.type==="heading"&&typeofnode.level==="number"&&node.level>=1&&node.level<=6))exportconstHeadingElement=createElementTransform(isHeading,({key, attributes, element, children})=>createElement(element.level,{
...attributes,
key
}))
To be clear, this is the convention taken from Plate's schema – they typically place tag names in the type field and this is why I made it in my package by default.
Now I am thinking if it was a good idea making pre-built transforms enabled by default. Maybe this is something I will need to change sometime later.
"heading" is not recognized:
"isHeading" function isn't checking the node type "heading":
The text was updated successfully, but these errors were encountered: