md-editor-v3 4.12.0 → 4.12.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/lib/cjs/DropdownToolbar.cjs +3 -1
- package/lib/cjs/MdCatalog.cjs +270 -1
- package/lib/cjs/MdEditor.cjs +3101 -58
- package/lib/cjs/MdModal.cjs +3 -1
- package/lib/cjs/MdPreview.cjs +3 -1
- package/lib/cjs/ModalToolbar.cjs +124 -1
- package/lib/cjs/NormalToolbar.cjs +61 -1
- package/lib/cjs/chunks/config.cjs +290 -1
- package/lib/cjs/chunks/dom.cjs +64 -1
- package/lib/cjs/chunks/index.cjs +1863 -8
- package/lib/cjs/chunks/index2.cjs +198 -1
- package/lib/cjs/chunks/index3.cjs +270 -1
- package/lib/cjs/chunks/index4.cjs +141 -2
- package/lib/cjs/chunks/vue-tsx.cjs +10 -1
- package/lib/cjs/config.cjs +12 -1
- package/lib/cjs/index.cjs +25 -1
- package/lib/es/DropdownToolbar.mjs +2 -2
- package/lib/es/MdCatalog.mjs +164 -114
- package/lib/es/MdEditor.mjs +2292 -1677
- package/lib/es/MdModal.mjs +2 -2
- package/lib/es/MdPreview.mjs +2 -2
- package/lib/es/ModalToolbar.mjs +55 -38
- package/lib/es/NormalToolbar.mjs +26 -18
- package/lib/es/chunks/config.mjs +73 -54
- package/lib/es/chunks/dom.mjs +57 -24
- package/lib/es/chunks/index.mjs +1093 -611
- package/lib/es/chunks/index2.mjs +126 -78
- package/lib/es/chunks/index3.mjs +185 -111
- package/lib/es/chunks/index4.mjs +124 -73
- package/lib/es/chunks/vue-tsx.mjs +8 -8
- package/lib/es/config.mjs +11 -10
- package/lib/es/index.mjs +23 -23
- package/lib/preview.css +200 -1
- package/lib/style.css +592 -1
- package/lib/types/DropdownToolbar/DropdownToolbar.d.ts +1 -1
- package/lib/types/DropdownToolbar/index.d.ts +39 -61
- package/lib/types/MdCatalog/CatalogLink.d.ts +1 -1
- package/lib/types/MdCatalog/MdCatalog.d.ts +1 -1
- package/lib/types/MdCatalog/index.d.ts +47 -60
- package/lib/types/MdEditor/Editor.d.ts +1 -1
- package/lib/types/MdEditor/components/Checkbox/index.d.ts +1 -1
- package/lib/types/MdEditor/components/Divider/index.d.ts +1 -1
- package/lib/types/MdEditor/components/Dropdown/index.d.ts +1 -1
- package/lib/types/MdEditor/components/Icon/Icon.d.ts +1 -1
- package/lib/types/MdEditor/components/Icon/index.d.ts +1 -1
- package/lib/types/MdEditor/components/Modal/Modal.d.ts +2 -2
- package/lib/types/MdEditor/components/Modal/index.d.ts +59 -63
- package/lib/types/MdEditor/components/Popper/index.d.ts +1 -1
- package/lib/types/MdEditor/index.d.ts +238 -104
- package/lib/types/MdEditor/layouts/Content/ContentPreview.d.ts +1 -1
- package/lib/types/MdEditor/layouts/Content/index.d.ts +1 -1
- package/lib/types/MdEditor/layouts/Footer/MarkdownTotal.d.ts +1 -1
- package/lib/types/MdEditor/layouts/Footer/ScrollAuto.d.ts +1 -1
- package/lib/types/MdEditor/layouts/Footer/index.d.ts +1 -1
- package/lib/types/MdEditor/layouts/Modals/Clip.d.ts +1 -1
- package/lib/types/MdEditor/layouts/Modals/Link.d.ts +1 -1
- package/lib/types/MdEditor/layouts/Modals/index.d.ts +1 -1
- package/lib/types/MdEditor/layouts/Toolbar/TableShape.d.ts +1 -1
- package/lib/types/MdEditor/layouts/Toolbar/index.d.ts +1 -1
- package/lib/types/MdEditor/utils/vue-tsx.d.ts +1 -1
- package/lib/types/MdPreview/MdPreview.d.ts +1 -1
- package/lib/types/MdPreview/index.d.ts +119 -73
- package/lib/types/ModalToolbar/ModalToolbar.d.ts +1 -1
- package/lib/types/ModalToolbar/index.d.ts +64 -66
- package/lib/types/NormalToolbar/NormalToolbar.d.ts +1 -1
- package/lib/types/NormalToolbar/index.d.ts +30 -58
- package/lib/umd/index.js +42 -42
- package/package.json +4 -4
package/lib/es/chunks/index.mjs
CHANGED
|
@@ -1,314 +1,614 @@
|
|
|
1
|
-
import { inject
|
|
2
|
-
import { e as
|
|
3
|
-
import { a as
|
|
4
|
-
import { a as
|
|
5
|
-
import
|
|
6
|
-
import { debounce
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import { LRUCache
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
I(
|
|
21
|
-
[a, te(e.setting, "preview")],
|
|
1
|
+
import { inject, watch, toRef, onMounted, nextTick, shallowRef, ref, computed, defineComponent, createVNode, Fragment, reactive, provide, onBeforeUnmount } from "vue";
|
|
2
|
+
import { e as configOption, p as prefix, m as mermaidUrl, k as katexUrl, f as codeCss, h as highlightUrl, s as staticTextDefault, a as iconfontSvgUrl, i as iconfontClassUrl, g as prettierUrl, j as cropperUrl, b as allToolbar, d as allFooter } from "./config.mjs";
|
|
3
|
+
import { a as generateCodeRowNumber, b as bus, P as PUSH_CATALOG, C as CATALOG_CHANGED, R as RERENDER, B as BUILD_FINISHED, O as ON_SAVE, E as ERROR_CATCHER, U as UPLOAD_IMAGE, c as CHANGE_CATALOG_VISIBLE, d as PAGE_FULL_SCREEN_CHANGED, F as FULL_SCREEN_CHANGED, e as PREVIEW_CHANGED, H as HTML_PREVIEW_CHANGED, f as CATALOG_VISIBLE_CHANGED, h as REPLACE, i as CHANGE_FULL_SCREEN, j as EVENT_LISTENER, k as getNextId } from "./index4.mjs";
|
|
4
|
+
import { a as appendHandler, u as updateHandler } from "./dom.mjs";
|
|
5
|
+
import mediumZoom from "medium-zoom";
|
|
6
|
+
import { debounce, uuid } from "@vavt/util";
|
|
7
|
+
import copy from "copy-to-clipboard";
|
|
8
|
+
import mdit from "markdown-it";
|
|
9
|
+
import ImageFiguresPlugin from "markdown-it-image-figures";
|
|
10
|
+
import TaskListPlugin from "markdown-it-task-lists";
|
|
11
|
+
import XSSPlugin from "markdown-it-xss";
|
|
12
|
+
import { LRUCache } from "lru-cache";
|
|
13
|
+
const userZoom = (props, html) => {
|
|
14
|
+
const editorId = inject("editorId");
|
|
15
|
+
const { noImgZoomIn } = props;
|
|
16
|
+
let zoomHander = () => {
|
|
17
|
+
};
|
|
18
|
+
watch(
|
|
19
|
+
[html, toRef(props.setting, "preview")],
|
|
22
20
|
() => {
|
|
23
|
-
!
|
|
21
|
+
if (!noImgZoomIn && props.setting.preview) {
|
|
22
|
+
zoomHander();
|
|
23
|
+
}
|
|
24
24
|
},
|
|
25
25
|
{
|
|
26
|
-
immediate:
|
|
26
|
+
immediate: true
|
|
27
27
|
}
|
|
28
28
|
);
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
29
|
+
onMounted(() => {
|
|
30
|
+
zoomHander = debounce(() => {
|
|
31
|
+
const imgs = document.querySelectorAll(`#${editorId}-preview img`);
|
|
32
|
+
if (imgs.length === 0) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
mediumZoom(imgs, {
|
|
36
|
+
background: "#00000073"
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
const StrIcon = (name, customIcon) => {
|
|
42
|
+
if (typeof customIcon[name] === "string") {
|
|
43
|
+
return customIcon[name];
|
|
44
|
+
}
|
|
45
|
+
const defaultStr = `<i class="${prefix}-iconfont ${prefix}-icon-${name}"></i>`;
|
|
46
|
+
switch (configOption.iconfontType) {
|
|
47
|
+
case "svg": {
|
|
48
|
+
return `<svg class="${prefix}-icon" aria-hidden="true"><use xlink:href="#${prefix}-icon-${name}"></use></svg>`;
|
|
49
|
+
}
|
|
50
|
+
default: {
|
|
51
|
+
return defaultStr;
|
|
52
|
+
}
|
|
38
53
|
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
54
|
+
};
|
|
55
|
+
const useCopyCode = (props, html, key) => {
|
|
56
|
+
const editorId = inject("editorId");
|
|
57
|
+
const ult = inject("usedLanguageText");
|
|
58
|
+
const customIcon = inject("customIcon");
|
|
59
|
+
const initCopyEntry = () => {
|
|
60
|
+
document.querySelectorAll(`#${editorId}-preview pre`).forEach((pre) => {
|
|
61
|
+
var _a, _b;
|
|
62
|
+
let clearTimer = -1;
|
|
63
|
+
(_a = pre.querySelector(".copy-button")) == null ? void 0 : _a.remove();
|
|
64
|
+
const copyBtnText = ((_b = ult.value.copyCode) == null ? void 0 : _b.text) || "复制代码";
|
|
65
|
+
const copyButton = document.createElement("span");
|
|
66
|
+
copyButton.setAttribute("class", "copy-button");
|
|
67
|
+
copyButton.dataset.tips = copyBtnText;
|
|
68
|
+
copyButton.innerHTML = StrIcon("copy", customIcon.value);
|
|
69
|
+
copyButton.addEventListener("click", () => {
|
|
70
|
+
var _a2, _b2;
|
|
71
|
+
clearTimeout(clearTimer);
|
|
72
|
+
const codeText = pre.querySelector("code").innerText;
|
|
73
|
+
const success = copy(props.formatCopiedText(codeText));
|
|
74
|
+
const succssTip = ((_a2 = ult.value.copyCode) == null ? void 0 : _a2.successTips) || "已复制!";
|
|
75
|
+
const failTip = ((_b2 = ult.value.copyCode) == null ? void 0 : _b2.failTips) || "已复制!";
|
|
76
|
+
copyButton.dataset.tips = success ? succssTip : failTip;
|
|
77
|
+
clearTimer = window.setTimeout(() => {
|
|
78
|
+
copyButton.dataset.tips = copyBtnText;
|
|
52
79
|
}, 1500);
|
|
53
|
-
})
|
|
80
|
+
});
|
|
81
|
+
pre.appendChild(copyButton);
|
|
54
82
|
});
|
|
55
|
-
}, u = () => {
|
|
56
|
-
j(o);
|
|
57
|
-
}, c = (s) => {
|
|
58
|
-
s && j(o);
|
|
59
83
|
};
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const o = document.createElement("script");
|
|
67
|
-
o.src = t.value.js, o.onload = () => {
|
|
68
|
-
n.value = window.hljs;
|
|
69
|
-
}, o.id = `${h}-hljs`, T(o, "hljs");
|
|
70
|
-
const u = document.createElement("link");
|
|
71
|
-
u.rel = "stylesheet", u.href = t.value.css, u.id = `${h}-hlCss`, T(u);
|
|
84
|
+
const htmlChanged = () => {
|
|
85
|
+
nextTick(initCopyEntry);
|
|
86
|
+
};
|
|
87
|
+
const settingPreviewChanged = (nVal) => {
|
|
88
|
+
if (nVal) {
|
|
89
|
+
nextTick(initCopyEntry);
|
|
72
90
|
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
91
|
+
};
|
|
92
|
+
watch([html, key], htmlChanged);
|
|
93
|
+
watch(() => props.setting.preview, settingPreviewChanged);
|
|
94
|
+
watch(() => props.setting.htmlPreview, settingPreviewChanged);
|
|
95
|
+
watch(() => ult.value, initCopyEntry);
|
|
96
|
+
onMounted(initCopyEntry);
|
|
97
|
+
};
|
|
98
|
+
const useHighlight = (props) => {
|
|
99
|
+
var _a;
|
|
100
|
+
const hljsConf = (_a = configOption.editorExtensions) == null ? void 0 : _a.highlight;
|
|
101
|
+
const hljs = hljsConf == null ? void 0 : hljsConf.instance;
|
|
102
|
+
const highlightUrl2 = inject("highlight");
|
|
103
|
+
const hljsRef = shallowRef(hljs);
|
|
104
|
+
onMounted(() => {
|
|
105
|
+
if (props.noHighlight) {
|
|
106
|
+
return;
|
|
77
107
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
108
|
+
if (!hljsRef.value) {
|
|
109
|
+
const highlightScript = document.createElement("script");
|
|
110
|
+
highlightScript.src = highlightUrl2.value.js;
|
|
111
|
+
highlightScript.onload = () => {
|
|
112
|
+
hljsRef.value = window.hljs;
|
|
113
|
+
};
|
|
114
|
+
highlightScript.id = `${prefix}-hljs`;
|
|
115
|
+
appendHandler(highlightScript, "hljs");
|
|
116
|
+
const highlightLink = document.createElement("link");
|
|
117
|
+
highlightLink.rel = "stylesheet";
|
|
118
|
+
highlightLink.href = highlightUrl2.value.css;
|
|
119
|
+
highlightLink.id = `${prefix}-hlCss`;
|
|
120
|
+
appendHandler(highlightLink);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
watch(
|
|
124
|
+
() => highlightUrl2.value.css,
|
|
125
|
+
(url) => {
|
|
126
|
+
updateHandler(`${prefix}-hlCss`, "href", url);
|
|
127
|
+
}
|
|
128
|
+
);
|
|
129
|
+
return hljsRef;
|
|
130
|
+
};
|
|
131
|
+
const useMermaid = (props) => {
|
|
132
|
+
const theme = inject("theme");
|
|
133
|
+
const { editorExtensions, mermaidConfig } = configOption;
|
|
134
|
+
const mermaidConf = editorExtensions == null ? void 0 : editorExtensions.mermaid;
|
|
135
|
+
const mermaidRef = shallowRef(mermaidConf == null ? void 0 : mermaidConf.instance);
|
|
136
|
+
const reRenderRef = shallowRef(-1);
|
|
137
|
+
const mermaidCache = new LRUCache({
|
|
81
138
|
max: 1e3,
|
|
82
139
|
// 缓存10分钟
|
|
83
140
|
ttl: 6e5
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
141
|
+
});
|
|
142
|
+
const configMermaid = () => {
|
|
143
|
+
const mermaid = mermaidRef.value;
|
|
144
|
+
if (!props.noMermaid && mermaid) {
|
|
145
|
+
mermaid.initialize(
|
|
146
|
+
mermaidConfig({
|
|
147
|
+
startOnLoad: false,
|
|
148
|
+
theme: theme.value === "dark" ? "dark" : "default"
|
|
149
|
+
})
|
|
150
|
+
);
|
|
151
|
+
reRenderRef.value = reRenderRef.value + 1;
|
|
152
|
+
}
|
|
92
153
|
};
|
|
93
|
-
|
|
94
|
-
() =>
|
|
154
|
+
watch(
|
|
155
|
+
() => theme.value,
|
|
95
156
|
() => {
|
|
96
|
-
|
|
157
|
+
mermaidCache.clear();
|
|
158
|
+
configMermaid();
|
|
159
|
+
}
|
|
160
|
+
);
|
|
161
|
+
onMounted(() => {
|
|
162
|
+
if (props.noMermaid) {
|
|
163
|
+
return;
|
|
97
164
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
if (/\.mjs/.test(r))
|
|
165
|
+
if (!(mermaidConf == null ? void 0 : mermaidConf.instance)) {
|
|
166
|
+
const jsSrc = (mermaidConf == null ? void 0 : mermaidConf.js) || mermaidUrl;
|
|
167
|
+
if (/\.mjs/.test(jsSrc)) {
|
|
102
168
|
import(
|
|
103
169
|
/* @vite-ignore */
|
|
104
170
|
/* webpackIgnore: true */
|
|
105
|
-
|
|
106
|
-
).then((
|
|
107
|
-
|
|
171
|
+
jsSrc
|
|
172
|
+
).then((module) => {
|
|
173
|
+
mermaidRef.value = module.default;
|
|
174
|
+
configMermaid();
|
|
108
175
|
});
|
|
109
|
-
else {
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
176
|
+
} else {
|
|
177
|
+
const mermaidScript = document.createElement("script");
|
|
178
|
+
mermaidScript.id = `${prefix}-mermaid`;
|
|
179
|
+
mermaidScript.src = jsSrc;
|
|
180
|
+
mermaidScript.onload = () => {
|
|
181
|
+
mermaidRef.value = window.mermaid;
|
|
182
|
+
configMermaid();
|
|
183
|
+
};
|
|
184
|
+
appendHandler(mermaidScript, "mermaid");
|
|
114
185
|
}
|
|
115
186
|
}
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
187
|
+
});
|
|
188
|
+
const replaceMermaid = () => {
|
|
189
|
+
nextTick(() => {
|
|
190
|
+
if (!props.noMermaid && mermaidRef.value) {
|
|
191
|
+
const mermaidSourceEles = document.querySelectorAll(
|
|
192
|
+
`div.${prefix}-mermaid`
|
|
193
|
+
);
|
|
194
|
+
const svgContainingElement = document.createElement("div");
|
|
195
|
+
svgContainingElement.style.width = document.body.offsetWidth + "px";
|
|
196
|
+
svgContainingElement.style.height = document.body.offsetHeight + "px";
|
|
197
|
+
svgContainingElement.style.position = "fixed";
|
|
198
|
+
svgContainingElement.style.zIndex = "-10000";
|
|
199
|
+
svgContainingElement.style.top = "-10000";
|
|
200
|
+
let count = mermaidSourceEles.length;
|
|
201
|
+
if (count > 0) {
|
|
202
|
+
document.body.appendChild(svgContainingElement);
|
|
203
|
+
}
|
|
204
|
+
mermaidSourceEles.forEach(async (item) => {
|
|
205
|
+
let mermaidHtml = mermaidCache.get(item.innerText);
|
|
206
|
+
if (!mermaidHtml) {
|
|
207
|
+
const idRand = uuid();
|
|
208
|
+
const render = mermaidRef.value.renderAsync || mermaidRef.value.render;
|
|
209
|
+
let svg = "";
|
|
129
210
|
try {
|
|
130
|
-
|
|
131
|
-
} catch {
|
|
211
|
+
svg = await render(idRand, item.innerText, svgContainingElement);
|
|
212
|
+
} catch (error) {
|
|
132
213
|
}
|
|
133
|
-
|
|
134
|
-
typeof
|
|
135
|
-
)
|
|
214
|
+
mermaidHtml = await props.sanitizeMermaid(
|
|
215
|
+
typeof svg === "string" ? svg : svg.svg
|
|
216
|
+
);
|
|
217
|
+
mermaidCache.set(item.innerText, mermaidHtml);
|
|
136
218
|
}
|
|
137
219
|
const p = document.createElement("p");
|
|
138
|
-
p.className = `${
|
|
220
|
+
p.className = `${prefix}-mermaid`;
|
|
221
|
+
p.setAttribute("data-processed", "");
|
|
222
|
+
p.innerHTML = mermaidHtml;
|
|
223
|
+
if (item.dataset.line !== void 0) {
|
|
224
|
+
p.dataset.line = item.dataset.line;
|
|
225
|
+
}
|
|
226
|
+
item.replaceWith(p);
|
|
227
|
+
if (--count === 0) {
|
|
228
|
+
svgContainingElement.remove();
|
|
229
|
+
}
|
|
139
230
|
});
|
|
140
231
|
}
|
|
141
232
|
});
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
const
|
|
153
|
-
|
|
233
|
+
};
|
|
234
|
+
return { mermaidRef, reRenderRef, replaceMermaid };
|
|
235
|
+
};
|
|
236
|
+
const useKatex = (props) => {
|
|
237
|
+
var _a;
|
|
238
|
+
const katexConf = (_a = configOption.editorExtensions) == null ? void 0 : _a.katex;
|
|
239
|
+
const katexIns = katexConf == null ? void 0 : katexConf.instance;
|
|
240
|
+
const katex = shallowRef(katexIns);
|
|
241
|
+
onMounted(() => {
|
|
242
|
+
if (!props.noKatex && !katex.value) {
|
|
243
|
+
const katexScript = document.createElement("script");
|
|
244
|
+
katexScript.src = (katexConf == null ? void 0 : katexConf.js) || katexUrl.js;
|
|
245
|
+
katexScript.onload = () => {
|
|
246
|
+
katex.value = window.katex;
|
|
247
|
+
};
|
|
248
|
+
katexScript.id = `${prefix}-katex`;
|
|
249
|
+
const katexLink = document.createElement("link");
|
|
250
|
+
katexLink.rel = "stylesheet";
|
|
251
|
+
katexLink.href = (katexConf == null ? void 0 : katexConf.css) || katexUrl.css;
|
|
252
|
+
katexLink.id = `${prefix}-katexCss`;
|
|
253
|
+
appendHandler(katexScript, "katex");
|
|
254
|
+
appendHandler(katexLink);
|
|
154
255
|
}
|
|
155
|
-
})
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
256
|
+
});
|
|
257
|
+
return katex;
|
|
258
|
+
};
|
|
259
|
+
const MermaidPlugin = (md, options) => {
|
|
260
|
+
const temp = md.renderer.rules.fence.bind(md.renderer.rules);
|
|
261
|
+
md.renderer.rules.fence = (tokens, idx, ops, env, slf) => {
|
|
262
|
+
const token = tokens[idx];
|
|
263
|
+
const code = token.content.trim();
|
|
264
|
+
if (token.info === "mermaid") {
|
|
265
|
+
let line;
|
|
266
|
+
if (tokens[idx].map && tokens[idx].level === 0) {
|
|
267
|
+
line = tokens[idx].map[0];
|
|
268
|
+
tokens[idx].attrSet("data-line", String(line));
|
|
269
|
+
}
|
|
270
|
+
return `<div class="${prefix}-mermaid" ${line !== void 0 ? "data-line=" + line : ""} data-mermaid-theme=${options.themeRef.value}>${code}</div>`;
|
|
163
271
|
}
|
|
164
|
-
return
|
|
272
|
+
return temp(tokens, idx, ops, env, slf);
|
|
165
273
|
};
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
274
|
+
};
|
|
275
|
+
const MermaidPlugin$1 = MermaidPlugin;
|
|
276
|
+
const isValidDelim = (state, pos) => {
|
|
277
|
+
let can_open = true, can_close = true;
|
|
278
|
+
const max = state.posMax;
|
|
279
|
+
const prevChar = pos > 0 ? state.src.charCodeAt(pos - 1) : -1;
|
|
280
|
+
const nextChar = pos + 1 <= max ? state.src.charCodeAt(pos + 1) : -1;
|
|
281
|
+
if (prevChar === 32 || prevChar === 9 || nextChar >= 48 && nextChar <= 57) {
|
|
282
|
+
can_close = false;
|
|
283
|
+
}
|
|
284
|
+
if (nextChar === 32 || nextChar === 9) {
|
|
285
|
+
can_open = false;
|
|
286
|
+
}
|
|
287
|
+
return {
|
|
288
|
+
can_open,
|
|
289
|
+
can_close
|
|
172
290
|
};
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
291
|
+
};
|
|
292
|
+
const math_inline = (state, silent) => {
|
|
293
|
+
let match, token, res, pos;
|
|
294
|
+
if (state.src[state.pos] !== "$") {
|
|
295
|
+
return false;
|
|
296
|
+
}
|
|
297
|
+
res = isValidDelim(state, state.pos);
|
|
298
|
+
if (!res.can_open) {
|
|
299
|
+
if (!silent) {
|
|
300
|
+
state.pending += "$";
|
|
301
|
+
}
|
|
302
|
+
state.pos += 1;
|
|
303
|
+
return true;
|
|
304
|
+
}
|
|
305
|
+
const start = state.pos + 1;
|
|
306
|
+
match = start;
|
|
307
|
+
while ((match = state.src.indexOf("$", match)) !== -1) {
|
|
308
|
+
pos = match - 1;
|
|
309
|
+
while (state.src[pos] === "\\") {
|
|
310
|
+
pos -= 1;
|
|
311
|
+
}
|
|
312
|
+
if ((match - pos) % 2 == 1) {
|
|
313
|
+
break;
|
|
314
|
+
}
|
|
315
|
+
match += 1;
|
|
316
|
+
}
|
|
317
|
+
if (match === -1) {
|
|
318
|
+
if (!silent) {
|
|
319
|
+
state.pending += "$";
|
|
320
|
+
}
|
|
321
|
+
state.pos = start;
|
|
322
|
+
return true;
|
|
323
|
+
}
|
|
324
|
+
if (match - start === 0) {
|
|
325
|
+
if (!silent) {
|
|
326
|
+
state.pending += "$$";
|
|
327
|
+
}
|
|
328
|
+
state.pos = start + 1;
|
|
329
|
+
return true;
|
|
330
|
+
}
|
|
331
|
+
res = isValidDelim(state, match);
|
|
332
|
+
if (!res.can_close) {
|
|
333
|
+
if (!silent) {
|
|
334
|
+
state.pending += "$";
|
|
335
|
+
}
|
|
336
|
+
state.pos = start;
|
|
337
|
+
return true;
|
|
338
|
+
}
|
|
339
|
+
if (!silent) {
|
|
340
|
+
token = state.push("math_inline", "math", 0);
|
|
341
|
+
token.markup = "$";
|
|
342
|
+
token.content = state.src.slice(start, match);
|
|
343
|
+
}
|
|
344
|
+
state.pos = match + 1;
|
|
345
|
+
return true;
|
|
346
|
+
};
|
|
347
|
+
const math_block = (state, start, end, silent) => {
|
|
348
|
+
let firstLine, lastLine, next, lastPos, found = false, pos = state.bMarks[start] + state.tShift[start], max = state.eMarks[start];
|
|
349
|
+
if (pos + 2 > max) {
|
|
350
|
+
return false;
|
|
351
|
+
}
|
|
352
|
+
if (state.src.slice(pos, pos + 2) !== "$$") {
|
|
353
|
+
return false;
|
|
354
|
+
}
|
|
355
|
+
pos += 2;
|
|
356
|
+
firstLine = state.src.slice(pos, max);
|
|
357
|
+
if (silent) {
|
|
358
|
+
return true;
|
|
359
|
+
}
|
|
360
|
+
if (firstLine.trim().slice(-2) === "$$") {
|
|
361
|
+
firstLine = firstLine.trim().slice(0, -2);
|
|
362
|
+
found = true;
|
|
363
|
+
}
|
|
364
|
+
for (next = start; !found; ) {
|
|
365
|
+
next++;
|
|
366
|
+
if (next >= end) {
|
|
184
367
|
break;
|
|
185
|
-
|
|
368
|
+
}
|
|
369
|
+
pos = state.bMarks[next] + state.tShift[next];
|
|
370
|
+
max = state.eMarks[next];
|
|
371
|
+
if (pos < max && state.tShift[next] < state.blkIndent) {
|
|
372
|
+
break;
|
|
373
|
+
}
|
|
374
|
+
if (state.src.slice(pos, max).trim().slice(-2) === "$$") {
|
|
375
|
+
lastPos = state.src.slice(0, max).lastIndexOf("$$");
|
|
376
|
+
lastLine = state.src.slice(pos, lastPos);
|
|
377
|
+
found = true;
|
|
378
|
+
}
|
|
186
379
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
}, qe = (e, a) => {
|
|
201
|
-
const l = (n) => {
|
|
202
|
-
if (a.katexRef.value) {
|
|
203
|
-
const i = a.katexRef.value.renderToString(n, {
|
|
204
|
-
throwOnError: !1
|
|
380
|
+
state.line = next + 1;
|
|
381
|
+
const token = state.push("math_block", "math", 0);
|
|
382
|
+
token.block = true;
|
|
383
|
+
token.content = (firstLine && firstLine.trim() ? firstLine + "\n" : "") + state.getLines(start + 1, next, state.tShift[start], true) + (lastLine && lastLine.trim() ? lastLine : "");
|
|
384
|
+
token.map = [start, state.line];
|
|
385
|
+
token.markup = "$$";
|
|
386
|
+
return true;
|
|
387
|
+
};
|
|
388
|
+
const KatexPlugin = (md, options) => {
|
|
389
|
+
const katexInline = (str) => {
|
|
390
|
+
if (options.katexRef.value) {
|
|
391
|
+
const html = options.katexRef.value.renderToString(str, {
|
|
392
|
+
throwOnError: false
|
|
205
393
|
});
|
|
206
|
-
return `<span class="${
|
|
207
|
-
} else
|
|
208
|
-
return `<span class="${
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
394
|
+
return `<span class="${prefix}-katex-inline" data-processed>${html}</span>`;
|
|
395
|
+
} else {
|
|
396
|
+
return `<span class="${prefix}-katex-inline">${str}</span>`;
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
const katexBlock = (str, lineNum) => {
|
|
400
|
+
if (options.katexRef.value) {
|
|
401
|
+
const html = options.katexRef.value.renderToString(str, {
|
|
402
|
+
throwOnError: false,
|
|
403
|
+
displayMode: true
|
|
214
404
|
});
|
|
215
|
-
return `<p class="${
|
|
216
|
-
} else
|
|
217
|
-
return `<p class="${
|
|
405
|
+
return `<p class="${prefix}-katex-block" data-line=${lineNum} data-processed>${html}</p>`;
|
|
406
|
+
} else {
|
|
407
|
+
return `<p class="${prefix}-katex-block" data-line=${lineNum}>${str}</p>`;
|
|
408
|
+
}
|
|
218
409
|
};
|
|
219
|
-
|
|
410
|
+
md.inline.ruler.after("escape", "math_inline", math_inline);
|
|
411
|
+
md.block.ruler.after("blockquote", "math_block", math_block, {
|
|
220
412
|
alt: ["paragraph", "reference", "blockquote", "list"]
|
|
221
|
-
})
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
413
|
+
});
|
|
414
|
+
md.renderer.rules.math_inline = (tokens, idx) => {
|
|
415
|
+
return katexInline(tokens[idx].content);
|
|
416
|
+
};
|
|
417
|
+
md.renderer.rules.math_block = (tokens, idx) => {
|
|
418
|
+
return katexBlock(tokens[idx].content, tokens[idx].map[0]) + "\n";
|
|
419
|
+
};
|
|
420
|
+
};
|
|
421
|
+
const KatexPlugin$1 = KatexPlugin;
|
|
422
|
+
const AdmonitionPlugin = (md, options) => {
|
|
423
|
+
options = options || {};
|
|
424
|
+
const markers = 3, markerStr = options.marker || "!", markerChar = markerStr.charCodeAt(0), markerLen = markerStr.length;
|
|
425
|
+
let type = "", title = "";
|
|
426
|
+
const render = (tokens, idx, _options, _env, self) => {
|
|
427
|
+
const token = tokens[idx];
|
|
428
|
+
if (token.type === "admonition_open") {
|
|
429
|
+
tokens[idx].attrPush([
|
|
430
|
+
"class",
|
|
431
|
+
`${prefix}-admonition ${prefix}-admonition-${token.info}`
|
|
432
|
+
]);
|
|
433
|
+
tokens[idx].attrSet("data-line", String(tokens[idx].map[0]));
|
|
434
|
+
} else if (token.type === "admonition_title_open") {
|
|
435
|
+
tokens[idx].attrPush(["class", `${prefix}-admonition-title`]);
|
|
436
|
+
}
|
|
437
|
+
return self.renderToken(tokens, idx, _options);
|
|
438
|
+
};
|
|
439
|
+
const validate = (params) => {
|
|
440
|
+
const array = params.trim().split(" ", 2);
|
|
441
|
+
title = "";
|
|
442
|
+
type = array[0];
|
|
443
|
+
if (array.length > 1) {
|
|
444
|
+
title = params.substring(type.length + 2);
|
|
445
|
+
}
|
|
446
|
+
if (title === "" || !title) {
|
|
447
|
+
title = type;
|
|
448
|
+
}
|
|
236
449
|
};
|
|
237
|
-
|
|
450
|
+
md.block.ruler.before(
|
|
238
451
|
"code",
|
|
239
452
|
"admonition",
|
|
240
|
-
(
|
|
241
|
-
let
|
|
242
|
-
if (
|
|
243
|
-
return
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
const
|
|
251
|
-
if (
|
|
252
|
-
return
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
453
|
+
(state, startLine, endLine, silent) => {
|
|
454
|
+
let pos, nextLine, token, autoClosed = false, start = state.bMarks[startLine] + state.tShift[startLine], max = state.eMarks[startLine];
|
|
455
|
+
if (markerChar !== state.src.charCodeAt(start)) {
|
|
456
|
+
return false;
|
|
457
|
+
}
|
|
458
|
+
for (pos = start + 1; pos <= max; pos++) {
|
|
459
|
+
if (markerStr[(pos - start) % markerLen] !== state.src[pos]) {
|
|
460
|
+
break;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
const markerCount = Math.floor((pos - start) / markerLen);
|
|
464
|
+
if (markerCount !== markers) {
|
|
465
|
+
return false;
|
|
466
|
+
}
|
|
467
|
+
pos -= (pos - start) % markerLen;
|
|
468
|
+
const markup = state.src.slice(start, pos);
|
|
469
|
+
const params = state.src.slice(pos, max);
|
|
470
|
+
validate(params);
|
|
471
|
+
if (silent) {
|
|
472
|
+
return true;
|
|
473
|
+
}
|
|
474
|
+
nextLine = startLine;
|
|
475
|
+
for (; ; ) {
|
|
476
|
+
nextLine++;
|
|
477
|
+
if (nextLine >= endLine) {
|
|
478
|
+
break;
|
|
479
|
+
}
|
|
480
|
+
start = state.bMarks[nextLine] + state.tShift[nextLine];
|
|
481
|
+
max = state.eMarks[nextLine];
|
|
482
|
+
if (start < max && state.sCount[nextLine] < state.blkIndent) {
|
|
483
|
+
break;
|
|
484
|
+
}
|
|
485
|
+
if (markerChar !== state.src.charCodeAt(start)) {
|
|
486
|
+
continue;
|
|
487
|
+
}
|
|
488
|
+
if (state.sCount[nextLine] - state.blkIndent >= 4) {
|
|
489
|
+
continue;
|
|
490
|
+
}
|
|
491
|
+
for (pos = start + 1; pos <= max; pos++) {
|
|
492
|
+
if (markerStr[(pos - start) % markerLen] !== state.src[pos]) {
|
|
259
493
|
break;
|
|
260
494
|
}
|
|
261
495
|
}
|
|
262
|
-
|
|
263
|
-
|
|
496
|
+
if (Math.floor((pos - start) / markerLen) < markerCount) {
|
|
497
|
+
continue;
|
|
498
|
+
}
|
|
499
|
+
pos -= (pos - start) % markerLen;
|
|
500
|
+
pos = state.skipSpaces(pos);
|
|
501
|
+
if (pos < max) {
|
|
502
|
+
continue;
|
|
503
|
+
}
|
|
504
|
+
autoClosed = true;
|
|
505
|
+
break;
|
|
506
|
+
}
|
|
507
|
+
const oldParent = state.parentType;
|
|
508
|
+
const oldLineMax = state.lineMax;
|
|
509
|
+
state.parentType = "root";
|
|
510
|
+
state.lineMax = nextLine;
|
|
511
|
+
token = state.push("admonition_open", "div", 1);
|
|
512
|
+
token.markup = markup;
|
|
513
|
+
token.block = true;
|
|
514
|
+
token.info = type;
|
|
515
|
+
token.map = [startLine, nextLine];
|
|
516
|
+
token = state.push("admonition_title_open", "p", 1);
|
|
517
|
+
token.markup = markup + " " + type;
|
|
518
|
+
token.map = [startLine, nextLine];
|
|
519
|
+
token = state.push("inline", "", 0);
|
|
520
|
+
token.content = title;
|
|
521
|
+
token.map = [startLine, state.line - 1];
|
|
522
|
+
token.children = [];
|
|
523
|
+
token = state.push("admonition_title_close", "p", -1);
|
|
524
|
+
token.markup = markup + " " + type;
|
|
525
|
+
state.md.block.tokenize(state, startLine + 1, nextLine);
|
|
526
|
+
token = state.push("admonition_close", "div", -1);
|
|
527
|
+
token.markup = state.src.slice(start, pos);
|
|
528
|
+
token.block = true;
|
|
529
|
+
state.parentType = oldParent;
|
|
530
|
+
state.lineMax = oldLineMax;
|
|
531
|
+
state.line = nextLine + (autoClosed ? 1 : 0);
|
|
532
|
+
return true;
|
|
264
533
|
},
|
|
265
534
|
{
|
|
266
535
|
alt: ["paragraph", "reference", "blockquote", "list"]
|
|
267
536
|
}
|
|
268
|
-
)
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
)
|
|
280
|
-
|
|
281
|
-
},
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
537
|
+
);
|
|
538
|
+
md.renderer.rules["admonition_open"] = render;
|
|
539
|
+
md.renderer.rules["admonition_title_open"] = render;
|
|
540
|
+
md.renderer.rules["admonition_title_close"] = render;
|
|
541
|
+
md.renderer.rules["admonition_close"] = render;
|
|
542
|
+
};
|
|
543
|
+
const AdmonitionPlugin$1 = AdmonitionPlugin;
|
|
544
|
+
const HeadingPlugin = (md, options) => {
|
|
545
|
+
md.renderer.rules.heading_open = (tokens, idx) => {
|
|
546
|
+
var _a;
|
|
547
|
+
const token = tokens[idx];
|
|
548
|
+
const text = ((_a = tokens[idx + 1].children) == null ? void 0 : _a.reduce((p, c) => {
|
|
549
|
+
return p + (c.content || "");
|
|
550
|
+
}, "")) || "";
|
|
551
|
+
const level = token.markup.length;
|
|
552
|
+
options.headsRef.value.push({
|
|
553
|
+
text,
|
|
554
|
+
level
|
|
555
|
+
});
|
|
556
|
+
if (token.map && token.level === 0) {
|
|
557
|
+
token.attrSet("data-line", String(token.map[0]));
|
|
558
|
+
token.attrSet(
|
|
559
|
+
"id",
|
|
560
|
+
options.mdHeadingId(text, level, options.headsRef.value.length)
|
|
561
|
+
);
|
|
562
|
+
}
|
|
563
|
+
return md.renderer.renderToken(tokens, idx, options);
|
|
564
|
+
};
|
|
565
|
+
md.renderer.rules.heading_close = (tokens, idx, opts, _env, self) => {
|
|
566
|
+
return self.renderToken(tokens, idx, opts);
|
|
567
|
+
};
|
|
568
|
+
};
|
|
569
|
+
const HeadingPlugin$1 = HeadingPlugin;
|
|
570
|
+
const codetabs = (md, _opts) => {
|
|
571
|
+
const defaultRender = md.renderer.rules.fence, unescapeAll = md.utils.unescapeAll, re = /\[(\w*)(?::([\w ]*))?\]/;
|
|
572
|
+
function getInfo(token) {
|
|
573
|
+
return token.info ? unescapeAll(token.info).trim() : "";
|
|
285
574
|
}
|
|
286
|
-
function
|
|
287
|
-
const
|
|
288
|
-
return [
|
|
575
|
+
function getGroupAndTab(token) {
|
|
576
|
+
const info = getInfo(token), [group = null, tab = ""] = (re.exec(info) || []).slice(1);
|
|
577
|
+
return [group, tab];
|
|
289
578
|
}
|
|
290
|
-
function
|
|
291
|
-
const
|
|
292
|
-
return
|
|
579
|
+
function getLangName(token) {
|
|
580
|
+
const info = getInfo(token);
|
|
581
|
+
return info ? info.split(/(\s+)/g)[0] : "";
|
|
293
582
|
}
|
|
294
|
-
const
|
|
295
|
-
if (
|
|
583
|
+
const fenceGroup = (tokens, idx, options, env, slf) => {
|
|
584
|
+
if (tokens[idx].hidden) {
|
|
296
585
|
return "";
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
586
|
+
}
|
|
587
|
+
const [GROUP, _] = getGroupAndTab(tokens[idx]);
|
|
588
|
+
if (GROUP === null) {
|
|
589
|
+
return defaultRender(tokens, idx, options, env, slf);
|
|
590
|
+
}
|
|
591
|
+
let token, group, tab, checked, labels = "", pres = "";
|
|
592
|
+
for (let i = idx; i < tokens.length; i++) {
|
|
593
|
+
token = tokens[i];
|
|
594
|
+
[group, tab] = getGroupAndTab(token);
|
|
595
|
+
if (group !== GROUP) {
|
|
596
|
+
break;
|
|
597
|
+
}
|
|
598
|
+
token.info = token.info.replace(re, "");
|
|
599
|
+
token.hidden = true;
|
|
600
|
+
checked = i - idx > 0 ? "" : " checked";
|
|
601
|
+
labels += `<li><input type="radio" name="label-group-${_opts.editorId}-${idx}"${checked}><label for="group-${_opts.editorId}-${idx}-tab-${i - idx}" onclick="this.previousElementSibling.click()">${tab || getLangName(token)}</label></li>
|
|
602
|
+
`;
|
|
603
|
+
pres += `<input type="radio" id="group-${_opts.editorId}-${idx}-tab-${i - idx}" name="group-${_opts.editorId}-${idx}"${checked}>
|
|
604
|
+
` + defaultRender(tokens, i, options, env, slf);
|
|
605
|
+
}
|
|
606
|
+
return '<div class="code-tabs">\n<ul>\n' + labels + "</ul>\n" + pres + "</div>";
|
|
309
607
|
};
|
|
310
|
-
|
|
311
|
-
}
|
|
608
|
+
md.renderer.rules.fence = fenceGroup;
|
|
609
|
+
};
|
|
610
|
+
const CodeTabsPlugin = codetabs;
|
|
611
|
+
const initLineNumber = (md) => {
|
|
312
612
|
[
|
|
313
613
|
"paragraph_open",
|
|
314
614
|
"table_open",
|
|
@@ -318,64 +618,85 @@ const Le = (e, a) => {
|
|
|
318
618
|
"hr",
|
|
319
619
|
"html_block",
|
|
320
620
|
"fence"
|
|
321
|
-
].forEach((
|
|
322
|
-
const
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
621
|
+
].forEach((rule) => {
|
|
622
|
+
const backup = md.renderer.rules[rule];
|
|
623
|
+
if (!backup) {
|
|
624
|
+
md.renderer.rules[rule] = (tokens, idx, options, _env, self) => {
|
|
625
|
+
let line;
|
|
626
|
+
if (tokens[idx].map && tokens[idx].level === 0) {
|
|
627
|
+
line = tokens[idx].map[0];
|
|
628
|
+
tokens[idx].attrSet("data-line", String(line));
|
|
629
|
+
}
|
|
630
|
+
return self.renderToken(tokens, idx, options);
|
|
631
|
+
};
|
|
632
|
+
} else {
|
|
633
|
+
md.renderer.rules[rule] = (tokens, idx, options, env, self) => {
|
|
634
|
+
let line;
|
|
635
|
+
const _htmlCode = backup(tokens, idx, options, env, self);
|
|
636
|
+
if (tokens[idx].map && tokens[idx].level === 0 && !/^<!--/.test(_htmlCode)) {
|
|
637
|
+
line = tokens[idx].map[0];
|
|
638
|
+
return _htmlCode.replace(/^(<[^>]*)/, `$1 data-line="${line}"`);
|
|
639
|
+
}
|
|
640
|
+
return _htmlCode;
|
|
641
|
+
};
|
|
642
|
+
}
|
|
331
643
|
});
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
644
|
+
};
|
|
645
|
+
const useMarkdownIt = (props, previewOnly) => {
|
|
646
|
+
const { editorConfig, markdownItConfig, markdownItPlugins } = configOption;
|
|
647
|
+
const editorId = inject("editorId");
|
|
648
|
+
const showCodeRowNumber = inject("showCodeRowNumber");
|
|
649
|
+
const themeRef = inject("theme");
|
|
650
|
+
const headsRef = ref([]);
|
|
651
|
+
const hljsRef = useHighlight(props);
|
|
652
|
+
const katexRef = useKatex(props);
|
|
653
|
+
const { reRenderRef, replaceMermaid } = useMermaid(props);
|
|
654
|
+
const md = mdit({
|
|
655
|
+
html: true,
|
|
656
|
+
breaks: true
|
|
336
657
|
});
|
|
337
|
-
|
|
338
|
-
editorId
|
|
658
|
+
markdownItConfig(md, {
|
|
659
|
+
editorId
|
|
339
660
|
});
|
|
340
|
-
const
|
|
661
|
+
const plugins = [
|
|
341
662
|
{
|
|
342
663
|
type: "katex",
|
|
343
|
-
plugin:
|
|
344
|
-
options: { katexRef
|
|
664
|
+
plugin: KatexPlugin$1,
|
|
665
|
+
options: { katexRef }
|
|
345
666
|
},
|
|
346
667
|
{
|
|
347
668
|
type: "image",
|
|
348
|
-
plugin:
|
|
349
|
-
options: { figcaption:
|
|
669
|
+
plugin: ImageFiguresPlugin,
|
|
670
|
+
options: { figcaption: true, classes: "md-zoom" }
|
|
350
671
|
},
|
|
351
672
|
{
|
|
352
673
|
type: "admonition",
|
|
353
|
-
plugin:
|
|
674
|
+
plugin: AdmonitionPlugin$1,
|
|
354
675
|
options: {}
|
|
355
676
|
},
|
|
356
677
|
{
|
|
357
678
|
type: "taskList",
|
|
358
|
-
plugin:
|
|
679
|
+
plugin: TaskListPlugin,
|
|
359
680
|
options: {}
|
|
360
681
|
},
|
|
361
682
|
{
|
|
362
683
|
type: "heading",
|
|
363
|
-
plugin:
|
|
364
|
-
options: { mdHeadingId:
|
|
684
|
+
plugin: HeadingPlugin$1,
|
|
685
|
+
options: { mdHeadingId: props.mdHeadingId, headsRef }
|
|
365
686
|
},
|
|
366
687
|
{
|
|
367
688
|
type: "codeTabs",
|
|
368
|
-
plugin:
|
|
369
|
-
options: { editorId
|
|
689
|
+
plugin: CodeTabsPlugin,
|
|
690
|
+
options: { editorId }
|
|
370
691
|
},
|
|
371
692
|
{
|
|
372
693
|
type: "xss",
|
|
373
|
-
plugin:
|
|
694
|
+
plugin: XSSPlugin,
|
|
374
695
|
options: {
|
|
375
696
|
// https://github.com/leizongmin/js-xss/blob/master/README.zh.md
|
|
376
|
-
xss(
|
|
697
|
+
xss(xss) {
|
|
377
698
|
return {
|
|
378
|
-
whiteList: Object.assign({},
|
|
699
|
+
whiteList: Object.assign({}, xss.getDefaultWhiteList(), {
|
|
379
700
|
// 支持任务列表
|
|
380
701
|
input: ["class", "disabled", "type", "checked"],
|
|
381
702
|
// 主要支持youtobe、腾讯视频、哔哩哔哩等内嵌视频代码
|
|
@@ -397,66 +718,97 @@ const Le = (e, a) => {
|
|
|
397
718
|
}
|
|
398
719
|
}
|
|
399
720
|
];
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
}
|
|
407
|
-
|
|
721
|
+
if (!props.noMermaid) {
|
|
722
|
+
plugins.push({
|
|
723
|
+
type: "mermaid",
|
|
724
|
+
plugin: MermaidPlugin$1,
|
|
725
|
+
options: { themeRef }
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
markdownItPlugins(plugins, {
|
|
729
|
+
editorId
|
|
730
|
+
}).forEach((item) => {
|
|
731
|
+
md.use(item.plugin, item.options);
|
|
408
732
|
});
|
|
409
|
-
const
|
|
410
|
-
|
|
411
|
-
highlight: (
|
|
412
|
-
if (
|
|
413
|
-
const
|
|
414
|
-
if (
|
|
415
|
-
return
|
|
733
|
+
const userDefHighlight = md.options.highlight;
|
|
734
|
+
md.set({
|
|
735
|
+
highlight: (str, language, attrs) => {
|
|
736
|
+
if (userDefHighlight) {
|
|
737
|
+
const result = userDefHighlight(str, language, attrs);
|
|
738
|
+
if (result) {
|
|
739
|
+
return result;
|
|
740
|
+
}
|
|
416
741
|
}
|
|
417
|
-
let
|
|
418
|
-
!
|
|
419
|
-
language
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
742
|
+
let codeHtml;
|
|
743
|
+
if (!props.noHighlight && hljsRef.value) {
|
|
744
|
+
const hljsLang = hljsRef.value.getLanguage(language);
|
|
745
|
+
if (hljsLang) {
|
|
746
|
+
codeHtml = hljsRef.value.highlight(str, {
|
|
747
|
+
language,
|
|
748
|
+
ignoreIllegals: true
|
|
749
|
+
}).value;
|
|
750
|
+
} else {
|
|
751
|
+
codeHtml = hljsRef.value.highlightAuto(str).value;
|
|
752
|
+
}
|
|
753
|
+
} else {
|
|
754
|
+
codeHtml = md.utils.escapeHtml(str);
|
|
755
|
+
}
|
|
756
|
+
const codeSpan = showCodeRowNumber ? generateCodeRowNumber(codeHtml.replace(/^\n+|\n+$/g, "")) : `<span class="code-block">${codeHtml.replace(/^\n+|\n+$/g, "")}</span>`;
|
|
757
|
+
return `<pre><code class="language-${language}" language=${language}>${codeSpan}</code></pre>`;
|
|
424
758
|
}
|
|
425
|
-
})
|
|
426
|
-
|
|
427
|
-
|
|
759
|
+
});
|
|
760
|
+
initLineNumber(md);
|
|
761
|
+
const key = ref(`_article-key_${uuid()}`);
|
|
762
|
+
const html = ref(props.sanitize(md.render(props.modelValue)));
|
|
763
|
+
const updatedTodo = () => {
|
|
764
|
+
bus.emit(editorId, BUILD_FINISHED, html.value);
|
|
765
|
+
props.onHtmlChanged(html.value);
|
|
766
|
+
props.onGetCatalog(headsRef.value);
|
|
767
|
+
bus.emit(editorId, CATALOG_CHANGED, headsRef.value);
|
|
768
|
+
replaceMermaid();
|
|
428
769
|
};
|
|
429
|
-
|
|
430
|
-
const
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
770
|
+
onMounted(updatedTodo);
|
|
771
|
+
const markHtml = () => {
|
|
772
|
+
headsRef.value = [];
|
|
773
|
+
html.value = props.sanitize(md.render(props.modelValue));
|
|
774
|
+
updatedTodo();
|
|
775
|
+
};
|
|
776
|
+
const needReRender = computed(() => {
|
|
777
|
+
return (props.noKatex || katexRef.value) && (props.noHighlight || hljsRef.value);
|
|
778
|
+
});
|
|
779
|
+
watch(
|
|
780
|
+
[toRef(props, "modelValue"), needReRender, reRenderRef],
|
|
781
|
+
debounce(
|
|
782
|
+
markHtml,
|
|
783
|
+
(editorConfig == null ? void 0 : editorConfig.renderDelay) !== void 0 ? editorConfig == null ? void 0 : editorConfig.renderDelay : previewOnly ? 0 : 500
|
|
438
784
|
)
|
|
439
|
-
)
|
|
440
|
-
|
|
441
|
-
|
|
785
|
+
);
|
|
786
|
+
onMounted(() => {
|
|
787
|
+
bus.on(editorId, {
|
|
788
|
+
name: PUSH_CATALOG,
|
|
442
789
|
callback() {
|
|
443
|
-
|
|
790
|
+
bus.emit(editorId, CATALOG_CHANGED, headsRef.value);
|
|
444
791
|
}
|
|
445
|
-
})
|
|
446
|
-
|
|
792
|
+
});
|
|
793
|
+
bus.on(editorId, {
|
|
794
|
+
name: RERENDER,
|
|
447
795
|
callback: () => {
|
|
448
|
-
|
|
796
|
+
markHtml();
|
|
797
|
+
key.value = `_article-key_${uuid()}`;
|
|
449
798
|
}
|
|
450
799
|
});
|
|
451
|
-
})
|
|
452
|
-
|
|
800
|
+
});
|
|
801
|
+
return { html, key };
|
|
802
|
+
};
|
|
803
|
+
const useMarkdownIt$1 = useMarkdownIt;
|
|
804
|
+
const contentPreviewProps = {
|
|
453
805
|
modelValue: {
|
|
454
806
|
type: String,
|
|
455
807
|
default: ""
|
|
456
808
|
},
|
|
457
809
|
setting: {
|
|
458
810
|
type: Object,
|
|
459
|
-
default: () => ({ preview:
|
|
811
|
+
default: () => ({ preview: true })
|
|
460
812
|
},
|
|
461
813
|
onHtmlChanged: {
|
|
462
814
|
type: Function,
|
|
@@ -474,28 +826,28 @@ const Le = (e, a) => {
|
|
|
474
826
|
},
|
|
475
827
|
noMermaid: {
|
|
476
828
|
type: Boolean,
|
|
477
|
-
default:
|
|
829
|
+
default: false
|
|
478
830
|
},
|
|
479
831
|
sanitize: {
|
|
480
832
|
type: Function,
|
|
481
|
-
default: (
|
|
833
|
+
default: (html) => html
|
|
482
834
|
},
|
|
483
835
|
// 不使用该函数功能
|
|
484
836
|
noKatex: {
|
|
485
837
|
type: Boolean,
|
|
486
|
-
default:
|
|
838
|
+
default: false
|
|
487
839
|
},
|
|
488
840
|
formatCopiedText: {
|
|
489
841
|
type: Function,
|
|
490
|
-
default: (
|
|
842
|
+
default: (text) => text
|
|
491
843
|
},
|
|
492
844
|
noHighlight: {
|
|
493
845
|
type: Boolean,
|
|
494
|
-
default:
|
|
846
|
+
default: false
|
|
495
847
|
},
|
|
496
848
|
previewOnly: {
|
|
497
849
|
type: Boolean,
|
|
498
|
-
default:
|
|
850
|
+
default: false
|
|
499
851
|
},
|
|
500
852
|
noImgZoomIn: {
|
|
501
853
|
type: Boolean
|
|
@@ -503,8 +855,9 @@ const Le = (e, a) => {
|
|
|
503
855
|
sanitizeMermaid: {
|
|
504
856
|
type: Function
|
|
505
857
|
}
|
|
506
|
-
}
|
|
507
|
-
|
|
858
|
+
};
|
|
859
|
+
const contentProps = {
|
|
860
|
+
...contentPreviewProps,
|
|
508
861
|
updateModelValue: {
|
|
509
862
|
type: Function,
|
|
510
863
|
default: () => {
|
|
@@ -580,296 +933,402 @@ const Le = (e, a) => {
|
|
|
580
933
|
onInputBoxWitdhChange: {
|
|
581
934
|
type: Function
|
|
582
935
|
}
|
|
583
|
-
}
|
|
936
|
+
};
|
|
937
|
+
const ContentPreview = /* @__PURE__ */ defineComponent({
|
|
584
938
|
name: "ContentPreview",
|
|
585
|
-
props:
|
|
586
|
-
setup(
|
|
587
|
-
const
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
939
|
+
props: contentPreviewProps,
|
|
940
|
+
setup(props) {
|
|
941
|
+
const editorId = inject("editorId");
|
|
942
|
+
const previewTheme = inject("previewTheme");
|
|
943
|
+
const showCodeRowNumber = inject("showCodeRowNumber");
|
|
944
|
+
const {
|
|
945
|
+
html,
|
|
946
|
+
key
|
|
947
|
+
} = useMarkdownIt$1(props, props.previewOnly);
|
|
948
|
+
useCopyCode(props, html, key);
|
|
949
|
+
userZoom(props, html);
|
|
950
|
+
return () => {
|
|
951
|
+
return createVNode(Fragment, null, [props.setting.preview && createVNode("div", {
|
|
952
|
+
"id": `${editorId}-preview-wrapper`,
|
|
953
|
+
"class": `${prefix}-preview-wrapper`,
|
|
954
|
+
"key": "content-preview-wrapper"
|
|
955
|
+
}, [createVNode("div", {
|
|
956
|
+
"key": key.value,
|
|
957
|
+
"id": `${editorId}-preview`,
|
|
958
|
+
"class": [`${prefix}-preview`, `${previewTheme == null ? void 0 : previewTheme.value}-theme`, showCodeRowNumber && `${prefix}-scrn`],
|
|
959
|
+
"innerHTML": html.value
|
|
960
|
+
}, null)]), !props.previewOnly && props.setting.htmlPreview && createVNode("div", {
|
|
961
|
+
"id": `${editorId}-html-wrapper`,
|
|
962
|
+
"class": `${prefix}-preview-wrapper`,
|
|
963
|
+
"key": "html-preview-wrapper"
|
|
964
|
+
}, [createVNode("div", {
|
|
965
|
+
"class": `${prefix}-html`
|
|
966
|
+
}, [html.value])])]);
|
|
967
|
+
};
|
|
607
968
|
}
|
|
608
|
-
})
|
|
609
|
-
|
|
969
|
+
});
|
|
970
|
+
const useOnSave = (props, context) => {
|
|
971
|
+
const { editorId } = props;
|
|
972
|
+
const state = reactive({
|
|
610
973
|
// 是否已编译成html
|
|
611
|
-
buildFinished:
|
|
974
|
+
buildFinished: false,
|
|
612
975
|
// 存储当前最新的html
|
|
613
976
|
html: ""
|
|
614
977
|
});
|
|
615
|
-
|
|
616
|
-
() =>
|
|
978
|
+
watch(
|
|
979
|
+
() => props.modelValue,
|
|
617
980
|
() => {
|
|
618
|
-
|
|
981
|
+
state.buildFinished = false;
|
|
619
982
|
}
|
|
620
|
-
)
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
983
|
+
);
|
|
984
|
+
onMounted(() => {
|
|
985
|
+
bus.on(editorId, {
|
|
986
|
+
name: BUILD_FINISHED,
|
|
987
|
+
callback(html) {
|
|
988
|
+
state.buildFinished = true;
|
|
989
|
+
state.html = html;
|
|
625
990
|
}
|
|
626
|
-
})
|
|
627
|
-
|
|
991
|
+
});
|
|
992
|
+
bus.on(editorId, {
|
|
993
|
+
name: ON_SAVE,
|
|
628
994
|
callback() {
|
|
629
|
-
const
|
|
630
|
-
if (
|
|
631
|
-
|
|
632
|
-
else {
|
|
633
|
-
const
|
|
634
|
-
|
|
995
|
+
const htmlPromise = new Promise((rev) => {
|
|
996
|
+
if (state.buildFinished) {
|
|
997
|
+
rev(state.html);
|
|
998
|
+
} else {
|
|
999
|
+
const buildFinishedCallback = (html) => {
|
|
1000
|
+
rev(html);
|
|
1001
|
+
bus.remove(editorId, BUILD_FINISHED, buildFinishedCallback);
|
|
635
1002
|
};
|
|
636
|
-
|
|
637
|
-
name:
|
|
638
|
-
callback:
|
|
1003
|
+
bus.on(editorId, {
|
|
1004
|
+
name: BUILD_FINISHED,
|
|
1005
|
+
callback: buildFinishedCallback
|
|
639
1006
|
});
|
|
640
1007
|
}
|
|
641
1008
|
});
|
|
642
|
-
|
|
1009
|
+
if (props.onSave) {
|
|
1010
|
+
props.onSave(props.modelValue, htmlPromise);
|
|
1011
|
+
} else {
|
|
1012
|
+
context.emit("onSave", props.modelValue, htmlPromise);
|
|
1013
|
+
}
|
|
643
1014
|
}
|
|
644
1015
|
});
|
|
645
1016
|
});
|
|
646
|
-
}
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
1017
|
+
};
|
|
1018
|
+
const useProvidePreview = (props) => {
|
|
1019
|
+
var _a, _b;
|
|
1020
|
+
const { editorId } = props;
|
|
1021
|
+
const highlightConfig = (_b = (_a = configOption) == null ? void 0 : _a.editorExtensions) == null ? void 0 : _b.highlight;
|
|
1022
|
+
provide("editorId", editorId);
|
|
1023
|
+
provide(
|
|
650
1024
|
"theme",
|
|
651
|
-
|
|
652
|
-
)
|
|
1025
|
+
computed(() => props.theme)
|
|
1026
|
+
);
|
|
1027
|
+
provide(
|
|
653
1028
|
"language",
|
|
654
|
-
|
|
655
|
-
)
|
|
1029
|
+
computed(() => props.language)
|
|
1030
|
+
);
|
|
1031
|
+
provide(
|
|
656
1032
|
"highlight",
|
|
657
|
-
|
|
658
|
-
const
|
|
659
|
-
...
|
|
660
|
-
...
|
|
661
|
-
}
|
|
1033
|
+
computed(() => {
|
|
1034
|
+
const cssList = {
|
|
1035
|
+
...codeCss,
|
|
1036
|
+
...highlightConfig == null ? void 0 : highlightConfig.css
|
|
1037
|
+
};
|
|
1038
|
+
const theme = props.codeStyleReverse && props.codeStyleReverseList.includes(props.previewTheme) ? "dark" : props.theme;
|
|
662
1039
|
return {
|
|
663
|
-
js: (
|
|
664
|
-
css:
|
|
1040
|
+
js: (highlightConfig == null ? void 0 : highlightConfig.js) || highlightUrl,
|
|
1041
|
+
css: cssList[props.codeTheme] ? cssList[props.codeTheme][theme] : codeCss.atom[theme]
|
|
665
1042
|
};
|
|
666
1043
|
})
|
|
667
|
-
)
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
...
|
|
1044
|
+
);
|
|
1045
|
+
provide("showCodeRowNumber", props.showCodeRowNumber);
|
|
1046
|
+
const usedLanguageText = computed(() => {
|
|
1047
|
+
var _a2, _b2;
|
|
1048
|
+
const allText = {
|
|
1049
|
+
...staticTextDefault,
|
|
1050
|
+
...(_b2 = (_a2 = configOption) == null ? void 0 : _a2.editorConfig) == null ? void 0 : _b2.languageUserDefined
|
|
673
1051
|
};
|
|
674
|
-
|
|
1052
|
+
if (allText[props.language]) {
|
|
1053
|
+
return allText[props.language];
|
|
1054
|
+
} else {
|
|
1055
|
+
return staticTextDefault["zh-CN"];
|
|
1056
|
+
}
|
|
675
1057
|
});
|
|
676
|
-
|
|
1058
|
+
provide("usedLanguageText", usedLanguageText);
|
|
1059
|
+
provide(
|
|
677
1060
|
"previewTheme",
|
|
678
|
-
|
|
679
|
-
)
|
|
1061
|
+
computed(() => props.previewTheme)
|
|
1062
|
+
);
|
|
1063
|
+
provide(
|
|
680
1064
|
"customIcon",
|
|
681
|
-
|
|
1065
|
+
computed(() => props.customIcon)
|
|
682
1066
|
);
|
|
683
|
-
}
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
1067
|
+
};
|
|
1068
|
+
const useProvide = (props) => {
|
|
1069
|
+
useProvidePreview(props);
|
|
1070
|
+
provide("tabWidth", props.tabWidth);
|
|
1071
|
+
};
|
|
1072
|
+
const useExpansionPreview = (props) => {
|
|
1073
|
+
onMounted(() => {
|
|
1074
|
+
var _a, _b;
|
|
1075
|
+
if (!props.noIconfont) {
|
|
1076
|
+
if (configOption.iconfontType === "svg") {
|
|
1077
|
+
const iconfontScript = document.createElement("script");
|
|
1078
|
+
iconfontScript.src = ((_a = configOption.editorExtensions) == null ? void 0 : _a.iconfont) || iconfontSvgUrl;
|
|
1079
|
+
iconfontScript.id = `${prefix}-icon`;
|
|
1080
|
+
appendHandler(iconfontScript);
|
|
692
1081
|
} else {
|
|
693
|
-
const
|
|
694
|
-
|
|
1082
|
+
const iconfontLink = document.createElement("link");
|
|
1083
|
+
iconfontLink.rel = "stylesheet";
|
|
1084
|
+
iconfontLink.href = ((_b = configOption.editorExtensions) == null ? void 0 : _b.iconfontClass) || iconfontClassUrl;
|
|
1085
|
+
iconfontLink.id = `${prefix}-icon-class`;
|
|
1086
|
+
appendHandler(iconfontLink);
|
|
695
1087
|
}
|
|
1088
|
+
}
|
|
696
1089
|
});
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
1090
|
+
};
|
|
1091
|
+
const useExpansion = (props) => {
|
|
1092
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1093
|
+
const { noPrettier, noUploadImg } = props;
|
|
1094
|
+
const { editorExtensions } = configOption;
|
|
1095
|
+
const noPrettierScript = noPrettier || !!((_b = (_a = configOption.editorExtensions) == null ? void 0 : _a.prettier) == null ? void 0 : _b.prettierInstance);
|
|
1096
|
+
const noParserMarkdownScript = noPrettier || !!((_d = (_c = configOption.editorExtensions) == null ? void 0 : _c.prettier) == null ? void 0 : _d.parserMarkdownInstance);
|
|
1097
|
+
const noCropperScript = noUploadImg || !!((_f = (_e = configOption.editorExtensions) == null ? void 0 : _e.cropper) == null ? void 0 : _f.instance);
|
|
1098
|
+
onMounted(() => {
|
|
1099
|
+
var _a2, _b2, _c2, _d2;
|
|
1100
|
+
const prettierScript = document.createElement("script");
|
|
1101
|
+
const prettierMDScript = document.createElement("script");
|
|
1102
|
+
prettierScript.src = ((_a2 = editorExtensions == null ? void 0 : editorExtensions.prettier) == null ? void 0 : _a2.standaloneJs) || prettierUrl.main;
|
|
1103
|
+
prettierScript.id = `${prefix}-prettier`;
|
|
1104
|
+
prettierMDScript.src = ((_b2 = editorExtensions == null ? void 0 : editorExtensions.prettier) == null ? void 0 : _b2.parserMarkdownJs) || prettierUrl.markdown;
|
|
1105
|
+
prettierMDScript.id = `${prefix}-prettierMD`;
|
|
1106
|
+
const cropperLink = document.createElement("link");
|
|
1107
|
+
cropperLink.rel = "stylesheet";
|
|
1108
|
+
cropperLink.href = ((_c2 = editorExtensions == null ? void 0 : editorExtensions.cropper) == null ? void 0 : _c2.css) || cropperUrl.css;
|
|
1109
|
+
cropperLink.id = `${prefix}-cropperCss`;
|
|
1110
|
+
const cropperScript = document.createElement("script");
|
|
1111
|
+
cropperScript.src = ((_d2 = editorExtensions == null ? void 0 : editorExtensions.cropper) == null ? void 0 : _d2.js) || cropperUrl.js;
|
|
1112
|
+
cropperScript.id = `${prefix}-cropper`;
|
|
1113
|
+
if (!noCropperScript) {
|
|
1114
|
+
appendHandler(cropperLink);
|
|
1115
|
+
appendHandler(cropperScript);
|
|
1116
|
+
}
|
|
1117
|
+
if (!noPrettierScript) {
|
|
1118
|
+
appendHandler(prettierScript);
|
|
1119
|
+
}
|
|
1120
|
+
if (!noParserMarkdownScript) {
|
|
1121
|
+
appendHandler(prettierMDScript);
|
|
1122
|
+
}
|
|
1123
|
+
});
|
|
1124
|
+
useExpansionPreview(props);
|
|
1125
|
+
};
|
|
1126
|
+
const useErrorCatcher = (props, context) => {
|
|
1127
|
+
const { editorId } = props;
|
|
1128
|
+
onMounted(() => {
|
|
1129
|
+
bus.on(editorId, {
|
|
1130
|
+
name: ERROR_CATCHER,
|
|
1131
|
+
callback: (err) => {
|
|
1132
|
+
if (props.onError instanceof Function) {
|
|
1133
|
+
props.onError(err);
|
|
1134
|
+
} else {
|
|
1135
|
+
context.emit("onError", err);
|
|
1136
|
+
}
|
|
716
1137
|
}
|
|
717
1138
|
});
|
|
718
1139
|
});
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
1140
|
+
};
|
|
1141
|
+
const useConfig = (props, context) => {
|
|
1142
|
+
const { editorId } = props;
|
|
1143
|
+
const setting = reactive({
|
|
1144
|
+
pageFullscreen: props.pageFullscreen,
|
|
1145
|
+
fullscreen: false,
|
|
1146
|
+
preview: props.preview,
|
|
1147
|
+
htmlPreview: props.preview ? false : props.htmlPreview
|
|
1148
|
+
});
|
|
1149
|
+
const updateSetting = (k, v) => {
|
|
1150
|
+
setting[k] = v === void 0 ? !setting[k] : v;
|
|
1151
|
+
if (k === "preview" && setting.preview) {
|
|
1152
|
+
setting.htmlPreview = false;
|
|
1153
|
+
} else if (k === "htmlPreview" && setting.htmlPreview) {
|
|
1154
|
+
setting.preview = false;
|
|
1155
|
+
}
|
|
727
1156
|
};
|
|
728
|
-
let
|
|
729
|
-
const
|
|
730
|
-
|
|
1157
|
+
let bodyOverflowHistory = "";
|
|
1158
|
+
const adjustBody = () => {
|
|
1159
|
+
if (setting.pageFullscreen || setting.fullscreen) {
|
|
1160
|
+
document.body.style.overflow = "hidden";
|
|
1161
|
+
} else {
|
|
1162
|
+
document.body.style.overflow = bodyOverflowHistory;
|
|
1163
|
+
}
|
|
731
1164
|
};
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
1165
|
+
watch(() => [setting.pageFullscreen, setting.fullscreen], adjustBody);
|
|
1166
|
+
onMounted(() => {
|
|
1167
|
+
bus.on(editorId, {
|
|
1168
|
+
name: UPLOAD_IMAGE,
|
|
1169
|
+
callback(files, cb) {
|
|
1170
|
+
const insertHanlder = (urls) => {
|
|
1171
|
+
bus.emit(editorId, REPLACE, "image", {
|
|
738
1172
|
desc: "",
|
|
739
|
-
urls
|
|
740
|
-
})
|
|
1173
|
+
urls
|
|
1174
|
+
});
|
|
1175
|
+
cb && cb();
|
|
741
1176
|
};
|
|
742
|
-
|
|
1177
|
+
if (props.onUploadImg) {
|
|
1178
|
+
props.onUploadImg(files, insertHanlder);
|
|
1179
|
+
} else {
|
|
1180
|
+
context.emit("onUploadImg", files, insertHanlder);
|
|
1181
|
+
}
|
|
743
1182
|
}
|
|
744
|
-
})
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
return
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
1183
|
+
});
|
|
1184
|
+
bodyOverflowHistory = document.body.style.overflow;
|
|
1185
|
+
adjustBody();
|
|
1186
|
+
});
|
|
1187
|
+
return [setting, updateSetting];
|
|
1188
|
+
};
|
|
1189
|
+
const useCatalog = (props) => {
|
|
1190
|
+
const { editorId } = props;
|
|
1191
|
+
const catalogShow = ref(false);
|
|
1192
|
+
onMounted(() => {
|
|
1193
|
+
bus.on(editorId, {
|
|
1194
|
+
name: CHANGE_CATALOG_VISIBLE,
|
|
1195
|
+
callback: (v) => {
|
|
1196
|
+
if (v === void 0) {
|
|
1197
|
+
catalogShow.value = !catalogShow.value;
|
|
1198
|
+
} else {
|
|
1199
|
+
catalogShow.value = v;
|
|
1200
|
+
}
|
|
753
1201
|
}
|
|
754
1202
|
});
|
|
755
|
-
})
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
1203
|
+
});
|
|
1204
|
+
const catalogVisible = computed(() => {
|
|
1205
|
+
return !props.toolbarsExclude.includes("catalog") && props.toolbars.includes("catalog") && catalogShow.value;
|
|
1206
|
+
});
|
|
1207
|
+
return catalogVisible;
|
|
1208
|
+
};
|
|
1209
|
+
const useExpose$1 = (props, ctx, catalogVisible, setting, updateSetting, codeRef) => {
|
|
1210
|
+
const { editorId } = props;
|
|
1211
|
+
watch(
|
|
1212
|
+
() => setting.pageFullscreen,
|
|
1213
|
+
(newVal) => {
|
|
1214
|
+
bus.emit(editorId, PAGE_FULL_SCREEN_CHANGED, newVal);
|
|
762
1215
|
}
|
|
763
|
-
)
|
|
764
|
-
|
|
765
|
-
(
|
|
766
|
-
|
|
1216
|
+
);
|
|
1217
|
+
watch(
|
|
1218
|
+
() => setting.fullscreen,
|
|
1219
|
+
(newVal) => {
|
|
1220
|
+
bus.emit(editorId, FULL_SCREEN_CHANGED, newVal);
|
|
767
1221
|
}
|
|
768
|
-
)
|
|
769
|
-
|
|
770
|
-
(
|
|
771
|
-
|
|
1222
|
+
);
|
|
1223
|
+
watch(
|
|
1224
|
+
() => setting.preview,
|
|
1225
|
+
(newVal) => {
|
|
1226
|
+
bus.emit(editorId, PREVIEW_CHANGED, newVal);
|
|
772
1227
|
}
|
|
773
|
-
)
|
|
774
|
-
|
|
775
|
-
(
|
|
776
|
-
|
|
1228
|
+
);
|
|
1229
|
+
watch(
|
|
1230
|
+
() => setting.htmlPreview,
|
|
1231
|
+
(newVal) => {
|
|
1232
|
+
bus.emit(editorId, HTML_PREVIEW_CHANGED, newVal);
|
|
777
1233
|
}
|
|
778
|
-
)
|
|
779
|
-
|
|
1234
|
+
);
|
|
1235
|
+
watch(catalogVisible, (newVal) => {
|
|
1236
|
+
bus.emit(editorId, CATALOG_VISIBLE_CHANGED, newVal);
|
|
780
1237
|
});
|
|
781
|
-
const
|
|
782
|
-
on(
|
|
783
|
-
switch (
|
|
1238
|
+
const exposeParam = {
|
|
1239
|
+
on(eventName, callBack) {
|
|
1240
|
+
switch (eventName) {
|
|
784
1241
|
case "pageFullscreen": {
|
|
785
|
-
|
|
786
|
-
name:
|
|
787
|
-
callback(
|
|
788
|
-
|
|
1242
|
+
bus.on(editorId, {
|
|
1243
|
+
name: PAGE_FULL_SCREEN_CHANGED,
|
|
1244
|
+
callback(status) {
|
|
1245
|
+
callBack(status);
|
|
789
1246
|
}
|
|
790
1247
|
});
|
|
791
1248
|
break;
|
|
792
1249
|
}
|
|
793
1250
|
case "fullscreen": {
|
|
794
|
-
|
|
795
|
-
name:
|
|
796
|
-
callback(
|
|
797
|
-
|
|
1251
|
+
bus.on(editorId, {
|
|
1252
|
+
name: FULL_SCREEN_CHANGED,
|
|
1253
|
+
callback(status) {
|
|
1254
|
+
callBack(status);
|
|
798
1255
|
}
|
|
799
1256
|
});
|
|
800
1257
|
break;
|
|
801
1258
|
}
|
|
802
1259
|
case "preview": {
|
|
803
|
-
|
|
804
|
-
name:
|
|
805
|
-
callback(
|
|
806
|
-
|
|
1260
|
+
bus.on(editorId, {
|
|
1261
|
+
name: PREVIEW_CHANGED,
|
|
1262
|
+
callback(status) {
|
|
1263
|
+
callBack(status);
|
|
807
1264
|
}
|
|
808
1265
|
});
|
|
809
1266
|
break;
|
|
810
1267
|
}
|
|
811
1268
|
case "htmlPreview": {
|
|
812
|
-
|
|
813
|
-
name:
|
|
814
|
-
callback(
|
|
815
|
-
|
|
1269
|
+
bus.on(editorId, {
|
|
1270
|
+
name: HTML_PREVIEW_CHANGED,
|
|
1271
|
+
callback(status) {
|
|
1272
|
+
callBack(status);
|
|
816
1273
|
}
|
|
817
1274
|
});
|
|
818
1275
|
break;
|
|
819
1276
|
}
|
|
820
1277
|
case "catalog": {
|
|
821
|
-
|
|
822
|
-
name:
|
|
823
|
-
callback(
|
|
824
|
-
|
|
1278
|
+
bus.on(editorId, {
|
|
1279
|
+
name: CATALOG_VISIBLE_CHANGED,
|
|
1280
|
+
callback(status) {
|
|
1281
|
+
callBack(status);
|
|
825
1282
|
}
|
|
826
1283
|
});
|
|
827
1284
|
break;
|
|
828
1285
|
}
|
|
829
1286
|
}
|
|
830
1287
|
},
|
|
831
|
-
togglePageFullscreen(
|
|
832
|
-
|
|
1288
|
+
togglePageFullscreen(status) {
|
|
1289
|
+
updateSetting("pageFullscreen", status);
|
|
833
1290
|
},
|
|
834
|
-
toggleFullscreen(
|
|
835
|
-
|
|
1291
|
+
toggleFullscreen(status) {
|
|
1292
|
+
bus.emit(editorId, CHANGE_FULL_SCREEN, status);
|
|
836
1293
|
},
|
|
837
|
-
togglePreview(
|
|
838
|
-
|
|
1294
|
+
togglePreview(status) {
|
|
1295
|
+
updateSetting("preview", status);
|
|
839
1296
|
},
|
|
840
|
-
toggleHtmlPreview(
|
|
841
|
-
|
|
1297
|
+
toggleHtmlPreview(status) {
|
|
1298
|
+
updateSetting("htmlPreview", status);
|
|
842
1299
|
},
|
|
843
|
-
toggleCatalog(
|
|
844
|
-
|
|
1300
|
+
toggleCatalog(status) {
|
|
1301
|
+
bus.emit(editorId, CHANGE_CATALOG_VISIBLE, status);
|
|
845
1302
|
},
|
|
846
1303
|
triggerSave() {
|
|
847
|
-
|
|
1304
|
+
bus.emit(editorId, ON_SAVE);
|
|
848
1305
|
},
|
|
849
|
-
insert(
|
|
850
|
-
|
|
1306
|
+
insert(generate) {
|
|
1307
|
+
bus.emit(editorId, REPLACE, "universal", { generate });
|
|
851
1308
|
},
|
|
852
|
-
focus(
|
|
853
|
-
var
|
|
854
|
-
(
|
|
1309
|
+
focus(options) {
|
|
1310
|
+
var _a;
|
|
1311
|
+
(_a = codeRef.value) == null ? void 0 : _a.focus(options);
|
|
855
1312
|
},
|
|
856
1313
|
rerender() {
|
|
857
|
-
|
|
1314
|
+
bus.emit(editorId, RERENDER);
|
|
858
1315
|
},
|
|
859
1316
|
getSelectedText() {
|
|
860
|
-
var
|
|
861
|
-
return (
|
|
1317
|
+
var _a;
|
|
1318
|
+
return (_a = codeRef.value) == null ? void 0 : _a.getSelectedText();
|
|
862
1319
|
},
|
|
863
1320
|
resetHistory() {
|
|
864
|
-
var
|
|
865
|
-
(
|
|
1321
|
+
var _a;
|
|
1322
|
+
(_a = codeRef.value) == null ? void 0 : _a.resetHistory();
|
|
866
1323
|
},
|
|
867
|
-
domEventHandlers(
|
|
868
|
-
|
|
1324
|
+
domEventHandlers(handlers) {
|
|
1325
|
+
bus.emit(editorId, EVENT_LISTENER, handlers);
|
|
869
1326
|
}
|
|
870
1327
|
};
|
|
871
|
-
|
|
872
|
-
}
|
|
1328
|
+
ctx.expose(exposeParam);
|
|
1329
|
+
};
|
|
1330
|
+
const mdHeadingId = (text) => text;
|
|
1331
|
+
const mdPreviewProps = {
|
|
873
1332
|
/**
|
|
874
1333
|
* markdown content.
|
|
875
1334
|
*
|
|
@@ -925,7 +1384,7 @@ const Le = (e, a) => {
|
|
|
925
1384
|
*/
|
|
926
1385
|
editorId: {
|
|
927
1386
|
type: String,
|
|
928
|
-
default: () =>
|
|
1387
|
+
default: () => getNextId("md-editor-v3_")
|
|
929
1388
|
},
|
|
930
1389
|
/**
|
|
931
1390
|
* 预览中代码是否显示行号
|
|
@@ -934,7 +1393,7 @@ const Le = (e, a) => {
|
|
|
934
1393
|
*/
|
|
935
1394
|
showCodeRowNumber: {
|
|
936
1395
|
type: Boolean,
|
|
937
|
-
default:
|
|
1396
|
+
default: false
|
|
938
1397
|
},
|
|
939
1398
|
/**
|
|
940
1399
|
* 预览内容样式
|
|
@@ -959,7 +1418,7 @@ const Le = (e, a) => {
|
|
|
959
1418
|
*/
|
|
960
1419
|
mdHeadingId: {
|
|
961
1420
|
type: Function,
|
|
962
|
-
default:
|
|
1421
|
+
default: mdHeadingId
|
|
963
1422
|
},
|
|
964
1423
|
/**
|
|
965
1424
|
*
|
|
@@ -970,7 +1429,7 @@ const Le = (e, a) => {
|
|
|
970
1429
|
*/
|
|
971
1430
|
sanitize: {
|
|
972
1431
|
type: Function,
|
|
973
|
-
default: (
|
|
1432
|
+
default: (html) => html
|
|
974
1433
|
},
|
|
975
1434
|
/**
|
|
976
1435
|
* 不使用该mermaid
|
|
@@ -979,7 +1438,7 @@ const Le = (e, a) => {
|
|
|
979
1438
|
*/
|
|
980
1439
|
noMermaid: {
|
|
981
1440
|
type: Boolean,
|
|
982
|
-
default:
|
|
1441
|
+
default: false
|
|
983
1442
|
},
|
|
984
1443
|
/**
|
|
985
1444
|
* 不使用katex
|
|
@@ -988,7 +1447,7 @@ const Le = (e, a) => {
|
|
|
988
1447
|
*/
|
|
989
1448
|
noKatex: {
|
|
990
1449
|
type: Boolean,
|
|
991
|
-
default:
|
|
1450
|
+
default: false
|
|
992
1451
|
},
|
|
993
1452
|
/**
|
|
994
1453
|
* 代码主题
|
|
@@ -1014,7 +1473,7 @@ const Le = (e, a) => {
|
|
|
1014
1473
|
*/
|
|
1015
1474
|
formatCopiedText: {
|
|
1016
1475
|
type: Function,
|
|
1017
|
-
default: (
|
|
1476
|
+
default: (text) => text
|
|
1018
1477
|
},
|
|
1019
1478
|
/**
|
|
1020
1479
|
* 某些预览主题的代码模块背景是暗色系
|
|
@@ -1024,7 +1483,7 @@ const Le = (e, a) => {
|
|
|
1024
1483
|
*/
|
|
1025
1484
|
codeStyleReverse: {
|
|
1026
1485
|
type: Boolean,
|
|
1027
|
-
default:
|
|
1486
|
+
default: true
|
|
1028
1487
|
},
|
|
1029
1488
|
/**
|
|
1030
1489
|
* 需要自动调整的预览主题
|
|
@@ -1037,14 +1496,14 @@ const Le = (e, a) => {
|
|
|
1037
1496
|
},
|
|
1038
1497
|
noHighlight: {
|
|
1039
1498
|
type: Boolean,
|
|
1040
|
-
default:
|
|
1499
|
+
default: false
|
|
1041
1500
|
},
|
|
1042
1501
|
/**
|
|
1043
1502
|
* 是否关闭编辑器默认的放大缩小功能
|
|
1044
1503
|
*/
|
|
1045
1504
|
noImgZoomIn: {
|
|
1046
1505
|
type: Boolean,
|
|
1047
|
-
default:
|
|
1506
|
+
default: false
|
|
1048
1507
|
},
|
|
1049
1508
|
/**
|
|
1050
1509
|
* 自定义的图标
|
|
@@ -1055,10 +1514,11 @@ const Le = (e, a) => {
|
|
|
1055
1514
|
},
|
|
1056
1515
|
sanitizeMermaid: {
|
|
1057
1516
|
type: Function,
|
|
1058
|
-
default: (
|
|
1517
|
+
default: (h) => Promise.resolve(h)
|
|
1059
1518
|
}
|
|
1060
|
-
}
|
|
1061
|
-
|
|
1519
|
+
};
|
|
1520
|
+
const editorProps = {
|
|
1521
|
+
...mdPreviewProps,
|
|
1062
1522
|
/**
|
|
1063
1523
|
* input回调事件
|
|
1064
1524
|
*/
|
|
@@ -1084,7 +1544,7 @@ const Le = (e, a) => {
|
|
|
1084
1544
|
*/
|
|
1085
1545
|
pageFullscreen: {
|
|
1086
1546
|
type: Boolean,
|
|
1087
|
-
default:
|
|
1547
|
+
default: false
|
|
1088
1548
|
},
|
|
1089
1549
|
/**
|
|
1090
1550
|
* 是否展开预览
|
|
@@ -1093,7 +1553,7 @@ const Le = (e, a) => {
|
|
|
1093
1553
|
*/
|
|
1094
1554
|
preview: {
|
|
1095
1555
|
type: Boolean,
|
|
1096
|
-
default:
|
|
1556
|
+
default: true
|
|
1097
1557
|
},
|
|
1098
1558
|
/**
|
|
1099
1559
|
* 是否展开html预览
|
|
@@ -1102,7 +1562,7 @@ const Le = (e, a) => {
|
|
|
1102
1562
|
*/
|
|
1103
1563
|
htmlPreview: {
|
|
1104
1564
|
type: Boolean,
|
|
1105
|
-
default:
|
|
1565
|
+
default: false
|
|
1106
1566
|
},
|
|
1107
1567
|
/**
|
|
1108
1568
|
* 仅预览模式,不显示toolbar和编辑框
|
|
@@ -1122,7 +1582,7 @@ const Le = (e, a) => {
|
|
|
1122
1582
|
*/
|
|
1123
1583
|
toolbars: {
|
|
1124
1584
|
type: Array,
|
|
1125
|
-
default:
|
|
1585
|
+
default: allToolbar
|
|
1126
1586
|
},
|
|
1127
1587
|
/**
|
|
1128
1588
|
* 工具栏选择不显示
|
|
@@ -1140,7 +1600,7 @@ const Le = (e, a) => {
|
|
|
1140
1600
|
*/
|
|
1141
1601
|
noPrettier: {
|
|
1142
1602
|
type: Boolean,
|
|
1143
|
-
default:
|
|
1603
|
+
default: false
|
|
1144
1604
|
},
|
|
1145
1605
|
/**
|
|
1146
1606
|
* 一个tab等于空格数
|
|
@@ -1186,7 +1646,7 @@ const Le = (e, a) => {
|
|
|
1186
1646
|
*/
|
|
1187
1647
|
footers: {
|
|
1188
1648
|
type: Array,
|
|
1189
|
-
default:
|
|
1649
|
+
default: allFooter
|
|
1190
1650
|
},
|
|
1191
1651
|
/**
|
|
1192
1652
|
* 是否默认激活输入框和预览框同步滚动
|
|
@@ -1195,7 +1655,7 @@ const Le = (e, a) => {
|
|
|
1195
1655
|
*/
|
|
1196
1656
|
scrollAuto: {
|
|
1197
1657
|
type: Boolean,
|
|
1198
|
-
default:
|
|
1658
|
+
default: true
|
|
1199
1659
|
},
|
|
1200
1660
|
/**
|
|
1201
1661
|
* 自定义的也叫工具组件列表
|
|
@@ -1282,7 +1742,7 @@ const Le = (e, a) => {
|
|
|
1282
1742
|
*/
|
|
1283
1743
|
showToolbarName: {
|
|
1284
1744
|
type: Boolean,
|
|
1285
|
-
default:
|
|
1745
|
+
default: false
|
|
1286
1746
|
},
|
|
1287
1747
|
/**
|
|
1288
1748
|
* 字符输入事件
|
|
@@ -1309,8 +1769,10 @@ const Le = (e, a) => {
|
|
|
1309
1769
|
onInputBoxWitdhChange: {
|
|
1310
1770
|
type: Function
|
|
1311
1771
|
}
|
|
1312
|
-
}
|
|
1313
|
-
|
|
1772
|
+
};
|
|
1773
|
+
const mdPreviewEmits = ["onHtmlChanged", "onGetCatalog"];
|
|
1774
|
+
const editorEmits = [
|
|
1775
|
+
...mdPreviewEmits,
|
|
1314
1776
|
"onChange",
|
|
1315
1777
|
"onSave",
|
|
1316
1778
|
"onUploadImg",
|
|
@@ -1321,62 +1783,82 @@ const Le = (e, a) => {
|
|
|
1321
1783
|
"onInput",
|
|
1322
1784
|
"onDrop",
|
|
1323
1785
|
"onInputBoxWitdhChange"
|
|
1324
|
-
]
|
|
1325
|
-
|
|
1786
|
+
];
|
|
1787
|
+
const useExpose = (props, ctx) => {
|
|
1788
|
+
const { editorId } = props;
|
|
1789
|
+
const exposeParam = {
|
|
1326
1790
|
rerender() {
|
|
1327
|
-
|
|
1791
|
+
bus.emit(editorId, RERENDER);
|
|
1328
1792
|
}
|
|
1329
1793
|
};
|
|
1330
|
-
|
|
1331
|
-
}
|
|
1794
|
+
ctx.expose(exposeParam);
|
|
1795
|
+
};
|
|
1796
|
+
const MdPreview = /* @__PURE__ */ defineComponent({
|
|
1332
1797
|
name: "MdPreview",
|
|
1333
|
-
props:
|
|
1334
|
-
emits:
|
|
1335
|
-
setup(
|
|
1798
|
+
props: mdPreviewProps,
|
|
1799
|
+
emits: mdPreviewEmits,
|
|
1800
|
+
setup(props, ctx) {
|
|
1336
1801
|
const {
|
|
1337
|
-
editorId
|
|
1338
|
-
noKatex
|
|
1339
|
-
noMermaid
|
|
1340
|
-
noHighlight
|
|
1341
|
-
} =
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1802
|
+
editorId,
|
|
1803
|
+
noKatex,
|
|
1804
|
+
noMermaid,
|
|
1805
|
+
noHighlight
|
|
1806
|
+
} = props;
|
|
1807
|
+
useProvidePreview(props);
|
|
1808
|
+
useExpansionPreview(props);
|
|
1809
|
+
useExpose(props, ctx);
|
|
1810
|
+
onBeforeUnmount(() => {
|
|
1811
|
+
bus.clear(editorId);
|
|
1812
|
+
});
|
|
1813
|
+
return () => {
|
|
1814
|
+
return createVNode("div", {
|
|
1815
|
+
"id": editorId,
|
|
1816
|
+
"class": [prefix, props.class, props.theme === "dark" && `${prefix}-dark`, `${prefix}-previewOnly`],
|
|
1817
|
+
"style": props.style
|
|
1818
|
+
}, [createVNode(ContentPreview, {
|
|
1819
|
+
"modelValue": props.modelValue,
|
|
1820
|
+
"onHtmlChanged": (html) => {
|
|
1821
|
+
if (props.onHtmlChanged) {
|
|
1822
|
+
props.onHtmlChanged(html);
|
|
1823
|
+
} else {
|
|
1824
|
+
ctx.emit("onHtmlChanged", html);
|
|
1825
|
+
}
|
|
1826
|
+
},
|
|
1827
|
+
"onGetCatalog": (list) => {
|
|
1828
|
+
if (props.onGetCatalog) {
|
|
1829
|
+
props.onGetCatalog(list);
|
|
1830
|
+
} else {
|
|
1831
|
+
ctx.emit("onGetCatalog", list);
|
|
1832
|
+
}
|
|
1833
|
+
},
|
|
1834
|
+
"mdHeadingId": props.mdHeadingId,
|
|
1835
|
+
"noMermaid": noMermaid,
|
|
1836
|
+
"sanitize": props.sanitize,
|
|
1837
|
+
"noKatex": noKatex,
|
|
1838
|
+
"formatCopiedText": props.formatCopiedText,
|
|
1839
|
+
"noHighlight": noHighlight,
|
|
1840
|
+
"noImgZoomIn": props.noImgZoomIn,
|
|
1841
|
+
"previewOnly": true,
|
|
1842
|
+
"sanitizeMermaid": props.sanitizeMermaid
|
|
1843
|
+
}, null)]);
|
|
1844
|
+
};
|
|
1366
1845
|
}
|
|
1367
1846
|
});
|
|
1368
|
-
|
|
1847
|
+
MdPreview.install = (app) => {
|
|
1848
|
+
app.component(MdPreview.name, MdPreview);
|
|
1849
|
+
return app;
|
|
1850
|
+
};
|
|
1369
1851
|
export {
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1852
|
+
ContentPreview as C,
|
|
1853
|
+
MdPreview as M,
|
|
1854
|
+
editorEmits as a,
|
|
1855
|
+
useProvide as b,
|
|
1856
|
+
contentProps as c,
|
|
1857
|
+
useExpansion as d,
|
|
1858
|
+
editorProps as e,
|
|
1859
|
+
useErrorCatcher as f,
|
|
1860
|
+
useConfig as g,
|
|
1861
|
+
useCatalog as h,
|
|
1862
|
+
useExpose$1 as i,
|
|
1863
|
+
useOnSave as u
|
|
1382
1864
|
};
|