@anyblock/remark-any-block 1.0.1 → 1.0.3-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/README.md +14 -2
- package/anyblock.ts +6 -3
- package/dist/remark-any-block.cjs +128 -56
- package/dist/remark-any-block.js +128 -56
- package/index.ts +3 -2
- package/jsdom_init.ts +27 -3
- package/package.json +45 -45
package/README.md
CHANGED
|
@@ -2,9 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
## remark-any-block 使用
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
当前使用 Remark 解析/渲染引擎的主流 SSG (静态网站生成器) 有:
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- Astro
|
|
8
|
+
- Quartz4: 包含 OFM (Obsidian风格Markdown) 相关的插件
|
|
9
|
+
- Docusaurus: 包含 MDX 相关插件
|
|
10
|
+
|
|
11
|
+
> [!WARNING]
|
|
12
|
+
> 暂时不属于完全通用的 Remark 插件 (doing, 或者你自己改改), 当前该插件测试于 Quartz V4 版本
|
|
13
|
+
> 详见 [any-block/QuartzDemo](https://github.com/any-block/QuartzDemo)
|
|
14
|
+
>
|
|
15
|
+
> Quartz V4 在 remark 的基础上又封装了一层
|
|
16
|
+
|
|
17
|
+
## 使用案例/示例
|
|
18
|
+
|
|
19
|
+
见 [any-block/QuartzDemo](https://github.com/any-block/QuartzDemo)
|
|
8
20
|
|
|
9
21
|
## 构建
|
|
10
22
|
|
package/anyblock.ts
CHANGED
|
@@ -179,7 +179,7 @@ export const remark_anyblock_render_codeblock = () => {
|
|
|
179
179
|
if (typeof document == "undefined") return
|
|
180
180
|
return (tree: Root, _file: VFile) => {
|
|
181
181
|
visit(tree, "code", (node: Code, index: number|undefined, parent: any|undefined) => { // 遍历所有的 code 类型节点
|
|
182
|
-
if (node.lang.toLowerCase() != "anyblock") return
|
|
182
|
+
if (typeof node.lang != "string" || node.lang.toLowerCase() != "anyblock") return
|
|
183
183
|
if (!parent || !index) return
|
|
184
184
|
|
|
185
185
|
const lines = node.value.split("\n")
|
|
@@ -230,8 +230,11 @@ export const remark_anyblock_render_codeblock = () => {
|
|
|
230
230
|
})
|
|
231
231
|
}
|
|
232
232
|
|
|
233
|
-
|
|
234
|
-
|
|
233
|
+
/** 这是 Quartz 的 Transformer 插件定义
|
|
234
|
+
*
|
|
235
|
+
* 仅 Quartz 项目可用,其他 Remark 项目 (如 Astro、Docusaurus) 不需要用到这个
|
|
236
|
+
*/
|
|
237
|
+
export const quartz_transformer_anyblock: QuartzTransformerPlugin = (/*options: any*/) => {
|
|
235
238
|
return {
|
|
236
239
|
name: "AnyBlock",
|
|
237
240
|
markdownPlugins(_ctx: BuildCtx) {
|
|
@@ -23,13 +23,21 @@ 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
|
+
let disable_disable_flag = false;
|
|
28
|
+
async function jsdom_init(enable = true, disable_disable = false) {
|
|
29
|
+
disable_disable_flag = disable_disable;
|
|
30
|
+
if (typeof document !== "undefined") return;
|
|
27
31
|
const { default: jsdom } = await import("jsdom");
|
|
28
32
|
const { JSDOM } = jsdom;
|
|
29
|
-
|
|
33
|
+
dom = new JSDOM(`<!DOCTYPE html><html><body></body></html>`, {
|
|
30
34
|
url: "http://localhost/"
|
|
31
35
|
// @warn 若缺少该行,则在mdit+build环境下,编译报错
|
|
32
36
|
});
|
|
37
|
+
if (enable) jsdom_enable();
|
|
38
|
+
}
|
|
39
|
+
function jsdom_enable() {
|
|
40
|
+
if (!dom) return;
|
|
33
41
|
global.Storage = dom.window.Storage;
|
|
34
42
|
global.window = dom.window;
|
|
35
43
|
global.history = dom.window.history;
|
|
@@ -47,6 +55,69 @@ async function jsdom_init() {
|
|
|
47
55
|
};
|
|
48
56
|
global.MutationObserver = dom.window.MutationObserver;
|
|
49
57
|
}
|
|
58
|
+
function jsdom_disable() {
|
|
59
|
+
if (disable_disable_flag) return;
|
|
60
|
+
if (!dom) return;
|
|
61
|
+
global.window = void 0;
|
|
62
|
+
global.history = void 0;
|
|
63
|
+
global.document = void 0;
|
|
64
|
+
}
|
|
65
|
+
const ABReg = {
|
|
66
|
+
/**
|
|
67
|
+
* AB块头部
|
|
68
|
+
*
|
|
69
|
+
* 例子:` > - > %%[d]:%% `
|
|
70
|
+
*
|
|
71
|
+
* - 前缀部分
|
|
72
|
+
* - $1: 前缀 | ` > - > ` | ((\s|>\s|-\s|\*\s|\+\s)*)
|
|
73
|
+
* - $2: 无用 | `>` | (\s|>\s|-\s|\*\s|\+\s)
|
|
74
|
+
* - 指令部分
|
|
75
|
+
* - $3: 无用 | `%%` | (%%)?
|
|
76
|
+
* - $4:无用 | `[header]` | (\[((?!toc)[0-9a-zA-Z].*)\])
|
|
77
|
+
* - $5:指令 | `header` | (?!toc)[0-9a-zA-Z].*)
|
|
78
|
+
* - $6: 无用 | `%%` | (%%)?
|
|
79
|
+
*
|
|
80
|
+
* 注意:
|
|
81
|
+
* - (?!\[) (?!\toc) 这种向后否定语句不作为一个匹配项
|
|
82
|
+
* - 允许 `%%` 和 `:` 的规则是V3新增的
|
|
83
|
+
* - 不允许 `::` 是避免与 dataview 的 inline property 冲突
|
|
84
|
+
*/
|
|
85
|
+
// 有前缀版本(给选择器用)
|
|
86
|
+
reg_header: /^((\s|>\s|-\s|\*\s|\+\s)*)(%%)?(\[((?!toc|TOC|\!|< )[\|\!#:;\(\)\s0-9a-zA-Z\u4e00-\u9fa5](?!.*::).*)\]):?(%%)?\s*$/,
|
|
87
|
+
// 可以用空`|`来解除首字符限制。(`|`注意:可以用来弄严格模式,`#`注意:建议后面空一格避免变成“标签”,`!`注意:别易误触发 `> [!note]`
|
|
88
|
+
reg_header_up: /^((\s|>\s|-\s|\*\s|\+\s)*)(%%)?(\[((?!toc|TOC|\!)< [\|\!#:;\(\)\s0-9a-zA-Z\u4e00-\u9fa5](?!.*::).*)\]):?(%%)?\s*$/,
|
|
89
|
+
// 向上检查标志的 头部选择器
|
|
90
|
+
reg_mdit_head: /^((\s|>\s|-\s|\*\s|\+\s)*)(::::*)\s?(.*)/,
|
|
91
|
+
reg_mdit_tail: /^((\s|>\s|-\s|\*\s|\+\s)*)(::::*)/,
|
|
92
|
+
reg_list: /^((\s|>\s|-\s|\*\s|\+\s)*)(-\s|\*\s|\+\s)(.*)/,
|
|
93
|
+
//: /^\s*(>\s)*-\s(.*)$/
|
|
94
|
+
reg_code: /^((\s|>\s|-\s|\*\s|\+\s)*)(````*|~~~~*)(.*)/,
|
|
95
|
+
//: /^\s*(>\s|-\s)*(````*|~~~~*)(.*)$/
|
|
96
|
+
reg_quote: /^((\s|>\s|-\s|\*\s|\+\s)*)(>\s)(.*)/,
|
|
97
|
+
// `- > ` 不匹配,要认为这种是列表
|
|
98
|
+
reg_heading: /^((\s|>\s|-\s|\*\s|\+\s)*)(\#+\s)(.*)/,
|
|
99
|
+
reg_table: /^((\s|>\s|-\s|\*\s|\+\s)*)(\|(.*)\|)/,
|
|
100
|
+
// 无前缀版本(给处理器用,处理器不需要处理前缀,前缀在选择器阶段已经被去除了)
|
|
101
|
+
reg_header_noprefix: /^((\s)*)(%%)?(\[((?!toc|TOC|\!|< )[\|\!#:;\(\)\s0-9a-zA-Z\u4e00-\u9fa5](?!.*::).*)\]):?(%%)?\s*$/,
|
|
102
|
+
reg_header_up_noprefix: /^((\s)*)(%%)?(\[((?!toc|TOC|\!)< [\|\!#:;\(\)\s0-9a-zA-Z\u4e00-\u9fa5](?!.*::).*)\]):?(%%)?\s*$/,
|
|
103
|
+
reg_mdit_head_noprefix: /^((\s)*)(::::*)\s?(.*)/,
|
|
104
|
+
reg_mdit_tail_noprefix: /^((\s)*)(::::*)/,
|
|
105
|
+
reg_list_noprefix: /^((\s)*)(-\s|\*\s|\+\s)(.*)/,
|
|
106
|
+
reg_code_noprefix: /^((\s)*)(````*|~~~~*)(.*)/,
|
|
107
|
+
reg_quote_noprefix: /^((\s)*)(>\s)(.*)/,
|
|
108
|
+
reg_heading_noprefix: /^((\s)*)(\#+\s)(.*)/,
|
|
109
|
+
reg_table_noprefix: /^((\s)*)(\|(.*)\|)/,
|
|
110
|
+
reg_emptyline_noprefix: /^\s*$/,
|
|
111
|
+
reg_indentline_noprefix: /^\s+?\S/,
|
|
112
|
+
inline_split: /\| |, |, |\. |。 |: |: /
|
|
113
|
+
// 内联切分。`|`或全角符号+一空格,半角符号+两空格 (后者由于空格压缩,若经历了重渲染可能有问题)
|
|
114
|
+
};
|
|
115
|
+
const ABCSetting = {
|
|
116
|
+
env: "obsidian",
|
|
117
|
+
// MarkdownPostProcessorContext类型, obsidian专用
|
|
118
|
+
mermaid: void 0
|
|
119
|
+
// obsidian专用,表示使用哪种方式渲染mermaid
|
|
120
|
+
};
|
|
50
121
|
const convert = (
|
|
51
122
|
// Note: overloads in JSDoc can’t yet use different `@template`s.
|
|
52
123
|
/**
|
|
@@ -305,27 +376,6 @@ class ABConvert {
|
|
|
305
376
|
}
|
|
306
377
|
}
|
|
307
378
|
}
|
|
308
|
-
const ABReg = {
|
|
309
|
-
// 向上检查标志的 头部选择器
|
|
310
|
-
reg_mdit_head: /^((\s|>\s|-\s|\*\s|\+\s)*)(::::*)\s?(.*)/,
|
|
311
|
-
//: /^\s*(>\s)*-\s(.*)$/
|
|
312
|
-
reg_code: /^((\s|>\s|-\s|\*\s|\+\s)*)(````*|~~~~*)(.*)/,
|
|
313
|
-
//: /^\s*(>\s|-\s)*(````*|~~~~*)(.*)$/
|
|
314
|
-
reg_quote: /^((\s|>\s|-\s|\*\s|\+\s)*)(>\s)(.*)/,
|
|
315
|
-
reg_list_noprefix: /^((\s)*)(-\s|\*\s|\+\s)(.*)/,
|
|
316
|
-
reg_code_noprefix: /^((\s)*)(````*|~~~~*)(.*)/,
|
|
317
|
-
reg_quote_noprefix: /^((\s)*)(>\s)(.*)/,
|
|
318
|
-
reg_heading_noprefix: /^((\s)*)(\#+\s)(.*)/,
|
|
319
|
-
reg_table_noprefix: /^((\s)*)(\|(.*)\|)/,
|
|
320
|
-
inline_split: /\| |, |, |\. |。 |: |: /
|
|
321
|
-
// 内联切分。`|`或全角符号+一空格,半角符号+两空格 (后者由于空格压缩,若经历了重渲染可能有问题)
|
|
322
|
-
};
|
|
323
|
-
const ABCSetting = {
|
|
324
|
-
env: "obsidian",
|
|
325
|
-
// MarkdownPostProcessorContext类型, obsidian专用
|
|
326
|
-
mermaid: void 0
|
|
327
|
-
// obsidian专用,表示使用哪种方式渲染mermaid
|
|
328
|
-
};
|
|
329
379
|
function autoABAlias(header, selectorName, content) {
|
|
330
380
|
if (!header.trimEnd().endsWith("|")) header = header + "|";
|
|
331
381
|
if (!header.trimStart().startsWith("|")) header = "|" + header;
|
|
@@ -2460,7 +2510,26 @@ ABConvert.factory({
|
|
|
2460
2510
|
sub_button.textContent = "折叠";
|
|
2461
2511
|
}
|
|
2462
2512
|
};
|
|
2463
|
-
|
|
2513
|
+
if (ABCSetting.env.startsWith("obsidian")) {
|
|
2514
|
+
sub_button.onclick = fn_fold;
|
|
2515
|
+
} else {
|
|
2516
|
+
sub_button.setAttribute("onclick", `
|
|
2517
|
+
const sub_button = this;
|
|
2518
|
+
const sub_el = this.nextElementSibling;
|
|
2519
|
+
|
|
2520
|
+
const is_hide = sub_el.getAttribute("is_hide")
|
|
2521
|
+
if (is_hide && is_hide=="false") {
|
|
2522
|
+
sub_el.setAttribute("is_hide", "true");
|
|
2523
|
+
sub_el.style.display = "none"
|
|
2524
|
+
sub_button.textContent = "展开"
|
|
2525
|
+
}
|
|
2526
|
+
else if(is_hide && is_hide=="true") {
|
|
2527
|
+
sub_el.setAttribute("is_hide", "false");
|
|
2528
|
+
sub_el.style.display = ""
|
|
2529
|
+
sub_button.textContent = "折叠"
|
|
2530
|
+
}
|
|
2531
|
+
`);
|
|
2532
|
+
}
|
|
2464
2533
|
mid_el.appendChild(sub_button);
|
|
2465
2534
|
mid_el.appendChild(sub_el);
|
|
2466
2535
|
const isListTable = sub_el.classList.contains("ab-list-table-parent");
|
|
@@ -17503,16 +17572,16 @@ const DomUtils = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProp
|
|
|
17503
17572
|
textContent,
|
|
17504
17573
|
uniqueSort
|
|
17505
17574
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
17506
|
-
function render(that,
|
|
17575
|
+
function render(that, dom2, options) {
|
|
17507
17576
|
if (!that)
|
|
17508
17577
|
return "";
|
|
17509
|
-
return that(
|
|
17578
|
+
return that(dom2 !== null && dom2 !== void 0 ? dom2 : that._root.children, null, void 0, options).toString();
|
|
17510
17579
|
}
|
|
17511
|
-
function isOptions(
|
|
17512
|
-
return typeof
|
|
17580
|
+
function isOptions(dom2, options) {
|
|
17581
|
+
return typeof dom2 === "object" && dom2 != null && !("length" in dom2) && !("type" in dom2);
|
|
17513
17582
|
}
|
|
17514
|
-
function html$1(
|
|
17515
|
-
const toRender = isOptions(
|
|
17583
|
+
function html$1(dom2, options) {
|
|
17584
|
+
const toRender = isOptions(dom2) ? (options = dom2, void 0) : dom2;
|
|
17516
17585
|
const opts = {
|
|
17517
17586
|
...defaultOpts$2,
|
|
17518
17587
|
...this === null || this === void 0 ? void 0 : this._options,
|
|
@@ -17520,9 +17589,9 @@ function html$1(dom, options) {
|
|
|
17520
17589
|
};
|
|
17521
17590
|
return render(this, toRender, opts);
|
|
17522
17591
|
}
|
|
17523
|
-
function xml(
|
|
17592
|
+
function xml(dom2) {
|
|
17524
17593
|
const options = { ...this._options, xmlMode: true };
|
|
17525
|
-
return render(this,
|
|
17594
|
+
return render(this, dom2, options);
|
|
17526
17595
|
}
|
|
17527
17596
|
function text$1(elements) {
|
|
17528
17597
|
const elems = elements ? elements : this ? this.root() : [];
|
|
@@ -17612,8 +17681,8 @@ function domEach(array, fn) {
|
|
|
17612
17681
|
fn(array[i], i);
|
|
17613
17682
|
return array;
|
|
17614
17683
|
}
|
|
17615
|
-
function cloneDom(
|
|
17616
|
-
const clone2 = "length" in
|
|
17684
|
+
function cloneDom(dom2) {
|
|
17685
|
+
const clone2 = "length" in dom2 ? Array.prototype.map.call(dom2, (el) => cloneNode(el, true)) : [cloneNode(dom2, true)];
|
|
17617
17686
|
const root2 = new Document$1(clone2);
|
|
17618
17687
|
clone2.forEach((node) => {
|
|
17619
17688
|
node.parent = root2;
|
|
@@ -19844,8 +19913,8 @@ function _insert(concatenator) {
|
|
|
19844
19913
|
if (!hasChildren(el))
|
|
19845
19914
|
return;
|
|
19846
19915
|
const domSrc = typeof elems[0] === "function" ? elems[0].call(el, i, this._render(el.children)) : elems;
|
|
19847
|
-
const
|
|
19848
|
-
concatenator(
|
|
19916
|
+
const dom2 = this._makeDomArray(domSrc, i < lastIdx);
|
|
19917
|
+
concatenator(dom2, el.children, el);
|
|
19849
19918
|
});
|
|
19850
19919
|
};
|
|
19851
19920
|
}
|
|
@@ -19899,11 +19968,11 @@ function prependTo(target) {
|
|
|
19899
19968
|
prependTarget.prepend(this);
|
|
19900
19969
|
return this;
|
|
19901
19970
|
}
|
|
19902
|
-
const append = _insert((
|
|
19903
|
-
uniqueSplice(children2, children2.length, 0,
|
|
19971
|
+
const append = _insert((dom2, children2, parent2) => {
|
|
19972
|
+
uniqueSplice(children2, children2.length, 0, dom2, parent2);
|
|
19904
19973
|
});
|
|
19905
|
-
const prepend = _insert((
|
|
19906
|
-
uniqueSplice(children2, 0, 0,
|
|
19974
|
+
const prepend = _insert((dom2, children2, parent2) => {
|
|
19975
|
+
uniqueSplice(children2, 0, 0, dom2, parent2);
|
|
19907
19976
|
});
|
|
19908
19977
|
function _wrap(insert) {
|
|
19909
19978
|
return function(wrapper) {
|
|
@@ -19988,8 +20057,8 @@ function after(...elems) {
|
|
|
19988
20057
|
if (index2 < 0)
|
|
19989
20058
|
return;
|
|
19990
20059
|
const domSrc = typeof elems[0] === "function" ? elems[0].call(el, i, this._render(el.children)) : elems;
|
|
19991
|
-
const
|
|
19992
|
-
uniqueSplice(siblings2, index2 + 1, 0,
|
|
20060
|
+
const dom2 = this._makeDomArray(domSrc, i < lastIdx);
|
|
20061
|
+
uniqueSplice(siblings2, index2 + 1, 0, dom2, parent2);
|
|
19993
20062
|
});
|
|
19994
20063
|
}
|
|
19995
20064
|
function insertAfter(target) {
|
|
@@ -20025,8 +20094,8 @@ function before(...elems) {
|
|
|
20025
20094
|
if (index2 < 0)
|
|
20026
20095
|
return;
|
|
20027
20096
|
const domSrc = typeof elems[0] === "function" ? elems[0].call(el, i, this._render(el.children)) : elems;
|
|
20028
|
-
const
|
|
20029
|
-
uniqueSplice(siblings2, index2, 0,
|
|
20097
|
+
const dom2 = this._makeDomArray(domSrc, i < lastIdx);
|
|
20098
|
+
uniqueSplice(siblings2, index2, 0, dom2, parent2);
|
|
20030
20099
|
});
|
|
20031
20100
|
}
|
|
20032
20101
|
function insertBefore(target) {
|
|
@@ -20064,11 +20133,11 @@ function replaceWith(content) {
|
|
|
20064
20133
|
}
|
|
20065
20134
|
const siblings2 = parent2.children;
|
|
20066
20135
|
const cont = typeof content === "function" ? content.call(el, i, el) : content;
|
|
20067
|
-
const
|
|
20068
|
-
update(
|
|
20136
|
+
const dom2 = this._makeDomArray(cont);
|
|
20137
|
+
update(dom2, null);
|
|
20069
20138
|
const index2 = siblings2.indexOf(el);
|
|
20070
|
-
uniqueSplice(siblings2, index2, 1,
|
|
20071
|
-
if (!
|
|
20139
|
+
uniqueSplice(siblings2, index2, 1, dom2, parent2);
|
|
20140
|
+
if (!dom2.includes(el)) {
|
|
20072
20141
|
el.parent = el.prev = el.next = null;
|
|
20073
20142
|
}
|
|
20074
20143
|
});
|
|
@@ -20304,8 +20373,8 @@ function getLoad(parse2, render2) {
|
|
|
20304
20373
|
_parse(content2, options2, isDocument3, context) {
|
|
20305
20374
|
return parse2(content2, options2, isDocument3, context);
|
|
20306
20375
|
}
|
|
20307
|
-
_render(
|
|
20308
|
-
return render2(
|
|
20376
|
+
_render(dom2) {
|
|
20377
|
+
return render2(dom2, this.options);
|
|
20309
20378
|
}
|
|
20310
20379
|
}
|
|
20311
20380
|
function initialize(selector, context, root2 = initialRoot, opts) {
|
|
@@ -28492,8 +28561,8 @@ function parseWithParse5(content, options, isDocument2, context) {
|
|
|
28492
28561
|
return isDocument2 ? parse$2(content, opts) : parseFragment(context, content, opts);
|
|
28493
28562
|
}
|
|
28494
28563
|
const renderOpts = { treeAdapter: adapter };
|
|
28495
|
-
function renderWithParse5(
|
|
28496
|
-
const nodes = "length" in
|
|
28564
|
+
function renderWithParse5(dom2) {
|
|
28565
|
+
const nodes = "length" in dom2 ? dom2 : [dom2];
|
|
28497
28566
|
for (let index2 = 0; index2 < nodes.length; index2 += 1) {
|
|
28498
28567
|
const node = nodes[index2];
|
|
28499
28568
|
if (isDocument$1(node)) {
|
|
@@ -29745,7 +29814,7 @@ function parseDocument$1(data2, options) {
|
|
|
29745
29814
|
return handler.root;
|
|
29746
29815
|
}
|
|
29747
29816
|
const parse$1 = getParse((content, options, isDocument2, context) => options.xmlMode || options._useHtmlParser2 ? parseDocument$1(content, options) : parseWithParse5(content, options, isDocument2, context));
|
|
29748
|
-
const load = getLoad(parse$1, (
|
|
29817
|
+
const load = getLoad(parse$1, (dom2, options) => options.xmlMode || options._useHtmlParser2 ? render$1(dom2, options) : renderWithParse5(dom2));
|
|
29749
29818
|
load([]);
|
|
29750
29819
|
const defaultSelectorRules = {
|
|
29751
29820
|
"div,p": ({ $node }) => ({
|
|
@@ -49621,7 +49690,7 @@ const remark_anyblock_render_codeblock = () => {
|
|
|
49621
49690
|
if (typeof document == "undefined") return;
|
|
49622
49691
|
return (tree, _file) => {
|
|
49623
49692
|
visit$1(tree, "code", (node, index2, parent2) => {
|
|
49624
|
-
if (node.lang.toLowerCase() != "anyblock") return;
|
|
49693
|
+
if (typeof node.lang != "string" || node.lang.toLowerCase() != "anyblock") return;
|
|
49625
49694
|
if (!parent2 || !index2) return;
|
|
49626
49695
|
const lines = node.value.split("\n");
|
|
49627
49696
|
const head = lines.shift();
|
|
@@ -49651,7 +49720,7 @@ const remark_anyblock_render_codeblock = () => {
|
|
|
49651
49720
|
el_child.innerHTML = result;
|
|
49652
49721
|
});
|
|
49653
49722
|
}
|
|
49654
|
-
const
|
|
49723
|
+
const quartz_transformer_anyblock = () => {
|
|
49655
49724
|
return {
|
|
49656
49725
|
name: "AnyBlock",
|
|
49657
49726
|
markdownPlugins(_ctx) {
|
|
@@ -49667,8 +49736,11 @@ const transformer_anyblock = () => {
|
|
|
49667
49736
|
};
|
|
49668
49737
|
};
|
|
49669
49738
|
exports.ABConvertManager = ABConvertManager;
|
|
49739
|
+
exports.ABReg = ABReg;
|
|
49670
49740
|
exports.abConvertEvent = abConvertEvent;
|
|
49741
|
+
exports.jsdom_disable = jsdom_disable;
|
|
49742
|
+
exports.jsdom_enable = jsdom_enable;
|
|
49671
49743
|
exports.jsdom_init = jsdom_init;
|
|
49672
49744
|
exports.remark_anyblock_render_codeblock = remark_anyblock_render_codeblock;
|
|
49673
|
-
exports.transformer_anyblock =
|
|
49745
|
+
exports.transformer_anyblock = quartz_transformer_anyblock;
|
|
49674
49746
|
//# sourceMappingURL=remark-any-block.cjs.map
|
package/dist/remark-any-block.js
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
import MarkdownIt from "markdown-it";
|
|
2
|
-
|
|
2
|
+
let dom = null;
|
|
3
|
+
let disable_disable_flag = false;
|
|
4
|
+
async function jsdom_init(enable = true, disable_disable = false) {
|
|
5
|
+
disable_disable_flag = disable_disable;
|
|
6
|
+
if (typeof document !== "undefined") return;
|
|
3
7
|
const { default: jsdom } = await import("jsdom");
|
|
4
8
|
const { JSDOM } = jsdom;
|
|
5
|
-
|
|
9
|
+
dom = new JSDOM(`<!DOCTYPE html><html><body></body></html>`, {
|
|
6
10
|
url: "http://localhost/"
|
|
7
11
|
// @warn 若缺少该行,则在mdit+build环境下,编译报错
|
|
8
12
|
});
|
|
13
|
+
if (enable) jsdom_enable();
|
|
14
|
+
}
|
|
15
|
+
function jsdom_enable() {
|
|
16
|
+
if (!dom) return;
|
|
9
17
|
global.Storage = dom.window.Storage;
|
|
10
18
|
global.window = dom.window;
|
|
11
19
|
global.history = dom.window.history;
|
|
@@ -23,6 +31,69 @@ async function jsdom_init() {
|
|
|
23
31
|
};
|
|
24
32
|
global.MutationObserver = dom.window.MutationObserver;
|
|
25
33
|
}
|
|
34
|
+
function jsdom_disable() {
|
|
35
|
+
if (disable_disable_flag) return;
|
|
36
|
+
if (!dom) return;
|
|
37
|
+
global.window = void 0;
|
|
38
|
+
global.history = void 0;
|
|
39
|
+
global.document = void 0;
|
|
40
|
+
}
|
|
41
|
+
const ABReg = {
|
|
42
|
+
/**
|
|
43
|
+
* AB块头部
|
|
44
|
+
*
|
|
45
|
+
* 例子:` > - > %%[d]:%% `
|
|
46
|
+
*
|
|
47
|
+
* - 前缀部分
|
|
48
|
+
* - $1: 前缀 | ` > - > ` | ((\s|>\s|-\s|\*\s|\+\s)*)
|
|
49
|
+
* - $2: 无用 | `>` | (\s|>\s|-\s|\*\s|\+\s)
|
|
50
|
+
* - 指令部分
|
|
51
|
+
* - $3: 无用 | `%%` | (%%)?
|
|
52
|
+
* - $4:无用 | `[header]` | (\[((?!toc)[0-9a-zA-Z].*)\])
|
|
53
|
+
* - $5:指令 | `header` | (?!toc)[0-9a-zA-Z].*)
|
|
54
|
+
* - $6: 无用 | `%%` | (%%)?
|
|
55
|
+
*
|
|
56
|
+
* 注意:
|
|
57
|
+
* - (?!\[) (?!\toc) 这种向后否定语句不作为一个匹配项
|
|
58
|
+
* - 允许 `%%` 和 `:` 的规则是V3新增的
|
|
59
|
+
* - 不允许 `::` 是避免与 dataview 的 inline property 冲突
|
|
60
|
+
*/
|
|
61
|
+
// 有前缀版本(给选择器用)
|
|
62
|
+
reg_header: /^((\s|>\s|-\s|\*\s|\+\s)*)(%%)?(\[((?!toc|TOC|\!|< )[\|\!#:;\(\)\s0-9a-zA-Z\u4e00-\u9fa5](?!.*::).*)\]):?(%%)?\s*$/,
|
|
63
|
+
// 可以用空`|`来解除首字符限制。(`|`注意:可以用来弄严格模式,`#`注意:建议后面空一格避免变成“标签”,`!`注意:别易误触发 `> [!note]`
|
|
64
|
+
reg_header_up: /^((\s|>\s|-\s|\*\s|\+\s)*)(%%)?(\[((?!toc|TOC|\!)< [\|\!#:;\(\)\s0-9a-zA-Z\u4e00-\u9fa5](?!.*::).*)\]):?(%%)?\s*$/,
|
|
65
|
+
// 向上检查标志的 头部选择器
|
|
66
|
+
reg_mdit_head: /^((\s|>\s|-\s|\*\s|\+\s)*)(::::*)\s?(.*)/,
|
|
67
|
+
reg_mdit_tail: /^((\s|>\s|-\s|\*\s|\+\s)*)(::::*)/,
|
|
68
|
+
reg_list: /^((\s|>\s|-\s|\*\s|\+\s)*)(-\s|\*\s|\+\s)(.*)/,
|
|
69
|
+
//: /^\s*(>\s)*-\s(.*)$/
|
|
70
|
+
reg_code: /^((\s|>\s|-\s|\*\s|\+\s)*)(````*|~~~~*)(.*)/,
|
|
71
|
+
//: /^\s*(>\s|-\s)*(````*|~~~~*)(.*)$/
|
|
72
|
+
reg_quote: /^((\s|>\s|-\s|\*\s|\+\s)*)(>\s)(.*)/,
|
|
73
|
+
// `- > ` 不匹配,要认为这种是列表
|
|
74
|
+
reg_heading: /^((\s|>\s|-\s|\*\s|\+\s)*)(\#+\s)(.*)/,
|
|
75
|
+
reg_table: /^((\s|>\s|-\s|\*\s|\+\s)*)(\|(.*)\|)/,
|
|
76
|
+
// 无前缀版本(给处理器用,处理器不需要处理前缀,前缀在选择器阶段已经被去除了)
|
|
77
|
+
reg_header_noprefix: /^((\s)*)(%%)?(\[((?!toc|TOC|\!|< )[\|\!#:;\(\)\s0-9a-zA-Z\u4e00-\u9fa5](?!.*::).*)\]):?(%%)?\s*$/,
|
|
78
|
+
reg_header_up_noprefix: /^((\s)*)(%%)?(\[((?!toc|TOC|\!)< [\|\!#:;\(\)\s0-9a-zA-Z\u4e00-\u9fa5](?!.*::).*)\]):?(%%)?\s*$/,
|
|
79
|
+
reg_mdit_head_noprefix: /^((\s)*)(::::*)\s?(.*)/,
|
|
80
|
+
reg_mdit_tail_noprefix: /^((\s)*)(::::*)/,
|
|
81
|
+
reg_list_noprefix: /^((\s)*)(-\s|\*\s|\+\s)(.*)/,
|
|
82
|
+
reg_code_noprefix: /^((\s)*)(````*|~~~~*)(.*)/,
|
|
83
|
+
reg_quote_noprefix: /^((\s)*)(>\s)(.*)/,
|
|
84
|
+
reg_heading_noprefix: /^((\s)*)(\#+\s)(.*)/,
|
|
85
|
+
reg_table_noprefix: /^((\s)*)(\|(.*)\|)/,
|
|
86
|
+
reg_emptyline_noprefix: /^\s*$/,
|
|
87
|
+
reg_indentline_noprefix: /^\s+?\S/,
|
|
88
|
+
inline_split: /\| |, |, |\. |。 |: |: /
|
|
89
|
+
// 内联切分。`|`或全角符号+一空格,半角符号+两空格 (后者由于空格压缩,若经历了重渲染可能有问题)
|
|
90
|
+
};
|
|
91
|
+
const ABCSetting = {
|
|
92
|
+
env: "obsidian",
|
|
93
|
+
// MarkdownPostProcessorContext类型, obsidian专用
|
|
94
|
+
mermaid: void 0
|
|
95
|
+
// obsidian专用,表示使用哪种方式渲染mermaid
|
|
96
|
+
};
|
|
26
97
|
const convert = (
|
|
27
98
|
// Note: overloads in JSDoc can’t yet use different `@template`s.
|
|
28
99
|
/**
|
|
@@ -281,27 +352,6 @@ class ABConvert {
|
|
|
281
352
|
}
|
|
282
353
|
}
|
|
283
354
|
}
|
|
284
|
-
const ABReg = {
|
|
285
|
-
// 向上检查标志的 头部选择器
|
|
286
|
-
reg_mdit_head: /^((\s|>\s|-\s|\*\s|\+\s)*)(::::*)\s?(.*)/,
|
|
287
|
-
//: /^\s*(>\s)*-\s(.*)$/
|
|
288
|
-
reg_code: /^((\s|>\s|-\s|\*\s|\+\s)*)(````*|~~~~*)(.*)/,
|
|
289
|
-
//: /^\s*(>\s|-\s)*(````*|~~~~*)(.*)$/
|
|
290
|
-
reg_quote: /^((\s|>\s|-\s|\*\s|\+\s)*)(>\s)(.*)/,
|
|
291
|
-
reg_list_noprefix: /^((\s)*)(-\s|\*\s|\+\s)(.*)/,
|
|
292
|
-
reg_code_noprefix: /^((\s)*)(````*|~~~~*)(.*)/,
|
|
293
|
-
reg_quote_noprefix: /^((\s)*)(>\s)(.*)/,
|
|
294
|
-
reg_heading_noprefix: /^((\s)*)(\#+\s)(.*)/,
|
|
295
|
-
reg_table_noprefix: /^((\s)*)(\|(.*)\|)/,
|
|
296
|
-
inline_split: /\| |, |, |\. |。 |: |: /
|
|
297
|
-
// 内联切分。`|`或全角符号+一空格,半角符号+两空格 (后者由于空格压缩,若经历了重渲染可能有问题)
|
|
298
|
-
};
|
|
299
|
-
const ABCSetting = {
|
|
300
|
-
env: "obsidian",
|
|
301
|
-
// MarkdownPostProcessorContext类型, obsidian专用
|
|
302
|
-
mermaid: void 0
|
|
303
|
-
// obsidian专用,表示使用哪种方式渲染mermaid
|
|
304
|
-
};
|
|
305
355
|
function autoABAlias(header, selectorName, content) {
|
|
306
356
|
if (!header.trimEnd().endsWith("|")) header = header + "|";
|
|
307
357
|
if (!header.trimStart().startsWith("|")) header = "|" + header;
|
|
@@ -2436,7 +2486,26 @@ ABConvert.factory({
|
|
|
2436
2486
|
sub_button.textContent = "折叠";
|
|
2437
2487
|
}
|
|
2438
2488
|
};
|
|
2439
|
-
|
|
2489
|
+
if (ABCSetting.env.startsWith("obsidian")) {
|
|
2490
|
+
sub_button.onclick = fn_fold;
|
|
2491
|
+
} else {
|
|
2492
|
+
sub_button.setAttribute("onclick", `
|
|
2493
|
+
const sub_button = this;
|
|
2494
|
+
const sub_el = this.nextElementSibling;
|
|
2495
|
+
|
|
2496
|
+
const is_hide = sub_el.getAttribute("is_hide")
|
|
2497
|
+
if (is_hide && is_hide=="false") {
|
|
2498
|
+
sub_el.setAttribute("is_hide", "true");
|
|
2499
|
+
sub_el.style.display = "none"
|
|
2500
|
+
sub_button.textContent = "展开"
|
|
2501
|
+
}
|
|
2502
|
+
else if(is_hide && is_hide=="true") {
|
|
2503
|
+
sub_el.setAttribute("is_hide", "false");
|
|
2504
|
+
sub_el.style.display = ""
|
|
2505
|
+
sub_button.textContent = "折叠"
|
|
2506
|
+
}
|
|
2507
|
+
`);
|
|
2508
|
+
}
|
|
2440
2509
|
mid_el.appendChild(sub_button);
|
|
2441
2510
|
mid_el.appendChild(sub_el);
|
|
2442
2511
|
const isListTable = sub_el.classList.contains("ab-list-table-parent");
|
|
@@ -17479,16 +17548,16 @@ const DomUtils = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProp
|
|
|
17479
17548
|
textContent,
|
|
17480
17549
|
uniqueSort
|
|
17481
17550
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
17482
|
-
function render(that,
|
|
17551
|
+
function render(that, dom2, options) {
|
|
17483
17552
|
if (!that)
|
|
17484
17553
|
return "";
|
|
17485
|
-
return that(
|
|
17554
|
+
return that(dom2 !== null && dom2 !== void 0 ? dom2 : that._root.children, null, void 0, options).toString();
|
|
17486
17555
|
}
|
|
17487
|
-
function isOptions(
|
|
17488
|
-
return typeof
|
|
17556
|
+
function isOptions(dom2, options) {
|
|
17557
|
+
return typeof dom2 === "object" && dom2 != null && !("length" in dom2) && !("type" in dom2);
|
|
17489
17558
|
}
|
|
17490
|
-
function html$1(
|
|
17491
|
-
const toRender = isOptions(
|
|
17559
|
+
function html$1(dom2, options) {
|
|
17560
|
+
const toRender = isOptions(dom2) ? (options = dom2, void 0) : dom2;
|
|
17492
17561
|
const opts = {
|
|
17493
17562
|
...defaultOpts$2,
|
|
17494
17563
|
...this === null || this === void 0 ? void 0 : this._options,
|
|
@@ -17496,9 +17565,9 @@ function html$1(dom, options) {
|
|
|
17496
17565
|
};
|
|
17497
17566
|
return render(this, toRender, opts);
|
|
17498
17567
|
}
|
|
17499
|
-
function xml(
|
|
17568
|
+
function xml(dom2) {
|
|
17500
17569
|
const options = { ...this._options, xmlMode: true };
|
|
17501
|
-
return render(this,
|
|
17570
|
+
return render(this, dom2, options);
|
|
17502
17571
|
}
|
|
17503
17572
|
function text$1(elements) {
|
|
17504
17573
|
const elems = elements ? elements : this ? this.root() : [];
|
|
@@ -17588,8 +17657,8 @@ function domEach(array, fn) {
|
|
|
17588
17657
|
fn(array[i], i);
|
|
17589
17658
|
return array;
|
|
17590
17659
|
}
|
|
17591
|
-
function cloneDom(
|
|
17592
|
-
const clone2 = "length" in
|
|
17660
|
+
function cloneDom(dom2) {
|
|
17661
|
+
const clone2 = "length" in dom2 ? Array.prototype.map.call(dom2, (el) => cloneNode(el, true)) : [cloneNode(dom2, true)];
|
|
17593
17662
|
const root2 = new Document$1(clone2);
|
|
17594
17663
|
clone2.forEach((node) => {
|
|
17595
17664
|
node.parent = root2;
|
|
@@ -19820,8 +19889,8 @@ function _insert(concatenator) {
|
|
|
19820
19889
|
if (!hasChildren(el))
|
|
19821
19890
|
return;
|
|
19822
19891
|
const domSrc = typeof elems[0] === "function" ? elems[0].call(el, i, this._render(el.children)) : elems;
|
|
19823
|
-
const
|
|
19824
|
-
concatenator(
|
|
19892
|
+
const dom2 = this._makeDomArray(domSrc, i < lastIdx);
|
|
19893
|
+
concatenator(dom2, el.children, el);
|
|
19825
19894
|
});
|
|
19826
19895
|
};
|
|
19827
19896
|
}
|
|
@@ -19875,11 +19944,11 @@ function prependTo(target) {
|
|
|
19875
19944
|
prependTarget.prepend(this);
|
|
19876
19945
|
return this;
|
|
19877
19946
|
}
|
|
19878
|
-
const append = _insert((
|
|
19879
|
-
uniqueSplice(children2, children2.length, 0,
|
|
19947
|
+
const append = _insert((dom2, children2, parent2) => {
|
|
19948
|
+
uniqueSplice(children2, children2.length, 0, dom2, parent2);
|
|
19880
19949
|
});
|
|
19881
|
-
const prepend = _insert((
|
|
19882
|
-
uniqueSplice(children2, 0, 0,
|
|
19950
|
+
const prepend = _insert((dom2, children2, parent2) => {
|
|
19951
|
+
uniqueSplice(children2, 0, 0, dom2, parent2);
|
|
19883
19952
|
});
|
|
19884
19953
|
function _wrap(insert) {
|
|
19885
19954
|
return function(wrapper) {
|
|
@@ -19964,8 +20033,8 @@ function after(...elems) {
|
|
|
19964
20033
|
if (index2 < 0)
|
|
19965
20034
|
return;
|
|
19966
20035
|
const domSrc = typeof elems[0] === "function" ? elems[0].call(el, i, this._render(el.children)) : elems;
|
|
19967
|
-
const
|
|
19968
|
-
uniqueSplice(siblings2, index2 + 1, 0,
|
|
20036
|
+
const dom2 = this._makeDomArray(domSrc, i < lastIdx);
|
|
20037
|
+
uniqueSplice(siblings2, index2 + 1, 0, dom2, parent2);
|
|
19969
20038
|
});
|
|
19970
20039
|
}
|
|
19971
20040
|
function insertAfter(target) {
|
|
@@ -20001,8 +20070,8 @@ function before(...elems) {
|
|
|
20001
20070
|
if (index2 < 0)
|
|
20002
20071
|
return;
|
|
20003
20072
|
const domSrc = typeof elems[0] === "function" ? elems[0].call(el, i, this._render(el.children)) : elems;
|
|
20004
|
-
const
|
|
20005
|
-
uniqueSplice(siblings2, index2, 0,
|
|
20073
|
+
const dom2 = this._makeDomArray(domSrc, i < lastIdx);
|
|
20074
|
+
uniqueSplice(siblings2, index2, 0, dom2, parent2);
|
|
20006
20075
|
});
|
|
20007
20076
|
}
|
|
20008
20077
|
function insertBefore(target) {
|
|
@@ -20040,11 +20109,11 @@ function replaceWith(content) {
|
|
|
20040
20109
|
}
|
|
20041
20110
|
const siblings2 = parent2.children;
|
|
20042
20111
|
const cont = typeof content === "function" ? content.call(el, i, el) : content;
|
|
20043
|
-
const
|
|
20044
|
-
update(
|
|
20112
|
+
const dom2 = this._makeDomArray(cont);
|
|
20113
|
+
update(dom2, null);
|
|
20045
20114
|
const index2 = siblings2.indexOf(el);
|
|
20046
|
-
uniqueSplice(siblings2, index2, 1,
|
|
20047
|
-
if (!
|
|
20115
|
+
uniqueSplice(siblings2, index2, 1, dom2, parent2);
|
|
20116
|
+
if (!dom2.includes(el)) {
|
|
20048
20117
|
el.parent = el.prev = el.next = null;
|
|
20049
20118
|
}
|
|
20050
20119
|
});
|
|
@@ -20280,8 +20349,8 @@ function getLoad(parse2, render2) {
|
|
|
20280
20349
|
_parse(content2, options2, isDocument3, context) {
|
|
20281
20350
|
return parse2(content2, options2, isDocument3, context);
|
|
20282
20351
|
}
|
|
20283
|
-
_render(
|
|
20284
|
-
return render2(
|
|
20352
|
+
_render(dom2) {
|
|
20353
|
+
return render2(dom2, this.options);
|
|
20285
20354
|
}
|
|
20286
20355
|
}
|
|
20287
20356
|
function initialize(selector, context, root2 = initialRoot, opts) {
|
|
@@ -28468,8 +28537,8 @@ function parseWithParse5(content, options, isDocument2, context) {
|
|
|
28468
28537
|
return isDocument2 ? parse$2(content, opts) : parseFragment(context, content, opts);
|
|
28469
28538
|
}
|
|
28470
28539
|
const renderOpts = { treeAdapter: adapter };
|
|
28471
|
-
function renderWithParse5(
|
|
28472
|
-
const nodes = "length" in
|
|
28540
|
+
function renderWithParse5(dom2) {
|
|
28541
|
+
const nodes = "length" in dom2 ? dom2 : [dom2];
|
|
28473
28542
|
for (let index2 = 0; index2 < nodes.length; index2 += 1) {
|
|
28474
28543
|
const node = nodes[index2];
|
|
28475
28544
|
if (isDocument$1(node)) {
|
|
@@ -29721,7 +29790,7 @@ function parseDocument$1(data2, options) {
|
|
|
29721
29790
|
return handler.root;
|
|
29722
29791
|
}
|
|
29723
29792
|
const parse$1 = getParse((content, options, isDocument2, context) => options.xmlMode || options._useHtmlParser2 ? parseDocument$1(content, options) : parseWithParse5(content, options, isDocument2, context));
|
|
29724
|
-
const load = getLoad(parse$1, (
|
|
29793
|
+
const load = getLoad(parse$1, (dom2, options) => options.xmlMode || options._useHtmlParser2 ? render$1(dom2, options) : renderWithParse5(dom2));
|
|
29725
29794
|
load([]);
|
|
29726
29795
|
const defaultSelectorRules = {
|
|
29727
29796
|
"div,p": ({ $node }) => ({
|
|
@@ -49597,7 +49666,7 @@ const remark_anyblock_render_codeblock = () => {
|
|
|
49597
49666
|
if (typeof document == "undefined") return;
|
|
49598
49667
|
return (tree, _file) => {
|
|
49599
49668
|
visit$1(tree, "code", (node, index2, parent2) => {
|
|
49600
|
-
if (node.lang.toLowerCase() != "anyblock") return;
|
|
49669
|
+
if (typeof node.lang != "string" || node.lang.toLowerCase() != "anyblock") return;
|
|
49601
49670
|
if (!parent2 || !index2) return;
|
|
49602
49671
|
const lines = node.value.split("\n");
|
|
49603
49672
|
const head = lines.shift();
|
|
@@ -49627,7 +49696,7 @@ const remark_anyblock_render_codeblock = () => {
|
|
|
49627
49696
|
el_child.innerHTML = result;
|
|
49628
49697
|
});
|
|
49629
49698
|
}
|
|
49630
|
-
const
|
|
49699
|
+
const quartz_transformer_anyblock = () => {
|
|
49631
49700
|
return {
|
|
49632
49701
|
name: "AnyBlock",
|
|
49633
49702
|
markdownPlugins(_ctx) {
|
|
@@ -49644,9 +49713,12 @@ const transformer_anyblock = () => {
|
|
|
49644
49713
|
};
|
|
49645
49714
|
export {
|
|
49646
49715
|
ABConvertManager,
|
|
49716
|
+
ABReg,
|
|
49647
49717
|
abConvertEvent,
|
|
49718
|
+
jsdom_disable,
|
|
49719
|
+
jsdom_enable,
|
|
49648
49720
|
jsdom_init,
|
|
49649
49721
|
remark_anyblock_render_codeblock,
|
|
49650
|
-
transformer_anyblock
|
|
49722
|
+
quartz_transformer_anyblock as transformer_anyblock
|
|
49651
49723
|
};
|
|
49652
49724
|
//# sourceMappingURL=remark-any-block.js.map
|
package/index.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// JsDom。仅用于提供document对象支持 (如果Ob环境中则不需要,用ob自带document对象的)
|
|
2
|
-
export
|
|
2
|
+
export * from './jsdom_init'
|
|
3
|
+
export { ABReg } from '../ABConverter/ABReg'
|
|
3
4
|
export {
|
|
4
|
-
transformer_anyblock,
|
|
5
|
+
quartz_transformer_anyblock as transformer_anyblock,
|
|
5
6
|
// remark_anyblock_to_codeblock, // 取消注释则用库的地方会报错找不到 document
|
|
6
7
|
remark_anyblock_render_codeblock,
|
|
7
8
|
} from './anyblock'
|
package/jsdom_init.ts
CHANGED
|
@@ -6,12 +6,27 @@
|
|
|
6
6
|
|
|
7
7
|
// import jsdom from "jsdom"
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
let dom: any = null // 缓存 jsdom 实例
|
|
10
|
+
let disable_disable_flag: boolean = false // 禁止禁用
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @param enable 默认开启
|
|
14
|
+
* @param disable_disable 禁止禁用
|
|
15
|
+
*/
|
|
16
|
+
export async function jsdom_init(enable: boolean = true, disable_disable: boolean = false) {
|
|
17
|
+
disable_disable_flag = disable_disable
|
|
18
|
+
if (typeof document !== "undefined") return // 客户端环境,无需 jsdom 环境,同时也避免误卸载 document 环境
|
|
10
19
|
const { default: jsdom } = await import('jsdom') // 废弃,要同步,避免docuemnt初始化不及时
|
|
11
20
|
const { JSDOM } = jsdom
|
|
12
|
-
|
|
21
|
+
dom = new JSDOM(`<!DOCTYPE html><html><body></body></html>`, {
|
|
13
22
|
url: 'http://localhost/', // @warn 若缺少该行,则在mdit+build环境下,编译报错
|
|
14
|
-
})
|
|
23
|
+
})
|
|
24
|
+
if (enable) jsdom_enable()
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/// 启用 jsdom 环境
|
|
28
|
+
export function jsdom_enable() {
|
|
29
|
+
if (!dom) return // console.error("jsdom_enable failed: please run jsdom_init first.") // 允许客户端中运行,不使用jsdom
|
|
15
30
|
global.Storage = dom.window.Storage;
|
|
16
31
|
global.window = dom.window as any
|
|
17
32
|
global.history = dom.window.history // @warn 若缺少该行,则在mdit+build环境下,编译报错:ReferenceError: history is not defined
|
|
@@ -28,3 +43,12 @@ export async function jsdom_init() {
|
|
|
28
43
|
dom.window.scrollTo = ()=>{} // @warn 若缺少该行,编译警告:Error: Not implemented: window.scrollTo
|
|
29
44
|
global.MutationObserver = dom.window.MutationObserver
|
|
30
45
|
}
|
|
46
|
+
|
|
47
|
+
/// 禁用 jsdom 环境
|
|
48
|
+
export function jsdom_disable() {
|
|
49
|
+
if (disable_disable_flag) return
|
|
50
|
+
if (!dom) return // console.error("jsdom_disable failed: please run jsdom_init first.") // 允许客户端中运行,不使用jsdom
|
|
51
|
+
global.window = undefined
|
|
52
|
+
global.history = undefined
|
|
53
|
+
global.document = undefined
|
|
54
|
+
}
|
package/package.json
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@anyblock/remark-any-block",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "You can flexibility to create a 'Block' by many means. It also provides many useful features, like `list to table`.",
|
|
5
|
-
"types": "@types/index_remark.d.ts",
|
|
6
|
-
"type": "module",
|
|
7
|
-
"main": "dist/remark-any-block.cjs",
|
|
8
|
-
"exports": {
|
|
9
|
-
".": {
|
|
10
|
-
"import": "./dist/remark-any-block.js",
|
|
11
|
-
"require": "./dist/remark-any-block.cjs"
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
"publishConfig": {
|
|
15
|
-
"access": "public"
|
|
16
|
-
},
|
|
17
|
-
"scripts": {
|
|
18
|
-
"test": "echo \"Error: no test specified\" && exit 1",
|
|
19
|
-
"build": "pnpm build_vite",
|
|
20
|
-
"build_vite": "pnpm copy_abc_style && vite build",
|
|
21
|
-
"prepublishOnly": "pnpm build",
|
|
22
|
-
"copy_abc_style": "copyfiles --flat ../../src/ABConverter/style/styles.css ./"
|
|
23
|
-
},
|
|
24
|
-
"keywords": [],
|
|
25
|
-
"author": "",
|
|
26
|
-
"license": "GNU Affero General Public License v3.0",
|
|
27
|
-
"packageManager": "pnpm@10.10.0",
|
|
28
|
-
"dependencies": {
|
|
29
|
-
"jsdom": "^26.1.0",
|
|
30
|
-
"markdown-it": "^14.1.0",
|
|
31
|
-
"mdast": "^3.0.0",
|
|
32
|
-
"mdast-util-to-markdown": "^2.1.2",
|
|
33
|
-
"tslib": "^2.8.1",
|
|
34
|
-
"unified": "^11.0.5",
|
|
35
|
-
"unist-util-visit": "^5.0.0",
|
|
36
|
-
"vfile": "^6.0.3"
|
|
37
|
-
},
|
|
38
|
-
"devDependencies": {
|
|
39
|
-
"@types/jsdom": "^21.1.7",
|
|
40
|
-
"@types/markdown-it": "^14.1.2",
|
|
41
|
-
"copyfiles": "^2.4.1",
|
|
42
|
-
"typescript": "^5.9.3",
|
|
43
|
-
"vite": "^7.2.7"
|
|
44
|
-
}
|
|
45
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@anyblock/remark-any-block",
|
|
3
|
+
"version": "1.0.3-beta1",
|
|
4
|
+
"description": "You can flexibility to create a 'Block' by many means. It also provides many useful features, like `list to table`.",
|
|
5
|
+
"types": "@types/index_remark.d.ts",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "dist/remark-any-block.cjs",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/remark-any-block.js",
|
|
11
|
+
"require": "./dist/remark-any-block.cjs"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
19
|
+
"build": "pnpm build_vite",
|
|
20
|
+
"build_vite": "pnpm copy_abc_style && vite build",
|
|
21
|
+
"prepublishOnly": "pnpm build",
|
|
22
|
+
"copy_abc_style": "copyfiles --flat ../../src/ABConverter/style/styles.css ./"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [],
|
|
25
|
+
"author": "",
|
|
26
|
+
"license": "GNU Affero General Public License v3.0",
|
|
27
|
+
"packageManager": "pnpm@10.10.0",
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"jsdom": "^26.1.0",
|
|
30
|
+
"markdown-it": "^14.1.0",
|
|
31
|
+
"mdast": "^3.0.0",
|
|
32
|
+
"mdast-util-to-markdown": "^2.1.2",
|
|
33
|
+
"tslib": "^2.8.1",
|
|
34
|
+
"unified": "^11.0.5",
|
|
35
|
+
"unist-util-visit": "^5.0.0",
|
|
36
|
+
"vfile": "^6.0.3"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/jsdom": "^21.1.7",
|
|
40
|
+
"@types/markdown-it": "^14.1.2",
|
|
41
|
+
"copyfiles": "^2.4.1",
|
|
42
|
+
"typescript": "^5.9.3",
|
|
43
|
+
"vite": "^7.2.7"
|
|
44
|
+
}
|
|
45
|
+
}
|