-
|
I've been trying to set up a custom text format that works similarly to bold, italic, etc - basically it's similar to what a highlight format would do. Here is what I have so far, attempting to build a custom node: I've tried a variety of different codes, but can't quite figure it out. Am I supposed to be creating a custom Node for this? Basically, all I've been trying to do is create a <span> with a class name on it. Unfortunately, I can't find the source code for how bold and italic nodes are being created or how those get registered inside the Or is there some built-in feature for this? I was thinking perhaps I'll eventually need to build a custom markdown transformer for this as well, but for now I'm just trying to get the format working first. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
|
There are no custom text formats in lexical, only exactly the formats supported in TextFormatType. If you were using TypeScript you'd get a compile time error on the formatText call. You could use one of the existing formats for this purpose if your app doesn't otherwise need it (e.g. strikethrough or code). Some of the formats are mutually exclusive, a TextNode can have at most one of lowercase, capitalize, or uppercase for example, or at most one of superscript or subscript. What you implemented is a custom TextNode subclass, which is not a format. You'd need to write the code to do the "format" by replacing the TextNodes in the selection with your custom node. Another option for implementing something like spoilers would be to wrap a custom ElementNode around it, especially if you have a need to obscure more than just text. |
Beta Was this translation helpful? Give feedback.
There are no custom text formats in lexical, only exactly the formats supported in TextFormatType. If you were using TypeScript you'd get a compile time error on the formatText call. You could use one of the existing formats for this purpose if your app doesn't otherwise need it (e.g. strikethrough or code). Some of the formats are mutually exclusive, a TextNode can have at most one of lowercase, capitalize, or uppercase for example, or at most one of superscript or subscript.
What you implemented is a custom TextNode subclass, which is not a format. You'd need to write the code to do the "format" by replacing the TextNodes in the selection with your custom node.
Another option for implem…