mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-22 09:30:14 +01:00
This commit is contained in:
parent
4b873f2091
commit
0cac246415
16 changed files with 70 additions and 15 deletions
|
|
@ -7,6 +7,7 @@ import {mindmapRender} from "../render/mindmapRender";
|
|||
import {flowchartRender} from "../render/flowchartRender";
|
||||
import {plantumlRender} from "../render/plantumlRender";
|
||||
import {Constants} from "../../constants";
|
||||
import {htmlRender} from "../render/htmlRender";
|
||||
|
||||
export const processPasteCode = (html: string, text: string) => {
|
||||
const tempElement = document.createElement("div");
|
||||
|
|
@ -31,7 +32,16 @@ export const processPasteCode = (html: string, text: string) => {
|
|||
if (isCode) {
|
||||
let code = text || html;
|
||||
if (/\n/.test(code)) {
|
||||
return `<div data-type="NodeCodeBlock" class="code-block" data-node-id="${Lute.NewNodeID()}"><div class="protyle-action"><span class="protyle-action--first protyle-action__language" contenteditable="false">${window.siyuan.storage[Constants.LOCAL_CODELANG]}</span><span class="fn__flex-1"></span><span class="protyle-icon protyle-icon--first protyle-action__copy"><svg><use xlink:href="#iconCopy"></use></svg></span><span class="protyle-icon protyle-icon--last protyle-action__menu"><svg><use xlink:href="#iconMore"></use></svg></span></div><div contenteditable="true" spellcheck="${window.siyuan.config.editor.spellcheck}">${code.replace(/&/g, "&").replace(/</g, "<")}<wbr></div><div class="protyle-attr" contenteditable="false">${Constants.ZWSP}</div></div>`;
|
||||
return `<div data-type="NodeCodeBlock" class="code-block" data-node-id="${Lute.NewNodeID()}">
|
||||
<div class="protyle-action">
|
||||
<span class="protyle-action--first protyle-action__language" contenteditable="false">${window.siyuan.storage[Constants.LOCAL_CODELANG]}</span>
|
||||
<span class="fn__flex-1"></span>
|
||||
<span aria-label="${window.siyuan.languages.copy}" class="b3-tooltips__nw b3-tooltips protyle-icon protyle-icon--first protyle-action__copy"><svg><use xlink:href="#iconCopy"></use></svg></span>
|
||||
<span aria-label="${window.siyuan.languages.more}" class="b3-tooltips__nw b3-tooltips protyle-icon protyle-icon--last protyle-action__menu"><svg><use xlink:href="#iconMore"></use></svg></span>
|
||||
</div>
|
||||
<div contenteditable="true" spellcheck="${window.siyuan.config.editor.spellcheck}">${code.replace(/&/g, "&").replace(/</g, "<")}<wbr></div>
|
||||
<div class="protyle-attr" contenteditable="false">${Constants.ZWSP}</div>
|
||||
</div>`;
|
||||
} else {
|
||||
// Paste code from IDE no longer escape `<` and `>` https://github.com/siyuan-note/siyuan/issues/8340
|
||||
code = code.replace("<", "<").replace(">", ">");
|
||||
|
|
@ -43,8 +53,9 @@ export const processPasteCode = (html: string, text: string) => {
|
|||
|
||||
export const processRender = (previewPanel: Element) => {
|
||||
const language = previewPanel.getAttribute("data-subtype");
|
||||
if (!["abc", "plantuml", "mermaid", "flowchart", "echarts", "mindmap", "graphviz", "math"].includes(language)) {
|
||||
if (!["abc", "plantuml", "mermaid", "flowchart", "echarts", "mindmap", "graphviz", "math"].includes(language) || previewPanel.getAttribute("data-type") !== "NodeHTMLBlock") {
|
||||
abcRender(previewPanel);
|
||||
htmlRender(previewPanel);
|
||||
plantumlRender(previewPanel);
|
||||
mermaidRender(previewPanel);
|
||||
flowchartRender(previewPanel);
|
||||
|
|
@ -70,5 +81,7 @@ export const processRender = (previewPanel: Element) => {
|
|||
graphvizRender(previewPanel);
|
||||
} else if (language === "math") {
|
||||
mathRender(previewPanel);
|
||||
} else if (previewPanel.getAttribute("data-type") === "NodeHTMLBlock") {
|
||||
htmlRender(previewPanel);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue