diff --git a/package.json b/package.json index cbfddc32..4ea7e840 100644 --- a/package.json +++ b/package.json @@ -158,10 +158,12 @@ "redux-optimist": "^0.0.2", "redux-thunk": "^1.0.3", "rehype-parse": "^3.1.0", + "rehype-remark": "^2.0.0", "rehype-stringify": "^3.0.0", "remark-html": "^6.0.0", "remark-parse": "^3.0.1", "remark-rehype": "^2.0.0", + "remark-stringify": "^3.0.1", "selection-position": "^1.0.0", "semaphore": "^1.0.5", "slate": "^0.14.14", diff --git a/src/components/Widgets/MarkdownControlElements/RawEditor/index.js b/src/components/Widgets/MarkdownControlElements/RawEditor/index.js index 649f41af..4dba11fe 100644 --- a/src/components/Widgets/MarkdownControlElements/RawEditor/index.js +++ b/src/components/Widgets/MarkdownControlElements/RawEditor/index.js @@ -1,7 +1,8 @@ import React, { PropTypes } from 'react'; -import MarkupIt from 'markup-it'; -import markdownSyntax from 'markup-it/syntaxes/markdown'; -import htmlSyntax from 'markup-it/syntaxes/html'; +import unified from 'unified'; +import htmlToRehype from 'rehype-parse'; +import rehypeToRemark from 'rehype-remark'; +import remarkToMarkdown from 'remark-stringify'; import CaretPosition from 'textarea-caret-position'; import TextareaAutosize from 'react-textarea-autosize'; import registry from '../../../../lib/registry'; @@ -12,9 +13,6 @@ import styles from './index.css'; const HAS_LINE_BREAK = /\n/m; -const markdown = new MarkupIt(markdownSyntax); -const html = new MarkupIt(htmlSyntax); - function processUrl(url) { if (url.match(/^(https?:\/\/|mailto:|\/)/)) { return url; @@ -26,8 +24,11 @@ function processUrl(url) { } function cleanupPaste(paste) { - const content = html.toContent(paste); - return markdown.toText(content); + return unified() + .use(htmlToRehype) + .use(rehypeToRemark) + .use(remarkToMarkdown) + .process(paste); } function getCleanPaste(e) {