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-optimist": "^0.0.2",
|
||||||
"redux-thunk": "^1.0.3",
|
"redux-thunk": "^1.0.3",
|
||||||
"rehype-parse": "^3.1.0",
|
"rehype-parse": "^3.1.0",
|
||||||
|
"rehype-remark": "^2.0.0",
|
||||||
"rehype-stringify": "^3.0.0",
|
"rehype-stringify": "^3.0.0",
|
||||||
"remark-html": "^6.0.0",
|
"remark-html": "^6.0.0",
|
||||||
"remark-parse": "^3.0.1",
|
"remark-parse": "^3.0.1",
|
||||||
"remark-rehype": "^2.0.0",
|
"remark-rehype": "^2.0.0",
|
||||||
|
"remark-stringify": "^3.0.1",
|
||||||
"selection-position": "^1.0.0",
|
"selection-position": "^1.0.0",
|
||||||
"semaphore": "^1.0.5",
|
"semaphore": "^1.0.5",
|
||||||
"slate": "^0.14.14",
|
"slate": "^0.14.14",
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import React, { PropTypes } from 'react';
|
import React, { PropTypes } from 'react';
|
||||||
import MarkupIt from 'markup-it';
|
import unified from 'unified';
|
||||||
import markdownSyntax from 'markup-it/syntaxes/markdown';
|
import htmlToRehype from 'rehype-parse';
|
||||||
import htmlSyntax from 'markup-it/syntaxes/html';
|
import rehypeToRemark from 'rehype-remark';
|
||||||
|
import remarkToMarkdown from 'remark-stringify';
|
||||||
import CaretPosition from 'textarea-caret-position';
|
import CaretPosition from 'textarea-caret-position';
|
||||||
import TextareaAutosize from 'react-textarea-autosize';
|
import TextareaAutosize from 'react-textarea-autosize';
|
||||||
import registry from '../../../../lib/registry';
|
import registry from '../../../../lib/registry';
|
||||||
@ -12,9 +13,6 @@ import styles from './index.css';
|
|||||||
|
|
||||||
const HAS_LINE_BREAK = /\n/m;
|
const HAS_LINE_BREAK = /\n/m;
|
||||||
|
|
||||||
const markdown = new MarkupIt(markdownSyntax);
|
|
||||||
const html = new MarkupIt(htmlSyntax);
|
|
||||||
|
|
||||||
function processUrl(url) {
|
function processUrl(url) {
|
||||||
if (url.match(/^(https?:\/\/|mailto:|\/)/)) {
|
if (url.match(/^(https?:\/\/|mailto:|\/)/)) {
|
||||||
return url;
|
return url;
|
||||||
@ -26,8 +24,11 @@ function processUrl(url) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function cleanupPaste(paste) {
|
function cleanupPaste(paste) {
|
||||||
const content = html.toContent(paste);
|
return unified()
|
||||||
return markdown.toText(content);
|
.use(htmlToRehype)
|
||||||
|
.use(rehypeToRemark)
|
||||||
|
.use(remarkToMarkdown)
|
||||||
|
.process(paste);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCleanPaste(e) {
|
function getCleanPaste(e) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user