markdown-it-any-block 3.3.5 → 3.3.7-beta1
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/mdit-any-block.cjs +107 -75
- package/dist/mdit-any-block.js +107 -75
- package/index.ts +2 -1
- package/index_mdit.ts +6 -3
- package/jsdom_init.ts +20 -3
- package/package.json +1 -1
package/dist/mdit-any-block.cjs
CHANGED
|
@@ -23,13 +23,19 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
23
|
));
|
|
24
24
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
25
25
|
const MarkdownIt = require("markdown-it");
|
|
26
|
-
|
|
26
|
+
let dom = null;
|
|
27
|
+
async function jsdom_init(enable = true) {
|
|
28
|
+
if (document) return;
|
|
27
29
|
const { default: jsdom } = await import("jsdom");
|
|
28
30
|
const { JSDOM } = jsdom;
|
|
29
|
-
|
|
31
|
+
dom = new JSDOM(`<!DOCTYPE html><html><body></body></html>`, {
|
|
30
32
|
url: "http://localhost/"
|
|
31
33
|
// @warn 若缺少该行,则在mdit+build环境下,编译报错
|
|
32
34
|
});
|
|
35
|
+
if (enable) jsdom_enable();
|
|
36
|
+
}
|
|
37
|
+
function jsdom_enable() {
|
|
38
|
+
if (!dom) return;
|
|
33
39
|
global.Storage = dom.window.Storage;
|
|
34
40
|
global.window = dom.window;
|
|
35
41
|
global.history = dom.window.history;
|
|
@@ -47,6 +53,68 @@ async function jsdom_init() {
|
|
|
47
53
|
};
|
|
48
54
|
global.MutationObserver = dom.window.MutationObserver;
|
|
49
55
|
}
|
|
56
|
+
function jsdom_disable() {
|
|
57
|
+
if (!dom) return;
|
|
58
|
+
global.window = void 0;
|
|
59
|
+
global.history = void 0;
|
|
60
|
+
global.document = void 0;
|
|
61
|
+
}
|
|
62
|
+
const ABReg = {
|
|
63
|
+
/**
|
|
64
|
+
* AB块头部
|
|
65
|
+
*
|
|
66
|
+
* 例子:` > - > %%[d]:%% `
|
|
67
|
+
*
|
|
68
|
+
* - 前缀部分
|
|
69
|
+
* - $1: 前缀 | ` > - > ` | ((\s|>\s|-\s|\*\s|\+\s)*)
|
|
70
|
+
* - $2: 无用 | `>` | (\s|>\s|-\s|\*\s|\+\s)
|
|
71
|
+
* - 指令部分
|
|
72
|
+
* - $3: 无用 | `%%` | (%%)?
|
|
73
|
+
* - $4:无用 | `[header]` | (\[((?!toc)[0-9a-zA-Z].*)\])
|
|
74
|
+
* - $5:指令 | `header` | (?!toc)[0-9a-zA-Z].*)
|
|
75
|
+
* - $6: 无用 | `%%` | (%%)?
|
|
76
|
+
*
|
|
77
|
+
* 注意:
|
|
78
|
+
* - (?!\[) (?!\toc) 这种向后否定语句不作为一个匹配项
|
|
79
|
+
* - 允许 `%%` 和 `:` 的规则是V3新增的
|
|
80
|
+
* - 不允许 `::` 是避免与 dataview 的 inline property 冲突
|
|
81
|
+
*/
|
|
82
|
+
// 有前缀版本(给选择器用)
|
|
83
|
+
reg_header: /^((\s|>\s|-\s|\*\s|\+\s)*)(%%)?(\[((?!toc|TOC|\!|< )[\|\!#:;\(\)\s0-9a-zA-Z\u4e00-\u9fa5](?!.*::).*)\]):?(%%)?\s*$/,
|
|
84
|
+
// 可以用空`|`来解除首字符限制。(`|`注意:可以用来弄严格模式,`#`注意:建议后面空一格避免变成“标签”,`!`注意:别易误触发 `> [!note]`
|
|
85
|
+
reg_header_up: /^((\s|>\s|-\s|\*\s|\+\s)*)(%%)?(\[((?!toc|TOC|\!)< [\|\!#:;\(\)\s0-9a-zA-Z\u4e00-\u9fa5](?!.*::).*)\]):?(%%)?\s*$/,
|
|
86
|
+
// 向上检查标志的 头部选择器
|
|
87
|
+
reg_mdit_head: /^((\s|>\s|-\s|\*\s|\+\s)*)(::::*)\s?(.*)/,
|
|
88
|
+
reg_mdit_tail: /^((\s|>\s|-\s|\*\s|\+\s)*)(::::*)/,
|
|
89
|
+
reg_list: /^((\s|>\s|-\s|\*\s|\+\s)*)(-\s|\*\s|\+\s)(.*)/,
|
|
90
|
+
//: /^\s*(>\s)*-\s(.*)$/
|
|
91
|
+
reg_code: /^((\s|>\s|-\s|\*\s|\+\s)*)(````*|~~~~*)(.*)/,
|
|
92
|
+
//: /^\s*(>\s|-\s)*(````*|~~~~*)(.*)$/
|
|
93
|
+
reg_quote: /^((\s|>\s|-\s|\*\s|\+\s)*)(>\s)(.*)/,
|
|
94
|
+
// `- > ` 不匹配,要认为这种是列表
|
|
95
|
+
reg_heading: /^((\s|>\s|-\s|\*\s|\+\s)*)(\#+\s)(.*)/,
|
|
96
|
+
reg_table: /^((\s|>\s|-\s|\*\s|\+\s)*)(\|(.*)\|)/,
|
|
97
|
+
// 无前缀版本(给处理器用,处理器不需要处理前缀,前缀在选择器阶段已经被去除了)
|
|
98
|
+
reg_header_noprefix: /^((\s)*)(%%)?(\[((?!toc|TOC|\!|< )[\|\!#:;\(\)\s0-9a-zA-Z\u4e00-\u9fa5](?!.*::).*)\]):?(%%)?\s*$/,
|
|
99
|
+
reg_header_up_noprefix: /^((\s)*)(%%)?(\[((?!toc|TOC|\!)< [\|\!#:;\(\)\s0-9a-zA-Z\u4e00-\u9fa5](?!.*::).*)\]):?(%%)?\s*$/,
|
|
100
|
+
reg_mdit_head_noprefix: /^((\s)*)(::::*)\s?(.*)/,
|
|
101
|
+
reg_mdit_tail_noprefix: /^((\s)*)(::::*)/,
|
|
102
|
+
reg_list_noprefix: /^((\s)*)(-\s|\*\s|\+\s)(.*)/,
|
|
103
|
+
reg_code_noprefix: /^((\s)*)(````*|~~~~*)(.*)/,
|
|
104
|
+
reg_quote_noprefix: /^((\s)*)(>\s)(.*)/,
|
|
105
|
+
reg_heading_noprefix: /^((\s)*)(\#+\s)(.*)/,
|
|
106
|
+
reg_table_noprefix: /^((\s)*)(\|(.*)\|)/,
|
|
107
|
+
reg_emptyline_noprefix: /^\s*$/,
|
|
108
|
+
reg_indentline_noprefix: /^\s+?\S/,
|
|
109
|
+
inline_split: /\| |, |, |\. |。 |: |: /
|
|
110
|
+
// 内联切分。`|`或全角符号+一空格,半角符号+两空格 (后者由于空格压缩,若经历了重渲染可能有问题)
|
|
111
|
+
};
|
|
112
|
+
const ABCSetting = {
|
|
113
|
+
env: "obsidian",
|
|
114
|
+
// MarkdownPostProcessorContext类型, obsidian专用
|
|
115
|
+
mermaid: void 0
|
|
116
|
+
// obsidian专用,表示使用哪种方式渲染mermaid
|
|
117
|
+
};
|
|
50
118
|
var ABConvert_IOEnum = /* @__PURE__ */ ((ABConvert_IOEnum2) => {
|
|
51
119
|
ABConvert_IOEnum2["text"] = "string";
|
|
52
120
|
ABConvert_IOEnum2["el"] = "HTMLElement";
|
|
@@ -114,47 +182,6 @@ class ABConvert {
|
|
|
114
182
|
}
|
|
115
183
|
}
|
|
116
184
|
}
|
|
117
|
-
const ABReg = {
|
|
118
|
-
/**
|
|
119
|
-
* AB块头部
|
|
120
|
-
*
|
|
121
|
-
* 例子:` > - > %%[d]:%% `
|
|
122
|
-
*
|
|
123
|
-
* - 前缀部分
|
|
124
|
-
* - $1: 前缀 | ` > - > ` | ((\s|>\s|-\s|\*\s|\+\s)*)
|
|
125
|
-
* - $2: 无用 | `>` | (\s|>\s|-\s|\*\s|\+\s)
|
|
126
|
-
* - 指令部分
|
|
127
|
-
* - $3: 无用 | `%%` | (%%)?
|
|
128
|
-
* - $4:无用 | `[header]` | (\[((?!toc)[0-9a-zA-Z].*)\])
|
|
129
|
-
* - $5:指令 | `header` | (?!toc)[0-9a-zA-Z].*)
|
|
130
|
-
* - $6: 无用 | `%%` | (%%)?
|
|
131
|
-
*
|
|
132
|
-
* 注意:
|
|
133
|
-
* - (?!\[) (?!\toc) 这种向后否定语句不作为一个匹配项
|
|
134
|
-
* - 允许 `%%` 和 `:` 的规则是V3新增的
|
|
135
|
-
*/
|
|
136
|
-
// 有前缀版本(给选择器用)
|
|
137
|
-
reg_header: /^((\s|>\s|-\s|\*\s|\+\s)*)(%%)?(\[((?!toc|TOC|\!|< )[\|\!#:;\(\)\s0-9a-zA-Z\u4e00-\u9fa5].*)\]):?(%%)?\s*$/,
|
|
138
|
-
// 向上检查标志的 头部选择器
|
|
139
|
-
reg_mdit_head: /^((\s|>\s|-\s|\*\s|\+\s)*)(::::*)\s?(.*)/,
|
|
140
|
-
//: /^\s*(>\s)*-\s(.*)$/
|
|
141
|
-
reg_code: /^((\s|>\s|-\s|\*\s|\+\s)*)(````*|~~~~*)(.*)/,
|
|
142
|
-
//: /^\s*(>\s|-\s)*(````*|~~~~*)(.*)$/
|
|
143
|
-
reg_quote: /^((\s|>\s|-\s|\*\s|\+\s)*)(>\s)(.*)/,
|
|
144
|
-
reg_list_noprefix: /^((\s)*)(-\s|\*\s|\+\s)(.*)/,
|
|
145
|
-
reg_code_noprefix: /^((\s)*)(````*|~~~~*)(.*)/,
|
|
146
|
-
reg_quote_noprefix: /^((\s)*)(>\s)(.*)/,
|
|
147
|
-
reg_heading_noprefix: /^((\s)*)(\#+\s)(.*)/,
|
|
148
|
-
reg_table_noprefix: /^((\s)*)(\|(.*)\|)/,
|
|
149
|
-
inline_split: /\| |, |, |\. |。 |: |: /
|
|
150
|
-
// 内联切分。`|`或全角符号+一空格,半角符号+两空格 (后者由于空格压缩,若经历了重渲染可能有问题)
|
|
151
|
-
};
|
|
152
|
-
const ABCSetting = {
|
|
153
|
-
env: "obsidian",
|
|
154
|
-
// MarkdownPostProcessorContext类型, obsidian专用
|
|
155
|
-
mermaid: void 0
|
|
156
|
-
// obsidian专用,表示使用哪种方式渲染mermaid
|
|
157
|
-
};
|
|
158
185
|
function autoABAlias(header, selectorName, content) {
|
|
159
186
|
if (!header.trimEnd().endsWith("|")) header = header + "|";
|
|
160
187
|
if (!header.trimStart().startsWith("|")) header = "|" + header;
|
|
@@ -3028,7 +3055,7 @@ ABConvert.factory({
|
|
|
3028
3055
|
process_param: ABConvert_IOEnum.text,
|
|
3029
3056
|
process_return: ABConvert_IOEnum.el,
|
|
3030
3057
|
process: (el, header, content) => {
|
|
3031
|
-
if (ABCSetting.env == "
|
|
3058
|
+
if (ABCSetting.env == "markdown-it") {
|
|
3032
3059
|
ABConvertManager.getInstance().m_renderMarkdownFn(`::::: tabs
|
|
3033
3060
|
|
|
3034
3061
|
@tab show
|
|
@@ -17255,16 +17282,16 @@ const DomUtils = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProp
|
|
|
17255
17282
|
textContent,
|
|
17256
17283
|
uniqueSort
|
|
17257
17284
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
17258
|
-
function render(that,
|
|
17285
|
+
function render(that, dom2, options) {
|
|
17259
17286
|
if (!that)
|
|
17260
17287
|
return "";
|
|
17261
|
-
return that(
|
|
17288
|
+
return that(dom2 !== null && dom2 !== void 0 ? dom2 : that._root.children, null, void 0, options).toString();
|
|
17262
17289
|
}
|
|
17263
|
-
function isOptions(
|
|
17264
|
-
return typeof
|
|
17290
|
+
function isOptions(dom2, options) {
|
|
17291
|
+
return typeof dom2 === "object" && dom2 != null && !("length" in dom2) && !("type" in dom2);
|
|
17265
17292
|
}
|
|
17266
|
-
function html$1(
|
|
17267
|
-
const toRender = isOptions(
|
|
17293
|
+
function html$1(dom2, options) {
|
|
17294
|
+
const toRender = isOptions(dom2) ? (options = dom2, void 0) : dom2;
|
|
17268
17295
|
const opts = {
|
|
17269
17296
|
...defaultOpts$2,
|
|
17270
17297
|
...this === null || this === void 0 ? void 0 : this._options,
|
|
@@ -17272,9 +17299,9 @@ function html$1(dom, options) {
|
|
|
17272
17299
|
};
|
|
17273
17300
|
return render(this, toRender, opts);
|
|
17274
17301
|
}
|
|
17275
|
-
function xml(
|
|
17302
|
+
function xml(dom2) {
|
|
17276
17303
|
const options = { ...this._options, xmlMode: true };
|
|
17277
|
-
return render(this,
|
|
17304
|
+
return render(this, dom2, options);
|
|
17278
17305
|
}
|
|
17279
17306
|
function text$1(elements) {
|
|
17280
17307
|
const elems = elements ? elements : this ? this.root() : [];
|
|
@@ -17364,8 +17391,8 @@ function domEach(array, fn) {
|
|
|
17364
17391
|
fn(array[i], i);
|
|
17365
17392
|
return array;
|
|
17366
17393
|
}
|
|
17367
|
-
function cloneDom(
|
|
17368
|
-
const clone2 = "length" in
|
|
17394
|
+
function cloneDom(dom2) {
|
|
17395
|
+
const clone2 = "length" in dom2 ? Array.prototype.map.call(dom2, (el) => cloneNode(el, true)) : [cloneNode(dom2, true)];
|
|
17369
17396
|
const root2 = new Document$1(clone2);
|
|
17370
17397
|
clone2.forEach((node) => {
|
|
17371
17398
|
node.parent = root2;
|
|
@@ -19583,8 +19610,8 @@ function _insert(concatenator) {
|
|
|
19583
19610
|
if (!hasChildren(el))
|
|
19584
19611
|
return;
|
|
19585
19612
|
const domSrc = typeof elems[0] === "function" ? elems[0].call(el, i, this._render(el.children)) : elems;
|
|
19586
|
-
const
|
|
19587
|
-
concatenator(
|
|
19613
|
+
const dom2 = this._makeDomArray(domSrc, i < lastIdx);
|
|
19614
|
+
concatenator(dom2, el.children, el);
|
|
19588
19615
|
});
|
|
19589
19616
|
};
|
|
19590
19617
|
}
|
|
@@ -19638,11 +19665,11 @@ function prependTo(target) {
|
|
|
19638
19665
|
prependTarget.prepend(this);
|
|
19639
19666
|
return this;
|
|
19640
19667
|
}
|
|
19641
|
-
const append = _insert((
|
|
19642
|
-
uniqueSplice(children2, children2.length, 0,
|
|
19668
|
+
const append = _insert((dom2, children2, parent2) => {
|
|
19669
|
+
uniqueSplice(children2, children2.length, 0, dom2, parent2);
|
|
19643
19670
|
});
|
|
19644
|
-
const prepend = _insert((
|
|
19645
|
-
uniqueSplice(children2, 0, 0,
|
|
19671
|
+
const prepend = _insert((dom2, children2, parent2) => {
|
|
19672
|
+
uniqueSplice(children2, 0, 0, dom2, parent2);
|
|
19646
19673
|
});
|
|
19647
19674
|
function _wrap(insert) {
|
|
19648
19675
|
return function(wrapper) {
|
|
@@ -19727,8 +19754,8 @@ function after(...elems) {
|
|
|
19727
19754
|
if (index2 < 0)
|
|
19728
19755
|
return;
|
|
19729
19756
|
const domSrc = typeof elems[0] === "function" ? elems[0].call(el, i, this._render(el.children)) : elems;
|
|
19730
|
-
const
|
|
19731
|
-
uniqueSplice(siblings2, index2 + 1, 0,
|
|
19757
|
+
const dom2 = this._makeDomArray(domSrc, i < lastIdx);
|
|
19758
|
+
uniqueSplice(siblings2, index2 + 1, 0, dom2, parent2);
|
|
19732
19759
|
});
|
|
19733
19760
|
}
|
|
19734
19761
|
function insertAfter(target) {
|
|
@@ -19764,8 +19791,8 @@ function before(...elems) {
|
|
|
19764
19791
|
if (index2 < 0)
|
|
19765
19792
|
return;
|
|
19766
19793
|
const domSrc = typeof elems[0] === "function" ? elems[0].call(el, i, this._render(el.children)) : elems;
|
|
19767
|
-
const
|
|
19768
|
-
uniqueSplice(siblings2, index2, 0,
|
|
19794
|
+
const dom2 = this._makeDomArray(domSrc, i < lastIdx);
|
|
19795
|
+
uniqueSplice(siblings2, index2, 0, dom2, parent2);
|
|
19769
19796
|
});
|
|
19770
19797
|
}
|
|
19771
19798
|
function insertBefore(target) {
|
|
@@ -19803,11 +19830,11 @@ function replaceWith(content) {
|
|
|
19803
19830
|
}
|
|
19804
19831
|
const siblings2 = parent2.children;
|
|
19805
19832
|
const cont = typeof content === "function" ? content.call(el, i, el) : content;
|
|
19806
|
-
const
|
|
19807
|
-
update(
|
|
19833
|
+
const dom2 = this._makeDomArray(cont);
|
|
19834
|
+
update(dom2, null);
|
|
19808
19835
|
const index2 = siblings2.indexOf(el);
|
|
19809
|
-
uniqueSplice(siblings2, index2, 1,
|
|
19810
|
-
if (!
|
|
19836
|
+
uniqueSplice(siblings2, index2, 1, dom2, parent2);
|
|
19837
|
+
if (!dom2.includes(el)) {
|
|
19811
19838
|
el.parent = el.prev = el.next = null;
|
|
19812
19839
|
}
|
|
19813
19840
|
});
|
|
@@ -20043,8 +20070,8 @@ function getLoad(parse2, render2) {
|
|
|
20043
20070
|
_parse(content2, options2, isDocument3, context) {
|
|
20044
20071
|
return parse2(content2, options2, isDocument3, context);
|
|
20045
20072
|
}
|
|
20046
|
-
_render(
|
|
20047
|
-
return render2(
|
|
20073
|
+
_render(dom2) {
|
|
20074
|
+
return render2(dom2, this.options);
|
|
20048
20075
|
}
|
|
20049
20076
|
}
|
|
20050
20077
|
function initialize(selector, context, root2 = initialRoot, opts) {
|
|
@@ -28228,8 +28255,8 @@ function parseWithParse5(content, options, isDocument2, context) {
|
|
|
28228
28255
|
return isDocument2 ? parse$2(content, opts) : parseFragment(context, content, opts);
|
|
28229
28256
|
}
|
|
28230
28257
|
const renderOpts = { treeAdapter: adapter };
|
|
28231
|
-
function renderWithParse5(
|
|
28232
|
-
const nodes = "length" in
|
|
28258
|
+
function renderWithParse5(dom2) {
|
|
28259
|
+
const nodes = "length" in dom2 ? dom2 : [dom2];
|
|
28233
28260
|
for (let index2 = 0; index2 < nodes.length; index2 += 1) {
|
|
28234
28261
|
const node = nodes[index2];
|
|
28235
28262
|
if (isDocument$1(node)) {
|
|
@@ -29481,7 +29508,7 @@ function parseDocument$1(data2, options) {
|
|
|
29481
29508
|
return handler.root;
|
|
29482
29509
|
}
|
|
29483
29510
|
const parse$1 = getParse((content, options, isDocument2, context) => options.xmlMode || options._useHtmlParser2 ? parseDocument$1(content, options) : parseWithParse5(content, options, isDocument2, context));
|
|
29484
|
-
const load = getLoad(parse$1, (
|
|
29511
|
+
const load = getLoad(parse$1, (dom2, options) => options.xmlMode || options._useHtmlParser2 ? render$1(dom2, options) : renderWithParse5(dom2));
|
|
29485
29512
|
load([]);
|
|
29486
29513
|
const defaultSelectorRules = {
|
|
29487
29514
|
"div,p": ({ $node }) => ({
|
|
@@ -49524,9 +49551,11 @@ function abRender_fence(md, options) {
|
|
|
49524
49551
|
ab_header = match2[1];
|
|
49525
49552
|
let ab_content = lines.join("\n");
|
|
49526
49553
|
ab_content = ab_content.trimStart();
|
|
49554
|
+
jsdom_enable();
|
|
49527
49555
|
const el = document.createElement("div");
|
|
49528
49556
|
el.classList.add("ab-note", "drop-shadow");
|
|
49529
49557
|
ABConvertManager.autoABConvert(el, ab_header, ab_content, token.markup.startsWith(":::") ? "mdit" : "");
|
|
49558
|
+
jsdom_disable();
|
|
49530
49559
|
if (el.classList.contains("ab-raw")) {
|
|
49531
49560
|
const subEl = el.querySelector(".ab-raw-data");
|
|
49532
49561
|
if (subEl) {
|
|
@@ -49562,7 +49591,7 @@ function ab_mdit(md, options) {
|
|
|
49562
49591
|
el.appendChild(el_child);
|
|
49563
49592
|
el_child.innerHTML = result;
|
|
49564
49593
|
});
|
|
49565
|
-
ABCSetting.env = "
|
|
49594
|
+
ABCSetting.env = "markdown-it";
|
|
49566
49595
|
md.use(abSelector_squareInline);
|
|
49567
49596
|
md.use(abSelector_container);
|
|
49568
49597
|
md.use(abRender_fence);
|
|
@@ -49575,13 +49604,16 @@ function ab_mdit_client(md, options) {
|
|
|
49575
49604
|
el.appendChild(el_child);
|
|
49576
49605
|
el_child.innerHTML = result;
|
|
49577
49606
|
});
|
|
49578
|
-
ABCSetting.env = "
|
|
49607
|
+
ABCSetting.env = "markdown-it";
|
|
49579
49608
|
md.use(abSelector_squareInline);
|
|
49580
49609
|
md.use(abSelector_container);
|
|
49581
49610
|
}
|
|
49582
49611
|
exports.ABConvertManager = ABConvertManager;
|
|
49612
|
+
exports.ABReg = ABReg;
|
|
49583
49613
|
exports.abConvertEvent = abConvertEvent;
|
|
49584
49614
|
exports.ab_mdit = ab_mdit;
|
|
49585
49615
|
exports.ab_mdit_client = ab_mdit_client;
|
|
49616
|
+
exports.jsdom_disable = jsdom_disable;
|
|
49617
|
+
exports.jsdom_enable = jsdom_enable;
|
|
49586
49618
|
exports.jsdom_init = jsdom_init;
|
|
49587
49619
|
//# sourceMappingURL=mdit-any-block.cjs.map
|
package/dist/mdit-any-block.js
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import MarkdownIt from "markdown-it";
|
|
2
|
-
|
|
2
|
+
let dom = null;
|
|
3
|
+
async function jsdom_init(enable = true) {
|
|
4
|
+
if (document) return;
|
|
3
5
|
const { default: jsdom } = await import("jsdom");
|
|
4
6
|
const { JSDOM } = jsdom;
|
|
5
|
-
|
|
7
|
+
dom = new JSDOM(`<!DOCTYPE html><html><body></body></html>`, {
|
|
6
8
|
url: "http://localhost/"
|
|
7
9
|
// @warn 若缺少该行,则在mdit+build环境下,编译报错
|
|
8
10
|
});
|
|
11
|
+
if (enable) jsdom_enable();
|
|
12
|
+
}
|
|
13
|
+
function jsdom_enable() {
|
|
14
|
+
if (!dom) return;
|
|
9
15
|
global.Storage = dom.window.Storage;
|
|
10
16
|
global.window = dom.window;
|
|
11
17
|
global.history = dom.window.history;
|
|
@@ -23,6 +29,68 @@ async function jsdom_init() {
|
|
|
23
29
|
};
|
|
24
30
|
global.MutationObserver = dom.window.MutationObserver;
|
|
25
31
|
}
|
|
32
|
+
function jsdom_disable() {
|
|
33
|
+
if (!dom) return;
|
|
34
|
+
global.window = void 0;
|
|
35
|
+
global.history = void 0;
|
|
36
|
+
global.document = void 0;
|
|
37
|
+
}
|
|
38
|
+
const ABReg = {
|
|
39
|
+
/**
|
|
40
|
+
* AB块头部
|
|
41
|
+
*
|
|
42
|
+
* 例子:` > - > %%[d]:%% `
|
|
43
|
+
*
|
|
44
|
+
* - 前缀部分
|
|
45
|
+
* - $1: 前缀 | ` > - > ` | ((\s|>\s|-\s|\*\s|\+\s)*)
|
|
46
|
+
* - $2: 无用 | `>` | (\s|>\s|-\s|\*\s|\+\s)
|
|
47
|
+
* - 指令部分
|
|
48
|
+
* - $3: 无用 | `%%` | (%%)?
|
|
49
|
+
* - $4:无用 | `[header]` | (\[((?!toc)[0-9a-zA-Z].*)\])
|
|
50
|
+
* - $5:指令 | `header` | (?!toc)[0-9a-zA-Z].*)
|
|
51
|
+
* - $6: 无用 | `%%` | (%%)?
|
|
52
|
+
*
|
|
53
|
+
* 注意:
|
|
54
|
+
* - (?!\[) (?!\toc) 这种向后否定语句不作为一个匹配项
|
|
55
|
+
* - 允许 `%%` 和 `:` 的规则是V3新增的
|
|
56
|
+
* - 不允许 `::` 是避免与 dataview 的 inline property 冲突
|
|
57
|
+
*/
|
|
58
|
+
// 有前缀版本(给选择器用)
|
|
59
|
+
reg_header: /^((\s|>\s|-\s|\*\s|\+\s)*)(%%)?(\[((?!toc|TOC|\!|< )[\|\!#:;\(\)\s0-9a-zA-Z\u4e00-\u9fa5](?!.*::).*)\]):?(%%)?\s*$/,
|
|
60
|
+
// 可以用空`|`来解除首字符限制。(`|`注意:可以用来弄严格模式,`#`注意:建议后面空一格避免变成“标签”,`!`注意:别易误触发 `> [!note]`
|
|
61
|
+
reg_header_up: /^((\s|>\s|-\s|\*\s|\+\s)*)(%%)?(\[((?!toc|TOC|\!)< [\|\!#:;\(\)\s0-9a-zA-Z\u4e00-\u9fa5](?!.*::).*)\]):?(%%)?\s*$/,
|
|
62
|
+
// 向上检查标志的 头部选择器
|
|
63
|
+
reg_mdit_head: /^((\s|>\s|-\s|\*\s|\+\s)*)(::::*)\s?(.*)/,
|
|
64
|
+
reg_mdit_tail: /^((\s|>\s|-\s|\*\s|\+\s)*)(::::*)/,
|
|
65
|
+
reg_list: /^((\s|>\s|-\s|\*\s|\+\s)*)(-\s|\*\s|\+\s)(.*)/,
|
|
66
|
+
//: /^\s*(>\s)*-\s(.*)$/
|
|
67
|
+
reg_code: /^((\s|>\s|-\s|\*\s|\+\s)*)(````*|~~~~*)(.*)/,
|
|
68
|
+
//: /^\s*(>\s|-\s)*(````*|~~~~*)(.*)$/
|
|
69
|
+
reg_quote: /^((\s|>\s|-\s|\*\s|\+\s)*)(>\s)(.*)/,
|
|
70
|
+
// `- > ` 不匹配,要认为这种是列表
|
|
71
|
+
reg_heading: /^((\s|>\s|-\s|\*\s|\+\s)*)(\#+\s)(.*)/,
|
|
72
|
+
reg_table: /^((\s|>\s|-\s|\*\s|\+\s)*)(\|(.*)\|)/,
|
|
73
|
+
// 无前缀版本(给处理器用,处理器不需要处理前缀,前缀在选择器阶段已经被去除了)
|
|
74
|
+
reg_header_noprefix: /^((\s)*)(%%)?(\[((?!toc|TOC|\!|< )[\|\!#:;\(\)\s0-9a-zA-Z\u4e00-\u9fa5](?!.*::).*)\]):?(%%)?\s*$/,
|
|
75
|
+
reg_header_up_noprefix: /^((\s)*)(%%)?(\[((?!toc|TOC|\!)< [\|\!#:;\(\)\s0-9a-zA-Z\u4e00-\u9fa5](?!.*::).*)\]):?(%%)?\s*$/,
|
|
76
|
+
reg_mdit_head_noprefix: /^((\s)*)(::::*)\s?(.*)/,
|
|
77
|
+
reg_mdit_tail_noprefix: /^((\s)*)(::::*)/,
|
|
78
|
+
reg_list_noprefix: /^((\s)*)(-\s|\*\s|\+\s)(.*)/,
|
|
79
|
+
reg_code_noprefix: /^((\s)*)(````*|~~~~*)(.*)/,
|
|
80
|
+
reg_quote_noprefix: /^((\s)*)(>\s)(.*)/,
|
|
81
|
+
reg_heading_noprefix: /^((\s)*)(\#+\s)(.*)/,
|
|
82
|
+
reg_table_noprefix: /^((\s)*)(\|(.*)\|)/,
|
|
83
|
+
reg_emptyline_noprefix: /^\s*$/,
|
|
84
|
+
reg_indentline_noprefix: /^\s+?\S/,
|
|
85
|
+
inline_split: /\| |, |, |\. |。 |: |: /
|
|
86
|
+
// 内联切分。`|`或全角符号+一空格,半角符号+两空格 (后者由于空格压缩,若经历了重渲染可能有问题)
|
|
87
|
+
};
|
|
88
|
+
const ABCSetting = {
|
|
89
|
+
env: "obsidian",
|
|
90
|
+
// MarkdownPostProcessorContext类型, obsidian专用
|
|
91
|
+
mermaid: void 0
|
|
92
|
+
// obsidian专用,表示使用哪种方式渲染mermaid
|
|
93
|
+
};
|
|
26
94
|
var ABConvert_IOEnum = /* @__PURE__ */ ((ABConvert_IOEnum2) => {
|
|
27
95
|
ABConvert_IOEnum2["text"] = "string";
|
|
28
96
|
ABConvert_IOEnum2["el"] = "HTMLElement";
|
|
@@ -90,47 +158,6 @@ class ABConvert {
|
|
|
90
158
|
}
|
|
91
159
|
}
|
|
92
160
|
}
|
|
93
|
-
const ABReg = {
|
|
94
|
-
/**
|
|
95
|
-
* AB块头部
|
|
96
|
-
*
|
|
97
|
-
* 例子:` > - > %%[d]:%% `
|
|
98
|
-
*
|
|
99
|
-
* - 前缀部分
|
|
100
|
-
* - $1: 前缀 | ` > - > ` | ((\s|>\s|-\s|\*\s|\+\s)*)
|
|
101
|
-
* - $2: 无用 | `>` | (\s|>\s|-\s|\*\s|\+\s)
|
|
102
|
-
* - 指令部分
|
|
103
|
-
* - $3: 无用 | `%%` | (%%)?
|
|
104
|
-
* - $4:无用 | `[header]` | (\[((?!toc)[0-9a-zA-Z].*)\])
|
|
105
|
-
* - $5:指令 | `header` | (?!toc)[0-9a-zA-Z].*)
|
|
106
|
-
* - $6: 无用 | `%%` | (%%)?
|
|
107
|
-
*
|
|
108
|
-
* 注意:
|
|
109
|
-
* - (?!\[) (?!\toc) 这种向后否定语句不作为一个匹配项
|
|
110
|
-
* - 允许 `%%` 和 `:` 的规则是V3新增的
|
|
111
|
-
*/
|
|
112
|
-
// 有前缀版本(给选择器用)
|
|
113
|
-
reg_header: /^((\s|>\s|-\s|\*\s|\+\s)*)(%%)?(\[((?!toc|TOC|\!|< )[\|\!#:;\(\)\s0-9a-zA-Z\u4e00-\u9fa5].*)\]):?(%%)?\s*$/,
|
|
114
|
-
// 向上检查标志的 头部选择器
|
|
115
|
-
reg_mdit_head: /^((\s|>\s|-\s|\*\s|\+\s)*)(::::*)\s?(.*)/,
|
|
116
|
-
//: /^\s*(>\s)*-\s(.*)$/
|
|
117
|
-
reg_code: /^((\s|>\s|-\s|\*\s|\+\s)*)(````*|~~~~*)(.*)/,
|
|
118
|
-
//: /^\s*(>\s|-\s)*(````*|~~~~*)(.*)$/
|
|
119
|
-
reg_quote: /^((\s|>\s|-\s|\*\s|\+\s)*)(>\s)(.*)/,
|
|
120
|
-
reg_list_noprefix: /^((\s)*)(-\s|\*\s|\+\s)(.*)/,
|
|
121
|
-
reg_code_noprefix: /^((\s)*)(````*|~~~~*)(.*)/,
|
|
122
|
-
reg_quote_noprefix: /^((\s)*)(>\s)(.*)/,
|
|
123
|
-
reg_heading_noprefix: /^((\s)*)(\#+\s)(.*)/,
|
|
124
|
-
reg_table_noprefix: /^((\s)*)(\|(.*)\|)/,
|
|
125
|
-
inline_split: /\| |, |, |\. |。 |: |: /
|
|
126
|
-
// 内联切分。`|`或全角符号+一空格,半角符号+两空格 (后者由于空格压缩,若经历了重渲染可能有问题)
|
|
127
|
-
};
|
|
128
|
-
const ABCSetting = {
|
|
129
|
-
env: "obsidian",
|
|
130
|
-
// MarkdownPostProcessorContext类型, obsidian专用
|
|
131
|
-
mermaid: void 0
|
|
132
|
-
// obsidian专用,表示使用哪种方式渲染mermaid
|
|
133
|
-
};
|
|
134
161
|
function autoABAlias(header, selectorName, content) {
|
|
135
162
|
if (!header.trimEnd().endsWith("|")) header = header + "|";
|
|
136
163
|
if (!header.trimStart().startsWith("|")) header = "|" + header;
|
|
@@ -3004,7 +3031,7 @@ ABConvert.factory({
|
|
|
3004
3031
|
process_param: ABConvert_IOEnum.text,
|
|
3005
3032
|
process_return: ABConvert_IOEnum.el,
|
|
3006
3033
|
process: (el, header, content) => {
|
|
3007
|
-
if (ABCSetting.env == "
|
|
3034
|
+
if (ABCSetting.env == "markdown-it") {
|
|
3008
3035
|
ABConvertManager.getInstance().m_renderMarkdownFn(`::::: tabs
|
|
3009
3036
|
|
|
3010
3037
|
@tab show
|
|
@@ -17231,16 +17258,16 @@ const DomUtils = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProp
|
|
|
17231
17258
|
textContent,
|
|
17232
17259
|
uniqueSort
|
|
17233
17260
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
17234
|
-
function render(that,
|
|
17261
|
+
function render(that, dom2, options) {
|
|
17235
17262
|
if (!that)
|
|
17236
17263
|
return "";
|
|
17237
|
-
return that(
|
|
17264
|
+
return that(dom2 !== null && dom2 !== void 0 ? dom2 : that._root.children, null, void 0, options).toString();
|
|
17238
17265
|
}
|
|
17239
|
-
function isOptions(
|
|
17240
|
-
return typeof
|
|
17266
|
+
function isOptions(dom2, options) {
|
|
17267
|
+
return typeof dom2 === "object" && dom2 != null && !("length" in dom2) && !("type" in dom2);
|
|
17241
17268
|
}
|
|
17242
|
-
function html$1(
|
|
17243
|
-
const toRender = isOptions(
|
|
17269
|
+
function html$1(dom2, options) {
|
|
17270
|
+
const toRender = isOptions(dom2) ? (options = dom2, void 0) : dom2;
|
|
17244
17271
|
const opts = {
|
|
17245
17272
|
...defaultOpts$2,
|
|
17246
17273
|
...this === null || this === void 0 ? void 0 : this._options,
|
|
@@ -17248,9 +17275,9 @@ function html$1(dom, options) {
|
|
|
17248
17275
|
};
|
|
17249
17276
|
return render(this, toRender, opts);
|
|
17250
17277
|
}
|
|
17251
|
-
function xml(
|
|
17278
|
+
function xml(dom2) {
|
|
17252
17279
|
const options = { ...this._options, xmlMode: true };
|
|
17253
|
-
return render(this,
|
|
17280
|
+
return render(this, dom2, options);
|
|
17254
17281
|
}
|
|
17255
17282
|
function text$1(elements) {
|
|
17256
17283
|
const elems = elements ? elements : this ? this.root() : [];
|
|
@@ -17340,8 +17367,8 @@ function domEach(array, fn) {
|
|
|
17340
17367
|
fn(array[i], i);
|
|
17341
17368
|
return array;
|
|
17342
17369
|
}
|
|
17343
|
-
function cloneDom(
|
|
17344
|
-
const clone2 = "length" in
|
|
17370
|
+
function cloneDom(dom2) {
|
|
17371
|
+
const clone2 = "length" in dom2 ? Array.prototype.map.call(dom2, (el) => cloneNode(el, true)) : [cloneNode(dom2, true)];
|
|
17345
17372
|
const root2 = new Document$1(clone2);
|
|
17346
17373
|
clone2.forEach((node) => {
|
|
17347
17374
|
node.parent = root2;
|
|
@@ -19559,8 +19586,8 @@ function _insert(concatenator) {
|
|
|
19559
19586
|
if (!hasChildren(el))
|
|
19560
19587
|
return;
|
|
19561
19588
|
const domSrc = typeof elems[0] === "function" ? elems[0].call(el, i, this._render(el.children)) : elems;
|
|
19562
|
-
const
|
|
19563
|
-
concatenator(
|
|
19589
|
+
const dom2 = this._makeDomArray(domSrc, i < lastIdx);
|
|
19590
|
+
concatenator(dom2, el.children, el);
|
|
19564
19591
|
});
|
|
19565
19592
|
};
|
|
19566
19593
|
}
|
|
@@ -19614,11 +19641,11 @@ function prependTo(target) {
|
|
|
19614
19641
|
prependTarget.prepend(this);
|
|
19615
19642
|
return this;
|
|
19616
19643
|
}
|
|
19617
|
-
const append = _insert((
|
|
19618
|
-
uniqueSplice(children2, children2.length, 0,
|
|
19644
|
+
const append = _insert((dom2, children2, parent2) => {
|
|
19645
|
+
uniqueSplice(children2, children2.length, 0, dom2, parent2);
|
|
19619
19646
|
});
|
|
19620
|
-
const prepend = _insert((
|
|
19621
|
-
uniqueSplice(children2, 0, 0,
|
|
19647
|
+
const prepend = _insert((dom2, children2, parent2) => {
|
|
19648
|
+
uniqueSplice(children2, 0, 0, dom2, parent2);
|
|
19622
19649
|
});
|
|
19623
19650
|
function _wrap(insert) {
|
|
19624
19651
|
return function(wrapper) {
|
|
@@ -19703,8 +19730,8 @@ function after(...elems) {
|
|
|
19703
19730
|
if (index2 < 0)
|
|
19704
19731
|
return;
|
|
19705
19732
|
const domSrc = typeof elems[0] === "function" ? elems[0].call(el, i, this._render(el.children)) : elems;
|
|
19706
|
-
const
|
|
19707
|
-
uniqueSplice(siblings2, index2 + 1, 0,
|
|
19733
|
+
const dom2 = this._makeDomArray(domSrc, i < lastIdx);
|
|
19734
|
+
uniqueSplice(siblings2, index2 + 1, 0, dom2, parent2);
|
|
19708
19735
|
});
|
|
19709
19736
|
}
|
|
19710
19737
|
function insertAfter(target) {
|
|
@@ -19740,8 +19767,8 @@ function before(...elems) {
|
|
|
19740
19767
|
if (index2 < 0)
|
|
19741
19768
|
return;
|
|
19742
19769
|
const domSrc = typeof elems[0] === "function" ? elems[0].call(el, i, this._render(el.children)) : elems;
|
|
19743
|
-
const
|
|
19744
|
-
uniqueSplice(siblings2, index2, 0,
|
|
19770
|
+
const dom2 = this._makeDomArray(domSrc, i < lastIdx);
|
|
19771
|
+
uniqueSplice(siblings2, index2, 0, dom2, parent2);
|
|
19745
19772
|
});
|
|
19746
19773
|
}
|
|
19747
19774
|
function insertBefore(target) {
|
|
@@ -19779,11 +19806,11 @@ function replaceWith(content) {
|
|
|
19779
19806
|
}
|
|
19780
19807
|
const siblings2 = parent2.children;
|
|
19781
19808
|
const cont = typeof content === "function" ? content.call(el, i, el) : content;
|
|
19782
|
-
const
|
|
19783
|
-
update(
|
|
19809
|
+
const dom2 = this._makeDomArray(cont);
|
|
19810
|
+
update(dom2, null);
|
|
19784
19811
|
const index2 = siblings2.indexOf(el);
|
|
19785
|
-
uniqueSplice(siblings2, index2, 1,
|
|
19786
|
-
if (!
|
|
19812
|
+
uniqueSplice(siblings2, index2, 1, dom2, parent2);
|
|
19813
|
+
if (!dom2.includes(el)) {
|
|
19787
19814
|
el.parent = el.prev = el.next = null;
|
|
19788
19815
|
}
|
|
19789
19816
|
});
|
|
@@ -20019,8 +20046,8 @@ function getLoad(parse2, render2) {
|
|
|
20019
20046
|
_parse(content2, options2, isDocument3, context) {
|
|
20020
20047
|
return parse2(content2, options2, isDocument3, context);
|
|
20021
20048
|
}
|
|
20022
|
-
_render(
|
|
20023
|
-
return render2(
|
|
20049
|
+
_render(dom2) {
|
|
20050
|
+
return render2(dom2, this.options);
|
|
20024
20051
|
}
|
|
20025
20052
|
}
|
|
20026
20053
|
function initialize(selector, context, root2 = initialRoot, opts) {
|
|
@@ -28204,8 +28231,8 @@ function parseWithParse5(content, options, isDocument2, context) {
|
|
|
28204
28231
|
return isDocument2 ? parse$2(content, opts) : parseFragment(context, content, opts);
|
|
28205
28232
|
}
|
|
28206
28233
|
const renderOpts = { treeAdapter: adapter };
|
|
28207
|
-
function renderWithParse5(
|
|
28208
|
-
const nodes = "length" in
|
|
28234
|
+
function renderWithParse5(dom2) {
|
|
28235
|
+
const nodes = "length" in dom2 ? dom2 : [dom2];
|
|
28209
28236
|
for (let index2 = 0; index2 < nodes.length; index2 += 1) {
|
|
28210
28237
|
const node = nodes[index2];
|
|
28211
28238
|
if (isDocument$1(node)) {
|
|
@@ -29457,7 +29484,7 @@ function parseDocument$1(data2, options) {
|
|
|
29457
29484
|
return handler.root;
|
|
29458
29485
|
}
|
|
29459
29486
|
const parse$1 = getParse((content, options, isDocument2, context) => options.xmlMode || options._useHtmlParser2 ? parseDocument$1(content, options) : parseWithParse5(content, options, isDocument2, context));
|
|
29460
|
-
const load = getLoad(parse$1, (
|
|
29487
|
+
const load = getLoad(parse$1, (dom2, options) => options.xmlMode || options._useHtmlParser2 ? render$1(dom2, options) : renderWithParse5(dom2));
|
|
29461
29488
|
load([]);
|
|
29462
29489
|
const defaultSelectorRules = {
|
|
29463
29490
|
"div,p": ({ $node }) => ({
|
|
@@ -49500,9 +49527,11 @@ function abRender_fence(md, options) {
|
|
|
49500
49527
|
ab_header = match2[1];
|
|
49501
49528
|
let ab_content = lines.join("\n");
|
|
49502
49529
|
ab_content = ab_content.trimStart();
|
|
49530
|
+
jsdom_enable();
|
|
49503
49531
|
const el = document.createElement("div");
|
|
49504
49532
|
el.classList.add("ab-note", "drop-shadow");
|
|
49505
49533
|
ABConvertManager.autoABConvert(el, ab_header, ab_content, token.markup.startsWith(":::") ? "mdit" : "");
|
|
49534
|
+
jsdom_disable();
|
|
49506
49535
|
if (el.classList.contains("ab-raw")) {
|
|
49507
49536
|
const subEl = el.querySelector(".ab-raw-data");
|
|
49508
49537
|
if (subEl) {
|
|
@@ -49538,7 +49567,7 @@ function ab_mdit(md, options) {
|
|
|
49538
49567
|
el.appendChild(el_child);
|
|
49539
49568
|
el_child.innerHTML = result;
|
|
49540
49569
|
});
|
|
49541
|
-
ABCSetting.env = "
|
|
49570
|
+
ABCSetting.env = "markdown-it";
|
|
49542
49571
|
md.use(abSelector_squareInline);
|
|
49543
49572
|
md.use(abSelector_container);
|
|
49544
49573
|
md.use(abRender_fence);
|
|
@@ -49551,15 +49580,18 @@ function ab_mdit_client(md, options) {
|
|
|
49551
49580
|
el.appendChild(el_child);
|
|
49552
49581
|
el_child.innerHTML = result;
|
|
49553
49582
|
});
|
|
49554
|
-
ABCSetting.env = "
|
|
49583
|
+
ABCSetting.env = "markdown-it";
|
|
49555
49584
|
md.use(abSelector_squareInline);
|
|
49556
49585
|
md.use(abSelector_container);
|
|
49557
49586
|
}
|
|
49558
49587
|
export {
|
|
49559
49588
|
ABConvertManager,
|
|
49589
|
+
ABReg,
|
|
49560
49590
|
abConvertEvent,
|
|
49561
49591
|
ab_mdit,
|
|
49562
49592
|
ab_mdit_client,
|
|
49593
|
+
jsdom_disable,
|
|
49594
|
+
jsdom_enable,
|
|
49563
49595
|
jsdom_init
|
|
49564
49596
|
};
|
|
49565
49597
|
//# sourceMappingURL=mdit-any-block.js.map
|
package/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// JsDom。仅用于提供document对象支持 (如果Ob环境中则不需要,用ob自带document对象的)
|
|
2
|
-
export
|
|
2
|
+
export * from './jsdom_init'
|
|
3
|
+
export { ABReg } from '../ABConverter/ABReg'
|
|
3
4
|
export { ab_mdit, ab_mdit_client } from './index_mdit'
|
|
4
5
|
export { abConvertEvent } from '../ABConverter/ABConvertEvent'
|
|
5
6
|
export { ABConvertManager } from '../ABConverter/ABConvertManager' // for client
|
package/index_mdit.ts
CHANGED
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
import MarkdownIt from "markdown-it"
|
|
45
45
|
|
|
46
46
|
// 2. markdown-it-container
|
|
47
|
-
import MarkdownItConstructor from "markdown-it-container"
|
|
47
|
+
import MarkdownItConstructor from "markdown-it-container"
|
|
48
48
|
|
|
49
49
|
// 3. markdown-it-anyblock 插件
|
|
50
50
|
// import { ABConvertManager } from "./index"
|
|
@@ -65,6 +65,7 @@ import "../ABConverter/converter/abc_echarts"
|
|
|
65
65
|
import "../ABConverter/converter/abc_plantuml" // 可选建议:
|
|
66
66
|
import "../ABConverter/converter/abc_mermaid" // 可选建议:新版无额外依赖,旧版非 min 环境下 7.1MB
|
|
67
67
|
import "../ABConverter/converter/abc_markmap" // 可选建议:1.3MB
|
|
68
|
+
import { jsdom_disable, jsdom_enable } from "./jsdom_init"
|
|
68
69
|
|
|
69
70
|
interface Options {
|
|
70
71
|
multiline: boolean;
|
|
@@ -372,10 +373,12 @@ function abRender_fence(md: MarkdownIt, options?: Partial<Options>): void {
|
|
|
372
373
|
//`<!--afterbegin-->${rawCode}<!--beforeend--></div><!--afterend-->`
|
|
373
374
|
|
|
374
375
|
// anyBlock专属渲染
|
|
376
|
+
jsdom_enable()
|
|
375
377
|
const el: HTMLDivElement = document.createElement("div"); el.classList.add("ab-note", "drop-shadow");
|
|
376
378
|
// 临时el,未appendClild到dom中,脱离作用域会自动销毁
|
|
377
379
|
// 用临时el是因为 mdit render 是 md_str 转 html_str 的,而Ob和原插件那边是使用HTML类的,要兼容
|
|
378
380
|
ABConvertManager.autoABConvert(el, ab_header, ab_content, token.markup.startsWith(':::')?'mdit':'')
|
|
381
|
+
jsdom_disable()
|
|
379
382
|
|
|
380
383
|
// anyBlock特殊情况 - 需要再渲染 (ob不需要,主要是vuepress有些插件可以复用一下,并且处理mdit无客户端环境可能存在的问题)
|
|
381
384
|
if (el.classList.contains("ab-raw")) {
|
|
@@ -427,7 +430,7 @@ export function ab_mdit(md: MarkdownIt, options?: Partial<Options>): void {
|
|
|
427
430
|
})
|
|
428
431
|
|
|
429
432
|
// 定义环境条件
|
|
430
|
-
ABCSetting.env = "
|
|
433
|
+
ABCSetting.env = "markdown-it"
|
|
431
434
|
|
|
432
435
|
md.use(abSelector_squareInline)
|
|
433
436
|
md.use(abSelector_container)
|
|
@@ -444,7 +447,7 @@ export function ab_mdit_client(md: MarkdownIt, options?: Partial<Options>): void
|
|
|
444
447
|
})
|
|
445
448
|
|
|
446
449
|
// 定义环境条件
|
|
447
|
-
ABCSetting.env = "
|
|
450
|
+
ABCSetting.env = "markdown-it"
|
|
448
451
|
|
|
449
452
|
md.use(abSelector_squareInline)
|
|
450
453
|
md.use(abSelector_container)
|
package/jsdom_init.ts
CHANGED
|
@@ -6,12 +6,21 @@
|
|
|
6
6
|
|
|
7
7
|
// import jsdom from "jsdom"
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
let dom: any = null;
|
|
10
|
+
|
|
11
|
+
export async function jsdom_init(enable: boolean = true) {
|
|
12
|
+
if (document) return // 客户端环境,无需 jsdom 环境,同时也避免误卸载 document 环境
|
|
10
13
|
const { default: jsdom } = await import('jsdom') // 废弃,要同步,避免docuemnt初始化不及时
|
|
11
14
|
const { JSDOM } = jsdom
|
|
12
|
-
|
|
15
|
+
dom = new JSDOM(`<!DOCTYPE html><html><body></body></html>`, {
|
|
13
16
|
url: 'http://localhost/', // @warn 若缺少该行,则在mdit+build环境下,编译报错
|
|
14
|
-
})
|
|
17
|
+
})
|
|
18
|
+
if (enable) jsdom_enable()
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/// 启用 jsdom 环境
|
|
22
|
+
export function jsdom_enable() {
|
|
23
|
+
if (!dom) return // console.error("jsdom_enable failed: please run jsdom_init first.") // 允许客户端中运行,不使用jsdom
|
|
15
24
|
global.Storage = dom.window.Storage;
|
|
16
25
|
global.window = dom.window as any
|
|
17
26
|
global.history = dom.window.history // @warn 若缺少该行,则在mdit+build环境下,编译报错:ReferenceError: history is not defined
|
|
@@ -28,3 +37,11 @@ export async function jsdom_init() {
|
|
|
28
37
|
dom.window.scrollTo = ()=>{} // @warn 若缺少该行,编译警告:Error: Not implemented: window.scrollTo
|
|
29
38
|
global.MutationObserver = dom.window.MutationObserver
|
|
30
39
|
}
|
|
40
|
+
|
|
41
|
+
/// 禁用 jsdom 环境
|
|
42
|
+
export function jsdom_disable() {
|
|
43
|
+
if (!dom) return // console.error("jsdom_disable failed: please run jsdom_init first.") // 允许客户端中运行,不使用jsdom
|
|
44
|
+
global.window = undefined
|
|
45
|
+
global.history = undefined
|
|
46
|
+
global.document = undefined
|
|
47
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markdown-it-any-block",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.7-beta1",
|
|
4
4
|
"description": "You can flexibility to create a 'Block' by many means. It also provides many useful features, like `list to table`. (obsidian/markdown-it/vuepress plugin/app)",
|
|
5
5
|
"types": "@types/index_mdit.d.ts",
|
|
6
6
|
"type": "module",
|