-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[lexical-markdown][lexical-playground] Feature: Option to include blanklines in markdown render #6020
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
size-limit report 📦
|
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). |
|
||
export function createMarkdownExport( | ||
transformers: Array<Transformer>, | ||
isNewlineDelimited: boolean = true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the two are the same feature, do we need a different flag name for these?
I would probably call it preserveNewLines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that makes sense to standardise the flag name for both import and export, will change!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed in 89a7b30
firstChild == null || | ||
(node.getChildrenSize() === 1 && | ||
$isTextNode(firstChild) && | ||
MARKDOWN_EMPTY_LINE_REG_EXP.test(firstChild.getTextContent())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this intentional? I believe this regex is particularly important on top of the default Node isEmpty
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i moved this to packages/lexical-markdown/src/utils.ts for reuse
$isTextNode(firstChild) && | ||
MARKDOWN_EMPTY_LINE_REG_EXP.test(firstChild.getTextContent())) | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zurfyx here it is
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)
text becomes
because of newline delimeter with shouldPreserveNewLines = true (new optional behavior)
text ^imagine no newlines seperating them becomes
tho this is consistent with other markdown surfaces such as github & dillinger where texts right below blockquotes get included in the blockquote |
@@ -116,6 +128,7 @@ function exportChildren( | |||
exportTextFormat(child, child.getTextContent(), textTransformersIndex), | |||
); | |||
} else if ($isElementNode(child)) { | |||
// empty para returns "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you think this comment adds some value, let's write "paragraph" instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed in 6a42853
|
||
export function createMarkdownExport( | ||
transformers: Array<Transformer>, | ||
shouldPreserveNewLines: boolean = false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think the preserveNewLines
comment we discussed applies here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i hope i understood u correctly, its been applied in 89a7b30 ,
isNewlineDelimited
replaced with shouldPreserveNewLines
,
preserveNewLines
is named as shouldPreserveNewLines
to be consistent with boolean naming conventions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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:
These flags are optional. Defaults to old behavior of removing newlines on import and delimiting with newlines on export.
Test plan
Before
Screen.Recording.2024-05-03.at.10.16.38.PM.mov
blank lines are ignored and removed
After
Screen.Recording.2024-05-03.at.10.18.02.PM.mov
number of blank lines consistent between markdown and rendered markdown
Added settings in playground to toggle newline preservation
Screen.Recording.2024-05-17.at.1.44.36.AM.mov
Unit and e2e tests pass locally