Skip to content

convertContentModelToMarkdown() may generate invalid markdown #3100

@Durss

Description

@Durss

This is a dedicated issue for the unresolved part of that previous issue.

Describe the bug
Depending on the HTML structure it may generate invalid MD.

To Reproduce
The following generates an invalid markdown string:

    // Note the closing <b> tag stuck to "how" word!
    const model = createModelFromHtml("<p>hello <b>world </b>how are you?</p>"); 
    const md = convertContentModelToMarkdown(model);
    console.log(md)// log => hello **world **how are you?

Here, as the </b> tag is right next to the "how" word, it sets the closing markdown ** next to that word as well.
It's a logical behavior, but it's an invalid Markdown. The space should be after the closing ** instead of before, even if it doesn't match the HTML source structure.
Ideally users shouldn't set the remaining space as bold to fix that, but with WYSIWYG it's extremely easy to make such "mistake", and strongly believe that markdown conversion should take care of this.
This applies to other kind of formatting like italic.

Example use case where this is an issue:

  • write "hello world how are you?" on the composer
  • select "world " (with the trailing space!)
  • set selection to bold (both "world" and its following space are now bold)
  • generate markdown from the content model

Generated markdown will be invalid.

Expected behavior
It should generate a valid markdown that properly reflects what the WYSIWYG shows

Device Information

  • OS: MacOs 15.4.1 (24E263)
  • Browser: Vivalid 7.5.3735.41
  • Version [e.g. 22]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions