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

Error with markdownToDraft and tables #79

Closed samuelcolvin closed 6 years ago

samuelcolvin commented 6 years ago

as per the example below, markdownToDraft does strange things with tables, they're converted to just the last value in the last row, plus the line before the table is removed.

I know markdown-draft-js (understandably) doesn't support tables fully but it would be great if it could just leave them alone rather than messing them up.

(the draftToMarkdown in the last line is unnecessary, it's just there to demonstrate more clearly what the output looks like).

const v = 'this is the first line.\n' +
          '\n' +
          'this is the second line.\n' +
          '\n' +
          '| foo | bar |\n' +
          '| --- | --- |\n' +
          '| baz | bim |\n' +
          '\n' +
          'This is another line under the table.'

const s = EditorState.createWithContent(convertFromRaw(markdownToDraft(v)))
const raw = convertToRaw(s.getCurrentContent())
console.log(JSON.stringify(raw, null, 2))
console.log(draftToMarkdown(raw))
{
  "blocks": [
    {
      "key": "d2fmf",
      "text": "this is the first line.",
      "type": "unstyled",
      "depth": 0,
      "inlineStyleRanges": [],
      "entityRanges": [],
      "data": {}
    },
    {
      "key": "5155o",
      "text": "bim",
      "type": "unstyled",
      "depth": 0,
      "inlineStyleRanges": [],
      "entityRanges": [],
      "data": {}
    },
    {
      "key": "c784q",
      "text": "This is another line under the table.",
      "type": "unstyled",
      "depth": 0,
      "inlineStyleRanges": [],
      "entityRanges": [],
      "data": {}
    }
  ],
  "entityMap": {}
}
------------------------------------------------------------------------------------
this is the first line.

bim

This is another line under the table.
samuelcolvin commented 6 years ago

This seems to be a problem with the line below the heading in the table | --- | --- | without that it seems to work fine.

Rosey commented 6 years ago

Oh thanks! This turned out to be a fairly easy fix, so here it is - https://github.com/Rosey/markdown-draft-js/pull/81 😄

samuelcolvin commented 6 years ago

Great, thanks.