handle raw editor html pastes with unified
This commit is contained in:
parent
b5e0be43f2
commit
b22323201d
@ -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",
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user