Rosey/markdown-draft-js

Incorrect list conversion

Closed this issue · 7 comments

Let's say in draft-js we have following content:

first line

  1. list
  2. two
  3. three

next line

That is converted to markdown as:

first line

1. list
1. two
1. three
next line

There should be a line between last list element three and the next line.
Otherwise, next line is considered as a part of the list.

Rosey commented

😢

Also for some reason
Numeration like 1. 2. 3. converted to 1. 1. 1.

Rosey commented

Also for some reason
Numeration like 1. 2. 3. converted to 1. 1. 1.

This has been fixed

The other main bug I haven't fixed yet as a quick test on https://rosey.github.io/markdown-draft-js/ I'm not seeing the behaviour described (there does seem to be the extra newline when I try it out) and I haven't tried digging any deeper than that yet!

screen shot 2018-08-28 at 14 30 15

Hi Rosey! First of all, really great project here: this has absolutely been a lifesaver, and fits my use-case almost 100%.

I'm experiencing what I believe to be the issue described above. If I create text in Draft.js which displays as such:
screen shot 2018-11-21 at 12 33 04 am

and export/reload, it displays as:

screen shot 2018-11-21 at 12 34 13 am

The exported markdown looks like:
"This is a test list.\n\n\n- Imagine\n- A world\n- Without lists\nHard, isn't it."

My config is pretty vanilla, though my export looks like this:

  draftToCustomMarkdown = (editorState) => {
    const rawContent = convertToRaw(editorState.getCurrentContent());
    const customMarkdownOptions = {
      styleItems: {
        VARIABLE: {
          open: () => '${',
          close: () => '}',
        },
      },
      preserveNewlines: true,
    };
    return draftToMarkdown(rawContent, customMarkdownOptions).replace(/\\_/g, '_');
  }

and I'm loading it back with

const rawContent = markdownToDraft(this.props.text, { preserveNewlines: true });

I'm on version 1.2.1. Let me know if I can give any additional info which would be helpful.

Rosey commented

@mikeappell thanks for putting together this detailed description and I'm sorry I haven't found the time yet to try out your recreation for myself! But I really appreciate you commenting on the issue with this 🙌