From 82b979894b43c38cf82b6c1a0c2bbe282c4ab805 Mon Sep 17 00:00:00 2001 From: caishi <1149225589@qq.com> Date: Tue, 18 Apr 2023 15:44:01 +0800 Subject: [PATCH] md files and xss --- src/App.css | 3 + src/common/marked.js | 14 ++-- src/common/marked1.js | 170 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 181 insertions(+), 6 deletions(-) create mode 100644 src/common/marked1.js diff --git a/src/App.css b/src/App.css index 205c64f7..295f959a 100644 --- a/src/App.css +++ b/src/App.css @@ -97,6 +97,9 @@ body { .editormd-image-click-expand .editormd-image-dialog .image-link { display: none; } +.editormd-fullscreen{ + z-index: 10000; +} /* 解决鼠标框选时,左边第一列没高亮的问题 */ .CodeMirror .CodeMirror-lines pre.CodeMirror-line, diff --git a/src/common/marked.js b/src/common/marked.js index f81f7b13..22ac47c8 100644 --- a/src/common/marked.js +++ b/src/common/marked.js @@ -23,6 +23,7 @@ function indentCodeCompensation(raw, text) { .join('\n'); } + //兼容之前的 ##标题式写法 let toc = [] let ctx = ["") } - ctx.push("") + ctx.push(""); k = buildToc(coll, k, level, ctx) return k } export function getTocContent() { - buildToc(toc, 0, 0, ctx) - ctx.push("") - return ctx.join("") + buildToc(toc, 0, 0, ctx); + ctx.push(""); + return ctx.join(""); } const tokenizer = { @@ -117,6 +118,7 @@ function replace_math_with_ids(text) { return rs } + const original_listitem = renderer.listitem renderer.listitem = function (text, task, checked) { return original_listitem(replace_math_with_ids(text), task, checked) @@ -155,9 +157,9 @@ renderer.heading = function (text, level, raw) { level: level, text: text }) - return '' + text + '' + let id = anchor.replace(/[.,/#!$%^&*;:{}=\-_`~():,。¥;「」|?》《~·【】‘、!]/g,""); + return '' + text + '' } - marked.setOptions({ silent: true, smartypants: true, diff --git a/src/common/marked1.js b/src/common/marked1.js new file mode 100644 index 00000000..f81f7b13 --- /dev/null +++ b/src/common/marked1.js @@ -0,0 +1,170 @@ +import marked from 'marked' +import { escape } from 'marked/src/helpers' + +function indentCodeCompensation(raw, text) { + const matchIndentToCode = raw.match(/^(\s+)(?:```)/); + if (matchIndentToCode === null) { + return text; + } + const indentToCode = matchIndentToCode[1]; + return text + .split('\n') + .map(node => { + const matchIndentInNode = node.match(/^\s+/); + if (matchIndentInNode === null) { + return node; + } + const [indentInNode] = matchIndentInNode; + if (indentInNode.length >= indentToCode.length) { + return node.slice(indentToCode.length); + } + return node; + }) + .join('\n'); +} + +//兼容之前的 ##标题式写法 +let toc = [] +let ctx = ["