sstur / draft-js-utils

DraftJS: import/export ContentState to and from HTML/Markdown
ISC License
883 stars 233 forks source link

stateFromMarkdown() adds code inline style inside code block #244

Open edwindwalker opened 3 years ago

edwindwalker commented 3 years ago

A very simple reproduction case:

import { stateFromMarkdown } from "draft-js-import-markdown";
import { convertToRaw } from "draft-js";

const editorContent = stateFromMarkdown("```\n1\n2\n3\n```");
console.log(convertToRaw(editorContent));

The output is:

{"blocks":[{"key":"cd9fm","text":"1\n2\n3","type":"code-block","depth":0,"inlineStyleRanges":[{"offset":0,"length":5,"style":"CODE"}],"entityRanges":[],"data":{}}],"entityMap":{}} 

This doesn't seem like the correct result. The block element should be sufficient to enforce the correct styling.

From the source code: https://github.com/sstur/draft-js-utils/blob/35937c2c31979737476ded28de5141c51ecae100/packages/draft-js-import-markdown/src/MarkdownParser.js#L604