Skip to content

Commit

Permalink
#913
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Jan 30, 2021
1 parent 814abe5 commit 8706e0d
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 41 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,14 @@

### v3.8.0 / 2021-01-xx

* [913](https://github.com/Vanessa219/vditor/pull/913) 支持plantuml `引入特性`
* [907](https://github.com/Vanessa219/vditor/issues/907) mathjax 在method.min.js 中preview 显示错误 `修复缺陷`
* [909](https://github.com/Vanessa219/vditor/issues/909) toc 和大纲中数学公式显示问题修复 `修复缺陷`
* [908](https://github.com/Vanessa219/vditor/issues/908) 粘贴不了 MS Office Excel 内容的问题 `修复缺陷`

* 文档修改
* 3.8.0
* 添加 plantumlRender 方法

### v3.7.7 / 2021-01-19

* [903](https://github.com/Vanessa219/vditor/issues/903) 使用 setValue 后第一次输入无法撤销 `修复缺陷`
Expand Down
1 change: 0 additions & 1 deletion src/assets/scss/_reset.scss
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@
}

.language-echarts,
.language-plantuml,
.language-mindmap {
overflow: hidden;
height: 420px;
Expand Down
1 change: 1 addition & 0 deletions src/js/plantuml/plantuml-encoder.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {mathRender} from "./ts/markdown/mathRender";
import {mediaRender} from "./ts/markdown/mediaRender";
import {mermaidRender} from "./ts/markdown/mermaidRender";
import {mindmapRender} from "./ts/markdown/mindmapRender";
import {plantumlRender} from "./ts/markdown/plantumlRender";
import {outlineRender} from "./ts/markdown/outlineRender";
import {plantumlRender} from "./ts/markdown/plantumlRender";
import {md2html, previewRender} from "./ts/markdown/previewRender";
import {speechRender} from "./ts/markdown/speechRender";
import { previewImage } from "./ts/preview/image";
Expand Down
50 changes: 22 additions & 28 deletions src/ts/markdown/plantumlRender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,32 @@ declare const plantumlEncoder: {
encode(options: string): string,
};

export const plantumlRender = (element: HTMLElement, cdn = Constants.CDN, theme: string) => {
export const plantumlRender = (element: HTMLElement, cdn = Constants.CDN) => {
const plantumlElements = element.querySelectorAll(".language-plantuml");
if (plantumlElements.length === 0) {
return;
}
addScript(`https://cdn.jsdelivr.net/gh/jmnote/plantuml[email protected]/dist/plantuml-encoder.min.js`, "vditorPlantumlEncoderScript").then(() => {
addScript(`${cdn}/dist/js/plantuml/plantuml-encoder.min.js`, "vditorPlantumlScript").then(() => {
plantumlElements.forEach((e: HTMLDivElement) => {
if (e.parentElement.classList.contains("vditor-wysiwyg__pre") ||
e.parentElement.classList.contains("vditor-ir__marker--pre")) {
return;
}
const text = e.innerText.trim();
if (!text) {
return;
}
try {
if (e.getAttribute("data-processed") === "true") {
return;
}

const encoded = plantumlEncoder.encode(text)
const imageElement = document.createElement("IMG");
imageElement.setAttribute("loading", "lazy")
imageElement.setAttribute("src", 'http://www.plantuml.com/plantuml/svg/~1' + encoded)
e.parentNode.insertBefore(imageElement, e);
e.style.display = 'none';

e.setAttribute("data-processed", "true");
} catch (error) {
e.className = "vditor-reset--error";
e.innerHTML = `plantuml render error: <br>${error}`;
}
});
if (e.parentElement.classList.contains("vditor-wysiwyg__pre") ||
e.parentElement.classList.contains("vditor-ir__marker--pre")) {
return;
}
const text = e.innerText.trim();
if (!text) {
return;
}
try {
const encoded = plantumlEncoder.encode(text);
const imageElement = document.createElement("img");
imageElement.setAttribute("loading", "lazy");
imageElement.setAttribute("src", "http://www.plantuml.com/plantuml/svg/~1" + encoded);
e.parentNode.insertBefore(imageElement, e);
e.remove();
} catch (error) {
e.className = "vditor-reset--error";
e.innerHTML = `plantuml render error: <br>${error}`;
}
});
});
};
2 changes: 1 addition & 1 deletion src/ts/markdown/previewRender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export const previewRender = async (previewElement: HTMLDivElement, markdown: st
graphvizRender(previewElement, mergedOptions.cdn);
chartRender(previewElement, mergedOptions.cdn, mergedOptions.mode);
mindmapRender(previewElement, mergedOptions.cdn, mergedOptions.mode);
plantumlRender(previewElement, mergedOptions.cdn, mergedOptions.mode);
plantumlRender(previewElement, mergedOptions.cdn);
abcRender(previewElement, mergedOptions.cdn);
mediaRender(previewElement);
if (mergedOptions.speech.enable) {
Expand Down
2 changes: 1 addition & 1 deletion src/ts/preview/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export class Preview {
graphvizRender(vditor.preview.element.lastElementChild as HTMLElement, vditor.options.cdn);
chartRender(vditor.preview.element.lastElementChild as HTMLElement, vditor.options.cdn, vditor.options.theme);
mindmapRender(vditor.preview.element.lastElementChild as HTMLElement, vditor.options.cdn, vditor.options.theme);
plantumlRender(vditor.preview.element.lastElementChild as HTMLElement, vditor.options.cdn, vditor.options.theme);
plantumlRender(vditor.preview.element.lastElementChild as HTMLElement, vditor.options.cdn);
abcRender(vditor.preview.element.lastElementChild as HTMLElement, vditor.options.cdn);
mediaRender(vditor.preview.element.lastElementChild as HTMLElement);
// toc render
Expand Down
2 changes: 1 addition & 1 deletion src/ts/util/processCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const processCodeRender = (previewPanel: HTMLElement, vditor: IVditor) =>
} else if (language === "mindmap") {
mindmapRender(previewPanel, vditor.options.cdn, vditor.options.theme);
} else if (language === "plantuml") {
plantumlRender(previewPanel, vditor.options.cdn, vditor.options.theme);
plantumlRender(previewPanel, vditor.options.cdn);
} else if (language === "graphviz") {
graphvizRender(previewPanel, vditor.options.cdn);
} else if (language === "math") {
Expand Down
16 changes: 9 additions & 7 deletions src/ts/wysiwyg/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ class WYSIWYG {
`<span class="vditor-comment" data-cmtids="${id}">${item.innerHTML}</span>`;
blockEndElement = item;
} else if (item.nodeType !== 3 && item.getAttribute("data-block") === "0") {
if (index === 0) {
removeStart = true;
} else if (index === contents.childNodes.length - 1) {
removeEnd = true;
}
item.innerHTML =
if (index === 0) {
removeStart = true;
} else if (index === contents.childNodes.length - 1) {
removeEnd = true;
}
item.innerHTML =
`<span class="vditor-comment" data-cmtids="${id}">${item.innerHTML}</span>`;
} else {
const commentElement = document.createElement("span");
Expand Down Expand Up @@ -400,7 +400,9 @@ class WYSIWYG {
return;
}

if (event.target.tagName === "IMG") {
if (event.target.tagName === "IMG" &&
// plantuml 图片渲染不进行提示
!event.target.parentElement.classList.contains("vditor-wysiwyg__preview")) {
if (event.target.getAttribute("data-type") === "link-ref") {
genLinkRefPopover(vditor, event.target);
} else {
Expand Down

0 comments on commit 8706e0d

Please sign in to comment.