$convertToMarkdownString does not slashify
If the editor contains text that can be interpreted as markdown, $convertToMarkdownString assumes the value is the same. It should escape any markdown sequences with backslashes.
Lexical version: 0.15.0
Steps To Reproduce
-
Put the text "**foo**" in your clipboard (using your favorite text editor).
-
Go to the lexical playground and paste it.
-
Click the convert to markdown button. The markdown looks incorrect; it still has the value "**foo**". The proper value is "\*\*foo\*\*", with the backslashes.
-
Unclick the markdown button. The playground now shows "foo", adding boldface and removing asterisks.
The current behavior
Markdown is incorrectly encoded with no backslashes.
The expected behavior
Markdown should be correctly encoded.
Impact of fix
Pasting into the editor should be lossless.
My first attempt to fix: add this pass to the routine exportTextFormat() in MarkdownExport.ts:
// Go through the text and if it matches an unslashified tag, add slashes
for (const transformer of textTransformers) {
const tagWithSlashes = transformer.tag.replaceAll(/(.)/g,"\\$1" )
const regexp = new RegExp("(?<!\\\\)" + tagWithSlashes, "g");
output = output.replaceAll(regexp, tagWithSlashes);
}
The only downside is that I have to add the reverse transform to $convertFromMarkdownString.
Related to https://github.com/facebook/lexical/issues/2715?
Duplicate of #2715