[lexical-markdown][lexical-playground] Feature: Option to include blanklines in markdown render
Description
Describe the changes in this pull request
option to make the number of blank lines consistent between markdown and the rendered markdown
Closes: #
To enable:
$convertFromMarkdownString(
...,
true // shouldIncludeBlankLines -> set to true,
)
$convertToMarkdownString(
...,
false, // isNewlineDelimited -> set to false
);
These flags are optional. Defaults to old behavior of removing newlines on import and delimiting with newlines on export.
Test plan
Before
https://github.com/facebook/lexical/assets/19604232/108fdd80-0cde-4678-b4dd-b301132082fa
blank lines are ignored and removed
After
https://github.com/facebook/lexical/assets/19604232/b8ce7e72-e1c2-4b60-9b96-c92a95791faf
number of blank lines consistent between markdown and rendered markdown
The latest updates on your projects. Learn more about Vercel for Git ↗︎
| Name | Status | Preview | Comments | Updated (UTC) |
|---|---|---|---|---|
| lexical | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | May 17, 2024 0:56am |
| lexical-playground | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | May 17, 2024 0:56am |
size-limit report 📦
| Path | Size | Loading time (3g) | Running time (snapdragon) | Total time |
|---|---|---|---|---|
| packages/lexical/dist/Lexical.js | 23.93 KB (0%) | 479 ms (0%) | 175 ms (+1113.49% 🔺) | 654 ms |
| packages/lexical-rich-text/dist/LexicalRichText.js | 34.59 KB (0%) | 692 ms (0%) | 207 ms (+521% 🔺) | 899 ms |
| packages/lexical-plain-text/dist/LexicalPlainText.js | 34.51 KB (0%) | 691 ms (0%) | 195 ms (+490.96% 🔺) | 885 ms |
LGTM, I believe there were some PRs in past with similar idea. More broader discussion (covered it a bit offline with Gerard & folks): it seems like best route for MD plugin is to eliminate out of the box import and export parsing and instead start relying on external library (e.g., remark), while plugin will only responsible to connect Lexical and 3rd party lib. That would allow delegating this kind of configuration to those libs.
Shortcuts is a bit more lightweight functionality (and handles simple formats only) so it could still remain a part of the plugin (that way we're not bloating editor with full MD parsing library for simple shortcuts).
it seems like best route for MD plugin is to eliminate out of the box import and export parsing and instead start relying on external library (e.g., remark) @fantactuka
I'm not very familiar with Remark, but I have a hard time seeing how a generic library could correctly parse Lexical's editorState.
Separate topic, I do like this PR. In my app I use markdown for the tests, and to make the conversion idempotent I do something quite dirty: I add a specific string to the empty paragraphs, and after the conversion is done I delete them.
note: there is a change to blockquote behavior.
with shouldPreserveNewLines = false (old behavior)
hello
text
becomes
>hello
text
because of newline delimeter
with shouldPreserveNewLines = true (new optional behavior)
hello
text
^imagine no newlines seperating them
becomes
>hello
>text
tho this is consistent with other markdown surfaces such as github & dillinger where texts right below blockquotes get included in the blockquote