Rosey / markdown-draft-js

A tool to convert content created in DraftJS to markdown and vice versa.
https://rosey.github.io/markdown-draft-js/
MIT License
318 stars 69 forks source link

Incorrect list conversion #71

Closed igorlesnenko closed 5 years ago

igorlesnenko commented 6 years ago

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 6 years ago

😢

nicholaswbowen commented 6 years ago

It's technically correct. If you run that markdown through remarkable it will still render properly, you don't individually number an ordered list in html.

On Tue, Aug 14, 2018, 3:56 PM Rose notifications@github.com wrote:

😢

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Rosey/markdown-draft-js/issues/71#issuecomment-413041994, or mute the thread https://github.com/notifications/unsubscribe-auth/AWSGaHYox7u1qRw-jKjfklRDk0DkeECAks5uQ1WXgaJpZM4V9Ox7 .

nicholaswbowen commented 6 years ago

I totally misread the issue, disregard the above :D .

On Tue, Aug 14, 2018, 6:37 PM Nicholas Bowen nicholas.w.bowen@gmail.com wrote:

It's technically correct. If you run that markdown through remarkable it will still render properly, you don't individually number an ordered list in html.

On Tue, Aug 14, 2018, 3:56 PM Rose notifications@github.com wrote:

😢

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Rosey/markdown-draft-js/issues/71#issuecomment-413041994, or mute the thread https://github.com/notifications/unsubscribe-auth/AWSGaHYox7u1qRw-jKjfklRDk0DkeECAks5uQ1WXgaJpZM4V9Ox7 .

igorlesnenko commented 6 years ago

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

Rosey commented 6 years ago

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
mikeappell commented 5 years ago

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 5 years ago

@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 🙌