vditor 3.10.1 → 3.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.css +4 -1
- package/dist/index.min.js +1 -1
- package/dist/method.d.ts +2 -2
- package/dist/method.min.js +1 -1
- package/dist/ts/util/function.d.ts +1 -0
- package/package.json +1 -1
- package/src/assets/less/_reset.less +520 -516
- package/src/ts/markdown/mediaRender.ts +30 -3
- package/src/ts/markdown/mermaidRender.ts +16 -5
- package/src/ts/markdown/plantumlRender.ts +1 -1
- package/src/ts/util/function.ts +8 -0
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import {getSearch} from "../util/function";
|
|
2
|
+
|
|
1
3
|
const videoRender = (element: HTMLElement, url: string) => {
|
|
2
4
|
element.insertAdjacentHTML("afterend", `<video controls="controls" src="${url}"></video>`);
|
|
3
5
|
element.remove();
|
|
@@ -46,10 +48,35 @@ const iframeRender = (element: HTMLElement, url: string) => {
|
|
|
46
48
|
`<iframe class="iframe__video"
|
|
47
49
|
src="https://www.dailymotion.com/embed/video/${dailymotionMatch[2]}"></iframe>`);
|
|
48
50
|
element.remove();
|
|
49
|
-
} else if (bilibiliMatch && bilibiliMatch[1]) {
|
|
51
|
+
} else if (url.indexOf("bilibili.com") > -1 && (url.indexOf("bvid=") > -1 || (bilibiliMatch && bilibiliMatch[1]))) {
|
|
52
|
+
const params: IObject = {
|
|
53
|
+
bvid: getSearch("bvid", url) || (bilibiliMatch && bilibiliMatch[1]),
|
|
54
|
+
page: "1",
|
|
55
|
+
high_quality: "1",
|
|
56
|
+
as_wide: "1",
|
|
57
|
+
allowfullscreen: "true",
|
|
58
|
+
autoplay: "0"
|
|
59
|
+
};
|
|
60
|
+
new URL(url.startsWith("http") ? url : "https:" + url).search.split("&").forEach((item, index) => {
|
|
61
|
+
if (!item) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (index === 0) {
|
|
65
|
+
item = item.substr(1);
|
|
66
|
+
}
|
|
67
|
+
const keyValue = item.split("=");
|
|
68
|
+
params[keyValue[0]] = keyValue[1];
|
|
69
|
+
});
|
|
70
|
+
let src = "https://player.bilibili.com/player.html?";
|
|
71
|
+
const keys = Object.keys(params);
|
|
72
|
+
keys.forEach((key, index) => {
|
|
73
|
+
src += `${key}=${params[key]}`;
|
|
74
|
+
if (index < keys.length - 1) {
|
|
75
|
+
src += "&";
|
|
76
|
+
}
|
|
77
|
+
});
|
|
50
78
|
element.insertAdjacentHTML("afterend",
|
|
51
|
-
`<iframe class="iframe__video"
|
|
52
|
-
src="//player.bilibili.com/player.html?bvid=${bilibiliMatch[1]}"></iframe>`);
|
|
79
|
+
`<iframe class="iframe__video" src="${src}"></iframe>`);
|
|
53
80
|
element.remove();
|
|
54
81
|
} else if (tedMatch && tedMatch[1]) {
|
|
55
82
|
element.insertAdjacentHTML("afterend",
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import {Constants} from "../constants";
|
|
2
2
|
import {addScript} from "../util/addScript";
|
|
3
3
|
import {mermaidRenderAdapter} from "./adapterRender";
|
|
4
|
+
import {genUUID} from "../util/function";
|
|
4
5
|
|
|
5
6
|
declare const mermaid: {
|
|
6
7
|
initialize(options: any): void,
|
|
7
|
-
|
|
8
|
+
render(id: string, text: string): { svg: string }
|
|
8
9
|
};
|
|
9
10
|
|
|
10
11
|
export const mermaidRender = (element: HTMLElement, cdn = Constants.CDN, theme: string) => {
|
|
@@ -12,7 +13,7 @@ export const mermaidRender = (element: HTMLElement, cdn = Constants.CDN, theme:
|
|
|
12
13
|
if (mermaidElements.length === 0) {
|
|
13
14
|
return;
|
|
14
15
|
}
|
|
15
|
-
addScript(`${cdn}/dist/js/mermaid/mermaid.min.js
|
|
16
|
+
addScript(`${cdn}/dist/js/mermaid/mermaid.min.js`, "vditorMermaidScript").then(() => {
|
|
16
17
|
const config: any = {
|
|
17
18
|
securityLevel: "loose", // 升级后无 https://github.com/siyuan-note/siyuan/issues/3587,可使用该选项
|
|
18
19
|
altFontFamily: "sans-serif",
|
|
@@ -26,7 +27,8 @@ export const mermaidRender = (element: HTMLElement, cdn = Constants.CDN, theme:
|
|
|
26
27
|
useMaxWidth: true,
|
|
27
28
|
diagramMarginX: 8,
|
|
28
29
|
diagramMarginY: 8,
|
|
29
|
-
boxMargin: 8
|
|
30
|
+
boxMargin: 8,
|
|
31
|
+
showSequenceNumbers: true // Mermaid 时序图增加序号 https://github.com/siyuan-note/siyuan/pull/6992 https://mermaid.js.org/syntax/sequenceDiagram.html#sequencenumbers
|
|
30
32
|
},
|
|
31
33
|
gantt: {
|
|
32
34
|
leftPadding: 75,
|
|
@@ -37,12 +39,21 @@ export const mermaidRender = (element: HTMLElement, cdn = Constants.CDN, theme:
|
|
|
37
39
|
config.theme = "dark";
|
|
38
40
|
}
|
|
39
41
|
mermaid.initialize(config);
|
|
40
|
-
mermaidElements.forEach((item) => {
|
|
42
|
+
mermaidElements.forEach(async (item) => {
|
|
41
43
|
const code = mermaidRenderAdapter.getCode(item);
|
|
42
44
|
if (item.getAttribute("data-processed") === "true" || code.trim() === "") {
|
|
43
45
|
return;
|
|
44
46
|
}
|
|
45
|
-
mermaid
|
|
47
|
+
const id = "mermaid"+genUUID()
|
|
48
|
+
try {
|
|
49
|
+
const mermaidData = await mermaid.render(id, item.textContent);
|
|
50
|
+
item.innerHTML = mermaidData.svg;
|
|
51
|
+
} catch (e) {
|
|
52
|
+
const errorElement = document.querySelector("#" + id);
|
|
53
|
+
item.innerHTML = `${errorElement.outerHTML}<br>
|
|
54
|
+
<div style="text-align: left"><small>${e.message.replace(/\n/, "<br>")}</small></div>`;
|
|
55
|
+
errorElement.parentElement.remove();
|
|
56
|
+
}
|
|
46
57
|
item.setAttribute("data-processed", "true");
|
|
47
58
|
});
|
|
48
59
|
});
|
|
@@ -22,7 +22,7 @@ export const plantumlRender = (element: (HTMLElement | Document) = document, cdn
|
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
24
|
try {
|
|
25
|
-
e.innerHTML = `<
|
|
25
|
+
e.innerHTML = `<object type="image/svg+xml" data="http://www.plantuml.com/plantuml/svg/~1${plantumlEncoder.encode(text)}"/>`;
|
|
26
26
|
} catch (error) {
|
|
27
27
|
e.className = "vditor-reset--error";
|
|
28
28
|
e.innerHTML = `plantuml render error: <br>${error}`;
|
package/src/ts/util/function.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
1
|
export const genUUID = () => ([1e7].toString() + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, (c) =>
|
|
2
2
|
(parseInt(c, 10) ^ (window.crypto.getRandomValues(new Uint32Array(1))[0] & (15 >> (parseInt(c, 10) / 4)))).toString(16)
|
|
3
3
|
);
|
|
4
|
+
|
|
5
|
+
export const getSearch = (key: string, link = window.location.search) => {
|
|
6
|
+
const params = link.substring(link.indexOf("?"));
|
|
7
|
+
const hashIndex = params.indexOf("#");
|
|
8
|
+
// REF https://developer.mozilla.org/zh-CN/docs/Web/API/URLSearchParams
|
|
9
|
+
const urlSearchParams = new URLSearchParams(params.substring(0, hashIndex >= 0 ? hashIndex : undefined));
|
|
10
|
+
return urlSearchParams.get(key);
|
|
11
|
+
};
|