facebook / lexical

Lexical is an extensible text editor framework that provides excellent reliability, accessibility and performance.
https://lexical.dev
MIT License
18.24k stars 1.53k forks source link

Feature: Use markdown plugin without bundling Prismjs #5763

Open canastro opened 3 months ago

canastro commented 3 months ago

Right now if you use the markdown plugin, even if you don't want to support "Code" blocks, you'll still endup with prismjs in your bundle.

Ideally this would be optional.

non25 commented 2 months ago

Thanks for bringing this up! :+1:

I see two problems here:

:one: We can't provide our own stripped down nodes, since plugins like MarkdownShortcutsPlugin internally hard-depend on default nodes due to using node-related functions like $isCodeNode, or by adding transformers which we can't dependency-inject in the userland like we can inject nodes to the editor config.

So if we want pick some rich text functionality, we need to copypaste and strip down all rich text related plugins and their deps, which is really sadge.

:two: Lexical packages are bundled and minified for production usage, making it really hard to use patch-package on CodeNode for example to strip down language-related code and thus prismjs.

I have a feeling that MarkdownShortcutsPlugin is the most common path for building editor variants users expect, so in the long run I think it makes sense to make it as barebones as possible in the base package and add the ability to extend it if needed.

Is there a way to monkey-patch prismjs in CodeNode in the userland in case user wants it, otherwise strip CodeNode of it by default? That would probably be the easiest solution to implement.

...

Here's a dumb stripdown of CodeNode, because I don't understand what this does and why it requires stuff from CodeHighlightNode which is even more dependent on prismjs.

And here's the attempt to extract prismjs stuff outside CodeNode and add a function to dynamically inject it back in the userland if needed.

I didn't test it and it feels pretty dumb, but might give some inspiration to someone.

@trueadm sorry for tagging you directly, but I'm really curious how does this look from your pov and wanted to start a conversation somehow, which might not start at all if I don't tag. :sweat_smile:

I don't see how we could improve tree-shaking and customizability of markdown plugin, in a sense that we might only want to add bold, italic, lists and that's it, without thinking how to dynamically inject all those things from the userland, and whether maintainers want to go that route at all. :man_shrugging:

What I miss from lexical after working with it for two weeks+ is the ability to import more low-level stuff as functions instead of copy-pasting them from playground or lexical repo. :grin:

Fx. I needed to add a toolbar, and basically what I had to do is to copy-paste considerable amount of playground code and patch it a bit with chatgpt so fx. clear formatting clears more things that it initially did. :sweat_smile:

Thanks to everyone who works on lexical, you guys rock! :muscle: