Error with markdownToDraft and tables
Closed this issue · 3 comments
samuelcolvin commented
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
This seems to be a problem with the line below the heading in the table | --- | --- |
without that it seems to work fine.
samuelcolvin commented
Great, thanks.