You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When hydrating a lexical editor with the following markdown **Bold *Italic*** calling $convertFromMarkdownString should properly format this as bold & and bold italic text. However, for some reason, it doesn't, and the rendered result is Bold *Italic*
This seems to work when switching between editor content and markdown in the playground, but it does not work when initializing the playground with this content.
Lexical version: 3.8
Steps To Reproduce
Have a lexical instance with initialEditorState that invokes $convertFromMarkdownString('**Bold *Italic***')
See the content be rendered in editor as Bold *Italic* rather than the expected BoldItalic
When findOutermostMatch is called on the above pieces of markdown, it wrongly identifies the outer most pieces of markdown, causing the other contents to then be "split" and subsequent formatting is never formatted correctly
In the first case, *Foo **Bar***, findOutermostMatch wrongly returns **Bar**, then splitText is called, and the leadingNode and remainingNode are *Foo and * respectively, causing lexical to then render
--
I tried modifying the code to look something like this:
However, mergeWithSiblings seems to combine formats in a way creates a separate bug, *Foo **Bar*** being both entirely bold and italic, whereas the desired is Foo not being bolded
--
I wonder if the next best approach would be modifying or creating more regex's that capture both the beginning formatters, *,**,***,.. etc .. as well as trying to capture the last possible instance. i.e. scan currentNode for * if we see it, try match everything to the last * on the line
@hanford Thanks for digging into it! Was suspecting findOutermostMatch is not working correctly but didn't get a chance to play with regExp. The question is if it's even possible with regExp only. Especially for cases like above when *** is a closing tag for separate * and **. So the logic would be if we have * and ** opened, then the next *** is their combined closing tag, and we don't need to look for any * or ** further.
Maybe getting all tags matches (with its corresponding matching indices) and then walking through that list, so that we have info of currently started tags which can be used to distinguish between *** being a single tag or two combined closing tags
I'm having this same issue when using bold and italics, however, in your case bold was still working but not italics, and now, none of them is working, seems like something broke in the latest version, here is a reproduction:
Also still having this issue using Lexical 0.39.0.
I asked Claude to do some analysis of the problem. Apologies if it has hallucinated. Here is it's output:
Test Cases
import{$convertFromMarkdownString}from"@lexical/markdown";import{$getRoot}from"lexical";// ✅ WORKS: Simple cases$convertFromMarkdownString("*italic*",TRANSFORMERS);// Result: <em>italic</em> ✓$convertFromMarkdownString("**bold**",TRANSFORMERS);// Result: <strong>bold</strong> ✓$convertFromMarkdownString("***bold and italic***",TRANSFORMERS);// Result: <em><strong>bold and italic</strong></em> ✓// ✅ WORKS: Properly balanced nesting$convertFromMarkdownString("**bold with *italic* inside**",TRANSFORMERS);// Result: <strong>bold with <em>italic</em> inside</strong> ✓$convertFromMarkdownString("*italic with **bold** inside*",TRANSFORMERS);// Result: <em>italic with <strong>bold</strong> inside</em> ✓// ❌ FAILS: Overlapping delimiters (opener before opener, closer after closer)$convertFromMarkdownString("ggggg*jhhhh**dsjdhjdj***",TRANSFORMERS);// Expected: ggggg<em>jhhhh<strong>dsjdhjdj</strong></em>// Actual: ggggg*jhhhh<strong>dsjdhjdj</strong>* ✗
Root Cause Analysis
After investigating the @lexical/markdown source code, the issue appears to be in the findOutermostMatch function in LexicalMarkdown.dev.js (lines 308-340).
The Algorithm Flaw
The current algorithm:
Finds all opening tags using openTagsRegExp in a left-to-right scan
For each opening tag (in order of appearance), tries to match its full pattern
Returns the first successful match
This is a greedy left-to-right approach that doesn't respect CommonMark's emphasis delimiter matching rules.
Why It Fails on *jhhhh**dsjdhjdj***
Scanner finds * at position 5, ** at position 11
Tries to match *...* for position 5 → NO MATCH (finds *jhhhh** which has ** at the end)
Tries to match **...** for position 11 → MATCH! (**dsjdhjdj**)
Applies bold formatting, leaving *jhhhh and * as literal characters
CommonMark's Algorithm
Per the CommonMark spec, emphasis delimiter matching should:
Identify delimiter runs and apply flanking rules
Process emphasis from innermost to outermost
Match delimiters based on precedence (*** before ** before *)
Handle overlapping by respecting the delimiter stack
The CommonMark algorithm is significantly more complex than Lexical's current implementation. See CommonMark spec section 6.2 for the full algorithm.
describe('@lexical/markdown emphasis parsing',()=>{test('should handle overlapping emphasis delimiters per CommonMark spec',()=>{consteditor=createHeadlessEditor({nodes: [],onError: (error)=>console.error(error),});editor.update(()=>{$convertFromMarkdownString('ggggg*jhhhh**dsjdhjdj***',TRANSFORMERS);constroot=$getRoot();consthtml=root.getFirstChild()?.exportDOM().element?.innerHTML;// Should have nested em and strong tagsexpect(html).toContain('<em>');expect(html).toContain('<strong>');expect(html).toMatch(/ggggg<em>jhhhh<strong>dsjdhjdj<\/strong><\/em>/);// Should NOT have literal asterisksexpect(html).not.toContain('*');});});});
Activity
hanford commentedon Jul 27, 2022
Narrowed the issue down to a bug in this function, where when splitText is called, it can break up markdown format syntax so it's not formatted...
i.e. the following markdown syntax will never be imported correctly:
When
findOutermostMatchis called on the above pieces of markdown, it wrongly identifies the outer most pieces of markdown, causing the other contents to then be "split" and subsequent formatting is never formatted correctlyIn the first case,
*Foo **Bar***,findOutermostMatchwrongly returns**Bar**, thensplitTextis called, and theleadingNodeandremainingNodeare*Fooand*respectively, causing lexical to then render--
I tried modifying the code to look something like this:
However,
mergeWithSiblingsseems to combine formats in a way creates a separate bug,*Foo **Bar***being both entirely bold and italic, whereas the desired is Foo not being bolded--
I wonder if the next best approach would be modifying or creating more regex's that capture both the beginning formatters,
*,**,***,..etc .. as well as trying to capture the last possible instance. i.e. scancurrentNodefor*if we see it, try match everything to the last*on the linefantactuka commentedon Jul 28, 2022
@hanford Thanks for digging into it! Was suspecting findOutermostMatch is not working correctly but didn't get a chance to play with regExp. The question is if it's even possible with regExp only. Especially for cases like above when
***is a closing tag for separate*and**. So the logic would be if we have*and**opened, then the next***is their combined closing tag, and we don't need to look for any*or**further.Maybe getting all tags matches (with its corresponding matching indices) and then walking through that list, so that we have info of currently started tags which can be used to distinguish between
***being a single tag or two combined closing tagshanford commentedon Aug 3, 2022
refs #2303
focux commentedon Jan 12, 2023
I'm having this same issue when using bold and italics, however, in your case bold was still working but not italics, and now, none of them is working, seems like something broke in the latest version, here is a reproduction:
https://codesandbox.io/s/lexical-bold-and-italics-not-working-99cg7q
777PolarFox777 commentedon Aug 11, 2023
Looks like there's also an issue when you apply bold/italic on a line that has a a space character after an emoji in the end:

Not sure if it's a new issue or related
bruno-kumo commentedon Mar 14, 2024
Hi, are there any updates on this? I've been running into the same bug
aklatzke-kraftful commentedon Mar 22, 2024
For anyone running into this issue, here's a workaround you may be able to use.
For me, this was manifesting as the following:
To workaround this, I used the alternate markdown syntax for bold/italics (
___instead of***) and implemented it in a custom transformer.Then registered this as the first transformer:
This fixed the editor issue, you just need to ensure everything else in your pipeline supports the
___syntax for the formatting.etrepum commentedon Dec 16, 2024
Should be fixed by #5758
AlexandrDubovchenko commentedon Nov 7, 2025
Still have same issue.
Steps to reproduce:
Provide $convertFromMarkdownString with BoldItalic
Result is: Bold *Italic*
Lexical version: 0.38.2
@etrepum @yhw5 Please check
Yith1 commentedon Jan 13, 2026
Also still having this issue using Lexical 0.39.0.
I asked Claude to do some analysis of the problem. Apologies if it has hallucinated. Here is it's output:
Test Cases
Root Cause Analysis
After investigating the
@lexical/markdownsource code, the issue appears to be in thefindOutermostMatchfunction inLexicalMarkdown.dev.js(lines 308-340).The Algorithm Flaw
The current algorithm:
openTagsRegExpin a left-to-right scanThis is a greedy left-to-right approach that doesn't respect CommonMark's emphasis delimiter matching rules.
Why It Fails on
*jhhhh**dsjdhjdj****at position 5,**at position 11*...*for position 5 → NO MATCH (finds*jhhhh**which has**at the end)**...**for position 11 → MATCH! (**dsjdhjdj**)*jhhhhand*as literal charactersCommonMark's Algorithm
Per the CommonMark spec, emphasis delimiter matching should:
The CommonMark algorithm is significantly more complex than Lexical's current implementation. See CommonMark spec section 6.2 for the full algorithm.
Reproduction
Minimal Test Case
Automated Test
etrepum commentedon Jan 13, 2026
If you’re experiencing a problem you should open a new issue rather than comment on one that’s been closed
Yith1 commentedon Jan 14, 2026
Done: #8073