Replies: 1 comment
-
|
Is there some kind of plugin or standard way to deal with the nodes when toggling Code Blocks? I'd like to remove and prevent all formatting from anything going into the code blocks, including links/autolinks. I should add that I'm trying to build the editor in Vanilla JS, which is makes this a little trickier. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Almosted figured it out. I have a "code highlight" button that just highlights bits of text in a paragraph and a "code block" button that turns the entire paragraph into a code block. When I select two separate paragraphs and run
$setBlocksType(selection, () => $createParagraphNode());, it creates two separate code blocks.What I'm trying to do:
My goal is to convert multiple (or a single) paragraphs into a single, merged code block. At the same time, if there is bold, italic, code highlighting, etc. on the text, I wish to remove all formatting and just leave text. It sounds simple enough, but I worked on it for about 12 hours (following examples here and on Google) and it seems to be far more difficult than it should be, and there is some weird behavior as well - stuff I don't understand.
Here is what I have so far:
Everything seems to work as expected when two or more paragraphs are selected. They merge and all the text formatting is removed. However, I'm guessing I'm doing this in a non-standard way, so I'd like some advice on doing it a better way.
However, everything works weird when it's just one paragraph - particularly when I want to remove the text formatting. When I iterate through ALL nodes in the selection of the paragraph, it doesn't find all the text inside if any of it has formatting. Note in the console log, just the text after the formatting
dfanddfis found on each line in the paragraph. Anything before that is cut off and not even registered!Even when the entire paragraph block is converted to a code block, iterating through the selection nodes does not find any "code" node type (with the 1-paragraph problem). This is like right after it was just converted to a code node.
I'm pretty new to Lexical, so I'm probably doing something wrong. Is there a better way to do this, some kind of built in feature? I'm sure this has been done a million times before, but I'm pretty stuck right now.
Beta Was this translation helpful? Give feedback.
All reactions