Skip to content

Bug: Markdown conversion not working properly for Bold Italic with link text #7811

@satzdev

Description

@satzdev
Image

Bug Report: Markdown Conversion Issue for Bold, Italic, and Bold Italic Text with Link

Description:
When converting text with bold, italic, or bold italic formatting combined with a hyperlink into Markdown using the @lexical/markdown library, the closing formatting markers (**, *, or ***) are missing at the end of the link. This results in incorrect Markdown output.

Steps to Reproduce:

  1. Add the following text in the editor:
    • Two words: hello link.
    • Apply the following formatting:
      • Bold: Make both words bold.
      • Italic: Make both words italic.
      • Bold Italic: Make both words bold italic.
    • Add a hyperlink to the word link (e.g., https://www.google.com/).
  2. Use the following code to convert the editor content to Markdown:
    const newState = editor.parseEditorState(editorStateData);
    editor.setEditorState(newState);
    
    editor.update(() => {
      const markDown = $convertToMarkdownString(CUSTOM_TRANSFORMERS, undefined, true);
      setDefaultMarkdown(markDown);
    });
  3. Observe the generated Markdown output.

Expected Output:

  • For Bold:
    **hello [link](https://www.google.com/)**
    
  • For Italic:
    *hello [link](https://www.google.com/)*
    
  • For Bold Italic:
    ***hello [link](https://www.google.com/)***
    

Actual Output:

  • For Bold:
    **hello [link](https://www.google.com/)
    
  • For Italic:
    *hello [link](https://www.google.com/)
    
  • For Bold Italic:
    ***hello [link](https://www.google.com/)
    

Library Version:
@lexical/markdown: ^0.33.1

Additional Context:
The issue occurs when combining bold, italic, or bold italic formatting with a hyperlink. The closing formatting markers (**, *, or ***) are omitted, leading to invalid Markdown syntax.

Active Code:
From the file: markDown.tsx

const newState = editor.parseEditorState(editorStateData);
editor.setEditorState(newState);

editor.update(() => {
  const markDown = $convertToMarkdownString(TRANSFORMERS, undefined, true);
  setDefaultMarkdown(markDown);
});

Please investigate and provide a fix or workaround for this issue. Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions