1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 09:46:22 +00:00

Add support for converting to MD when paste HTML

This commit is contained in:
Alexander
2018-08-10 13:27:17 +03:00
parent 79fb04126c
commit dac23e38d9
3 changed files with 110 additions and 4 deletions

View File

@@ -14,6 +14,8 @@ import consts from 'browser/lib/consts'
import fs from 'fs'
const { ipcRenderer } = require('electron')
import normalizeEditorFontFamily from 'browser/lib/normalizeEditorFontFamily'
import TurndownService from 'turndown'
import { gfm } from 'turndown-plugin-gfm'
CodeMirror.modeURL = '../node_modules/codemirror/mode/%N/%N.js'
@@ -52,6 +54,9 @@ export default class CodeEditor extends React.Component {
this.searchState = null
this.formatTable = () => this.handleFormatTable()
this.turndownService = new TurndownService()
this.turndownService.use(gfm)
}
handleSearch (msg) {
@@ -406,6 +411,12 @@ export default class CodeEditor extends React.Component {
)
return prevChar === '](' && nextChar === ')'
}
const pastedHtml = clipboardData.getData('text/html')
if (pastedHtml !== '') {
this.handlePasteHtml(e, editor, pastedHtml)
}
if (dataTransferItem.type.match('image')) {
attachmentManagement.handlePastImageEvent(this, storageKey, noteKey, dataTransferItem)
} else if (this.props.fetchUrlTitle && isURL(pastedTxt) && !isInLinkTag(editor)) {
@@ -459,6 +470,12 @@ export default class CodeEditor extends React.Component {
})
}
handlePasteHtml (e, editor, pastedHtml) {
e.preventDefault()
const markdown = this.turndownService.turndown(pastedHtml)
editor.replaceSelection(markdown)
}
mapNormalResponse (response, pastedTxt) {
return this.decodeResponse(response).then((body) => {
return new Promise((resolve, reject) => {