upd: optimize code to html

This commit is contained in:
purocean
2021-12-20 23:15:52 +08:00
parent c514a0b7a5
commit b5ef9ffe9c
3 changed files with 9 additions and 3 deletions
+2 -2
View File
@@ -83,7 +83,7 @@ const RunCode = defineComponent({
const runResult = result.value || cache[hash.value]
return [
h('div', { class: 'p-mcr-run-code-action' }, [
h('div', { class: 'p-mcr-run-code-action skip-export' }, [
h('div', {
title: t('code-run.run'),
class: 'p-mcr-run-btn',
@@ -96,7 +96,7 @@ const RunCode = defineComponent({
onClick: runInXterm
}),
]),
h('div', { class: 'p-mcr-run-code-result', style: 'padding: .5em 0 0 0', key: runResult, innerHTML: runResult }),
h('div', { class: 'p-mcr-run-code-result skip-export', style: 'padding: .5em 0 0 0', key: runResult, innerHTML: runResult }),
h('div', { class: 'p-mcr-clear-btn-wrapper no-print' }, h(
h(
'div',
@@ -68,6 +68,7 @@ defaultRules.code_block = function (tokens: Token[], idx: number, _: any, __: an
defaultRules.fence = function (tokens: Token[], idx: number, options: any, _: any, slf: Renderer) {
const token = tokens[idx]
const info = token.info ? unescapeAll(token.info).trim() : ''
token.attrSet('data-export-text', token.content)
let langName = ''
let langAttrs = ''
let highlighted: any; let i; let arr; let tmpAttrs; let tmpToken
+6 -1
View File
@@ -1,3 +1,4 @@
import { escape } from 'lodash-es'
import { Escape } from '@fe/core/command'
import { getActionHandler, registerAction } from '@fe/core/action'
import { useToast } from '@fe/support/ui/toast'
@@ -73,12 +74,16 @@ export function getContentHtml (nodeProcessor?: (node: HTMLElement) => void) {
}
const filter = (node: HTMLElement) => {
if (node.classList.contains('no-print')) {
if (node.classList.contains('no-print') || node.classList.contains('skip-export')) {
node.remove()
return
}
if (node.dataset) {
if (node.dataset.exportText) {
node.innerHTML = escape(node.dataset.exportText)
}
Object.keys(node.dataset).forEach(key => {
delete node.dataset[key]
})