mirror of
https://github.com/marktext/marktext.git
synced 2025-05-03 00:19:35 +08:00
fix: #546
This commit is contained in:
parent
79ee58ef7e
commit
2e133e21e0
1
.github/CHANGELOG.md
vendored
1
.github/CHANGELOG.md
vendored
@ -13,6 +13,7 @@
|
||||
- fix: #534
|
||||
- fix: #535 Application menu is not updated when switching windows
|
||||
- fix #216 and #311 key binding issues on Linux and Windows
|
||||
- fix #546 paste issue in table
|
||||
|
||||
### 0.13.50
|
||||
|
||||
|
@ -131,6 +131,18 @@ const pasteCtrl = ContentState => {
|
||||
return this.partialRender()
|
||||
}
|
||||
|
||||
if (/th|td/.test(startBlock.type)) {
|
||||
const pendingText = text.trim().replace(/\n/g, '<br/>')
|
||||
startBlock.text += pendingText
|
||||
const { key } = startBlock
|
||||
const offset = start.offset + pendingText.length
|
||||
this.cursor = {
|
||||
start: { key, offset },
|
||||
end: { key, offset }
|
||||
}
|
||||
return this.partialRender()
|
||||
}
|
||||
|
||||
// handle copyAsHtml
|
||||
if (copyType === 'copyAsHtml') {
|
||||
switch (type) {
|
||||
|
@ -508,8 +508,8 @@ const tokenizerFac = (src, beginRules, inlineRules, pos = 0, top) => {
|
||||
return tokens
|
||||
}
|
||||
|
||||
export const tokenizer = (src, highlights = []) => {
|
||||
const tokens = tokenizerFac(src, beginRules, inlineRules, 0, true)
|
||||
export const tokenizer = (src, highlights = [], hasBeginRules = true) => {
|
||||
const tokens = tokenizerFac(src, hasBeginRules ? beginRules : null, inlineRules, 0, true)
|
||||
const postTokenizer = tokens => {
|
||||
for (const token of tokens) {
|
||||
for (const light of highlights) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import katex from 'katex'
|
||||
import mermaid from 'mermaid'
|
||||
import prism, { loadedCache } from '../../../prism/'
|
||||
import { CLASS_OR_ID, DEVICE_MEMORY, isInElectron, PREVIEW_DOMPURIFY_CONFIG } from '../../../config'
|
||||
import { CLASS_OR_ID, DEVICE_MEMORY, isInElectron, PREVIEW_DOMPURIFY_CONFIG, HAS_TEXT_BLOCK_REG } from '../../../config'
|
||||
import { tokenizer } from '../../parse'
|
||||
import { snakeToCamel, sanitize, escapeHtml, getLongUniqueId } from '../../../utils'
|
||||
import { h, htmlToVNode } from '../snabbdom'
|
||||
@ -70,12 +70,19 @@ export default function renderLeafBlock (block, cursor, activeBlocks, matches, u
|
||||
}
|
||||
let children = ''
|
||||
if (text) {
|
||||
let tokens = null
|
||||
let tokens = []
|
||||
if (highlights.length === 0 && this.tokenCache.has(text)) {
|
||||
tokens = this.tokenCache.get(text)
|
||||
} else {
|
||||
tokens = tokenizer(text, highlights)
|
||||
if (highlights.length === 0 && useCache && DEVICE_MEMORY >= 4) this.tokenCache.set(text, tokens)
|
||||
} else if (
|
||||
HAS_TEXT_BLOCK_REG.test(type) &&
|
||||
functionType !== 'codeLine' &&
|
||||
functionType !== 'languageInput'
|
||||
) {
|
||||
const hasBeginRules = /^(h\d|span|hr)/.test(type)
|
||||
tokens = tokenizer(text, highlights, hasBeginRules)
|
||||
if (highlights.length === 0 && useCache && DEVICE_MEMORY >= 4) {
|
||||
this.tokenCache.set(text, tokens)
|
||||
}
|
||||
}
|
||||
children = tokens.reduce((acc, token) => [...acc, ...this[snakeToCamel(token.type)](h, cursor, block, token)], [])
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user