mirror of
https://github.com/marktext/marktext.git
synced 2025-05-02 07:31:18 +08:00
feature: copy table from Number
This commit is contained in:
parent
30de74e866
commit
2c8814c5ee
@ -1,4 +1,7 @@
|
|||||||
import { PARAGRAPH_TYPES } from '../config'
|
import cheerio from 'cheerio'
|
||||||
|
import { sanitize } from '../utils'
|
||||||
|
import { PARAGRAPH_TYPES, PREVIEW_DOMPURIFY_CONFIG } from '../config'
|
||||||
|
|
||||||
const LIST_REG = /ul|ol/
|
const LIST_REG = /ul|ol/
|
||||||
const LINE_BREAKS_REG = /\n/
|
const LINE_BREAKS_REG = /\n/
|
||||||
|
|
||||||
@ -37,6 +40,33 @@ const pasteCtrl = ContentState => {
|
|||||||
return type
|
return type
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ContentState.prototype.standardizeHTML = function (html) {
|
||||||
|
const $ = cheerio.load(sanitize(html, PREVIEW_DOMPURIFY_CONFIG))
|
||||||
|
// convert un-standard table to standard table which can be identified by turndown.
|
||||||
|
// These un-standard table mainly copy from Number app.
|
||||||
|
const tables = $('table')
|
||||||
|
if (tables.length > 0) {
|
||||||
|
tables.each((i, t) => {
|
||||||
|
const table = $(t)
|
||||||
|
table.find('tr').each((i, tr) => {
|
||||||
|
if (i === 0 && $(tr).children().first().tagName !== 'th') {
|
||||||
|
$(tr).children().each((i, td) => {
|
||||||
|
const html = $(td).html()
|
||||||
|
$(td).replaceWith($(`<th>${html}</th>`))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
table.find('p').each((i, p) => {
|
||||||
|
const html = $(p).html()
|
||||||
|
$(p).replaceWith($(`<span>${html}</span>`))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return $('body').html()
|
||||||
|
}
|
||||||
|
|
||||||
// handle `normal` and `pasteAsPlainText` paste
|
// handle `normal` and `pasteAsPlainText` paste
|
||||||
ContentState.prototype.pasteHandler = function (event, type) {
|
ContentState.prototype.pasteHandler = function (event, type) {
|
||||||
if (this.checkInCodeBlock()) {
|
if (this.checkInCodeBlock()) {
|
||||||
@ -44,7 +74,8 @@ const pasteCtrl = ContentState => {
|
|||||||
}
|
}
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
const text = event.clipboardData.getData('text/plain')
|
const text = event.clipboardData.getData('text/plain')
|
||||||
const html = event.clipboardData.getData('text/html')
|
let html = event.clipboardData.getData('text/html')
|
||||||
|
html = this.standardizeHTML(html)
|
||||||
// console.log(text)
|
// console.log(text)
|
||||||
// console.log(html)
|
// console.log(html)
|
||||||
const copyType = this.checkCopyType(html, text)
|
const copyType = this.checkCopyType(html, text)
|
||||||
@ -66,7 +97,6 @@ const pasteCtrl = ContentState => {
|
|||||||
end: { key, offset }
|
end: { key, offset }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle copyAsHtml
|
// handle copyAsHtml
|
||||||
if (copyType === 'copyAsHtml') {
|
if (copyType === 'copyAsHtml') {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
@ -15,6 +15,11 @@
|
|||||||
--extraLightBorder: #F2F6FC;
|
--extraLightBorder: #F2F6FC;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
html {
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@keyframes highlight {
|
@keyframes highlight {
|
||||||
from {
|
from {
|
||||||
transform: scale(1);
|
transform: scale(1);
|
||||||
|
@ -5,7 +5,7 @@ import appWindow from '../window'
|
|||||||
export const selectTheme = (theme, themeCSS) => {
|
export const selectTheme = (theme, themeCSS) => {
|
||||||
userPreference.setItem('theme', theme)
|
userPreference.setItem('theme', theme)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
for (const win of appWindow.windows.values()) {
|
for (const { win } of appWindow.windows.values()) {
|
||||||
win.webContents.send('AGANI::user-preference', { theme })
|
win.webContents.send('AGANI::user-preference', { theme })
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -5,6 +5,34 @@
|
|||||||
|
|
||||||
@include-when-export url(https://fonts.googleapis.com/css?family=Open+Sans:400italic,700italic,700,400&subset=latin,latin-ext);
|
@include-when-export url(https://fonts.googleapis.com/css?family=Open+Sans:400italic,700italic,700,400&subset=latin,latin-ext);
|
||||||
|
|
||||||
|
@font-face {
|
||||||
|
font-family: 'Open Sans';
|
||||||
|
font-style: normal;
|
||||||
|
font-weight: normal;
|
||||||
|
src: local('Open Sans Regular'),url('./github/400.woff') format('woff')
|
||||||
|
}
|
||||||
|
|
||||||
|
@font-face {
|
||||||
|
font-family: 'Open Sans';
|
||||||
|
font-style: italic;
|
||||||
|
font-weight: normal;
|
||||||
|
src: local('Open Sans Italic'),url('./github/400i.woff') format('woff')
|
||||||
|
}
|
||||||
|
|
||||||
|
@font-face {
|
||||||
|
font-family: 'Open Sans';
|
||||||
|
font-style: normal;
|
||||||
|
font-weight: bold;
|
||||||
|
src: local('Open Sans Bold'),url('./github/700.woff') format('woff')
|
||||||
|
}
|
||||||
|
|
||||||
|
@font-face {
|
||||||
|
font-family: 'Open Sans';
|
||||||
|
font-style: italic;
|
||||||
|
font-weight: bold;
|
||||||
|
src: local('Open Sans Bold Italic'),url('./github/700i.woff') format('woff')
|
||||||
|
}
|
||||||
|
|
||||||
html, body {
|
html, body {
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,34 @@
|
|||||||
|
|
||||||
@include-when-export url(https://fonts.googleapis.com/css?family=Open+Sans:400italic,700italic,700,400&subset=latin,latin-ext);
|
@include-when-export url(https://fonts.googleapis.com/css?family=Open+Sans:400italic,700italic,700,400&subset=latin,latin-ext);
|
||||||
|
|
||||||
|
@font-face {
|
||||||
|
font-family: 'Open Sans';
|
||||||
|
font-style: normal;
|
||||||
|
font-weight: normal;
|
||||||
|
src: local('Open Sans Regular'),url('./github/400.woff') format('woff')
|
||||||
|
}
|
||||||
|
|
||||||
|
@font-face {
|
||||||
|
font-family: 'Open Sans';
|
||||||
|
font-style: italic;
|
||||||
|
font-weight: normal;
|
||||||
|
src: local('Open Sans Italic'),url('./github/400i.woff') format('woff')
|
||||||
|
}
|
||||||
|
|
||||||
|
@font-face {
|
||||||
|
font-family: 'Open Sans';
|
||||||
|
font-style: normal;
|
||||||
|
font-weight: bold;
|
||||||
|
src: local('Open Sans Bold'),url('./github/700.woff') format('woff')
|
||||||
|
}
|
||||||
|
|
||||||
|
@font-face {
|
||||||
|
font-family: 'Open Sans';
|
||||||
|
font-style: italic;
|
||||||
|
font-weight: bold;
|
||||||
|
src: local('Open Sans Bold Italic'),url('./github/700i.woff') format('woff')
|
||||||
|
}
|
||||||
|
|
||||||
html, body {
|
html, body {
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
background: rgb(252, 252, 252);
|
background: rgb(252, 252, 252);
|
||||||
|
Loading…
Reference in New Issue
Block a user