|
|
|
@ -6,7 +6,8 @@ import textareaAutosizeInit from "./textarea.autosize"
@@ -6,7 +6,8 @@ import textareaAutosizeInit from "./textarea.autosize"
|
|
|
|
|
import createCursor from './cursor' |
|
|
|
|
import Store from './store' |
|
|
|
|
import Keymap from './keymap' |
|
|
|
|
import getCaretCoordinates from "../editor/src/caret-position"; |
|
|
|
|
import getCaretCoordinates from "../editor/src/caret-position" |
|
|
|
|
import TurndownService from "turndown" |
|
|
|
|
|
|
|
|
|
textareaAutosizeInit($) |
|
|
|
|
|
|
|
|
@ -508,6 +509,34 @@ function editor(root, inputData, options) {
@@ -508,6 +509,34 @@ function editor(root, inputData, options) {
|
|
|
|
|
return true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (event.originalEvent.clipboardData.types.includes("text/html")) { |
|
|
|
|
let pastedData = event.originalEvent.clipboardData.getData('text/html') |
|
|
|
|
const turndownService = new TurndownService({ |
|
|
|
|
headingStyle: 'atx', |
|
|
|
|
codeBlockStyle: 'fenced', |
|
|
|
|
}) |
|
|
|
|
const markdown = turndownService.turndown(pastedData) |
|
|
|
|
let items = markdown.split(/\n+/); |
|
|
|
|
console.log(items) |
|
|
|
|
let item = $(this).parents('.list-item') |
|
|
|
|
let id = item.attr('data-id') |
|
|
|
|
const firstItem = store.value(id) |
|
|
|
|
items = _.map(items, text => { |
|
|
|
|
const m = text.match(/^(\s*)\*\s*(.*)$/) |
|
|
|
|
if (m) { |
|
|
|
|
const item = newListItem(firstItem.indented+1+Math.trunc(m[1].length/4)) |
|
|
|
|
item.text = m[2] |
|
|
|
|
return item |
|
|
|
|
} |
|
|
|
|
const item = newListItem(firstItem.indented) |
|
|
|
|
item.text = text |
|
|
|
|
return item |
|
|
|
|
}) |
|
|
|
|
store.insertAfter(id, ...items) |
|
|
|
|
trigger('change') |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let pastedData = event.originalEvent.clipboardData.getData('text/plain') |
|
|
|
|
try { |
|
|
|
|
let items = JSON.parse(pastedData.toString()); |
|
|
|
|