markdown-it-any-block 3.3.5 → 3.3.6

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.
@@ -23,13 +23,17 @@ 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
- async function jsdom_init() {
26
+ let dom = null;
27
+ async function jsdom_init(enable = true) {
27
28
  const { default: jsdom } = await import("jsdom");
28
29
  const { JSDOM } = jsdom;
29
- const dom = new JSDOM(`<!DOCTYPE html><html><body></body></html>`, {
30
+ dom = new JSDOM(`<!DOCTYPE html><html><body></body></html>`, {
30
31
  url: "http://localhost/"
31
32
  // @warn 若缺少该行,则在mdit+build环境下,编译报错
32
33
  });
34
+ if (enable) jsdom_enable();
35
+ }
36
+ function jsdom_enable() {
33
37
  global.Storage = dom.window.Storage;
34
38
  global.window = dom.window;
35
39
  global.history = dom.window.history;
@@ -47,6 +51,67 @@ async function jsdom_init() {
47
51
  };
48
52
  global.MutationObserver = dom.window.MutationObserver;
49
53
  }
54
+ function jsdom_disable() {
55
+ global.window = void 0;
56
+ global.history = void 0;
57
+ global.document = void 0;
58
+ }
59
+ const ABReg = {
60
+ /**
61
+ * AB块头部
62
+ *
63
+ * 例子:` > - > %%[d]:%% `
64
+ *
65
+ * - 前缀部分
66
+ * - $1: 前缀 | ` > - > ` | ((\s|>\s|-\s|\*\s|\+\s)*)
67
+ * - $2: 无用 | `>` | (\s|>\s|-\s|\*\s|\+\s)
68
+ * - 指令部分
69
+ * - $3: 无用 | `%%` | (%%)?
70
+ * - $4:无用 | `[header]` | (\[((?!toc)[0-9a-zA-Z].*)\])
71
+ * - $5:指令 | `header` | (?!toc)[0-9a-zA-Z].*)
72
+ * - $6: 无用 | `%%` | (%%)?
73
+ *
74
+ * 注意:
75
+ * - (?!\[) (?!\toc) 这种向后否定语句不作为一个匹配项
76
+ * - 允许 `%%` 和 `:` 的规则是V3新增的
77
+ * - 不允许 `::` 是避免与 dataview 的 inline property 冲突
78
+ */
79
+ // 有前缀版本(给选择器用)
80
+ reg_header: /^((\s|>\s|-\s|\*\s|\+\s)*)(%%)?(\[((?!toc|TOC|\!|< )[\|\!#:;\(\)\s0-9a-zA-Z\u4e00-\u9fa5](?!.*::).*)\]):?(%%)?\s*$/,
81
+ // 可以用空`|`来解除首字符限制。(`|`注意:可以用来弄严格模式,`#`注意:建议后面空一格避免变成“标签”,`!`注意:别易误触发 `> [!note]`
82
+ reg_header_up: /^((\s|>\s|-\s|\*\s|\+\s)*)(%%)?(\[((?!toc|TOC|\!)< [\|\!#:;\(\)\s0-9a-zA-Z\u4e00-\u9fa5](?!.*::).*)\]):?(%%)?\s*$/,
83
+ // 向上检查标志的 头部选择器
84
+ reg_mdit_head: /^((\s|>\s|-\s|\*\s|\+\s)*)(::::*)\s?(.*)/,
85
+ reg_mdit_tail: /^((\s|>\s|-\s|\*\s|\+\s)*)(::::*)/,
86
+ reg_list: /^((\s|>\s|-\s|\*\s|\+\s)*)(-\s|\*\s|\+\s)(.*)/,
87
+ //: /^\s*(>\s)*-\s(.*)$/
88
+ reg_code: /^((\s|>\s|-\s|\*\s|\+\s)*)(````*|~~~~*)(.*)/,
89
+ //: /^\s*(>\s|-\s)*(````*|~~~~*)(.*)$/
90
+ reg_quote: /^((\s|>\s|-\s|\*\s|\+\s)*)(>\s)(.*)/,
91
+ // `- > ` 不匹配,要认为这种是列表
92
+ reg_heading: /^((\s|>\s|-\s|\*\s|\+\s)*)(\#+\s)(.*)/,
93
+ reg_table: /^((\s|>\s|-\s|\*\s|\+\s)*)(\|(.*)\|)/,
94
+ // 无前缀版本(给处理器用,处理器不需要处理前缀,前缀在选择器阶段已经被去除了)
95
+ reg_header_noprefix: /^((\s)*)(%%)?(\[((?!toc|TOC|\!|< )[\|\!#:;\(\)\s0-9a-zA-Z\u4e00-\u9fa5](?!.*::).*)\]):?(%%)?\s*$/,
96
+ reg_header_up_noprefix: /^((\s)*)(%%)?(\[((?!toc|TOC|\!)< [\|\!#:;\(\)\s0-9a-zA-Z\u4e00-\u9fa5](?!.*::).*)\]):?(%%)?\s*$/,
97
+ reg_mdit_head_noprefix: /^((\s)*)(::::*)\s?(.*)/,
98
+ reg_mdit_tail_noprefix: /^((\s)*)(::::*)/,
99
+ reg_list_noprefix: /^((\s)*)(-\s|\*\s|\+\s)(.*)/,
100
+ reg_code_noprefix: /^((\s)*)(````*|~~~~*)(.*)/,
101
+ reg_quote_noprefix: /^((\s)*)(>\s)(.*)/,
102
+ reg_heading_noprefix: /^((\s)*)(\#+\s)(.*)/,
103
+ reg_table_noprefix: /^((\s)*)(\|(.*)\|)/,
104
+ reg_emptyline_noprefix: /^\s*$/,
105
+ reg_indentline_noprefix: /^\s+?\S/,
106
+ inline_split: /\| |, |, |\. |。 |: |: /
107
+ // 内联切分。`|`或全角符号+一空格,半角符号+两空格 (后者由于空格压缩,若经历了重渲染可能有问题)
108
+ };
109
+ const ABCSetting = {
110
+ env: "obsidian",
111
+ // MarkdownPostProcessorContext类型, obsidian专用
112
+ mermaid: void 0
113
+ // obsidian专用,表示使用哪种方式渲染mermaid
114
+ };
50
115
  var ABConvert_IOEnum = /* @__PURE__ */ ((ABConvert_IOEnum2) => {
51
116
  ABConvert_IOEnum2["text"] = "string";
52
117
  ABConvert_IOEnum2["el"] = "HTMLElement";
@@ -114,47 +179,6 @@ class ABConvert {
114
179
  }
115
180
  }
116
181
  }
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
182
  function autoABAlias(header, selectorName, content) {
159
183
  if (!header.trimEnd().endsWith("|")) header = header + "|";
160
184
  if (!header.trimStart().startsWith("|")) header = "|" + header;
@@ -3028,7 +3052,7 @@ ABConvert.factory({
3028
3052
  process_param: ABConvert_IOEnum.text,
3029
3053
  process_return: ABConvert_IOEnum.el,
3030
3054
  process: (el, header, content) => {
3031
- if (ABCSetting.env == "vuepress") {
3055
+ if (ABCSetting.env == "markdown-it") {
3032
3056
  ABConvertManager.getInstance().m_renderMarkdownFn(`::::: tabs
3033
3057
 
3034
3058
  @tab show
@@ -17255,16 +17279,16 @@ const DomUtils = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProp
17255
17279
  textContent,
17256
17280
  uniqueSort
17257
17281
  }, Symbol.toStringTag, { value: "Module" }));
17258
- function render(that, dom, options) {
17282
+ function render(that, dom2, options) {
17259
17283
  if (!that)
17260
17284
  return "";
17261
- return that(dom !== null && dom !== void 0 ? dom : that._root.children, null, void 0, options).toString();
17285
+ return that(dom2 !== null && dom2 !== void 0 ? dom2 : that._root.children, null, void 0, options).toString();
17262
17286
  }
17263
- function isOptions(dom, options) {
17264
- return typeof dom === "object" && dom != null && !("length" in dom) && !("type" in dom);
17287
+ function isOptions(dom2, options) {
17288
+ return typeof dom2 === "object" && dom2 != null && !("length" in dom2) && !("type" in dom2);
17265
17289
  }
17266
- function html$1(dom, options) {
17267
- const toRender = isOptions(dom) ? (options = dom, void 0) : dom;
17290
+ function html$1(dom2, options) {
17291
+ const toRender = isOptions(dom2) ? (options = dom2, void 0) : dom2;
17268
17292
  const opts = {
17269
17293
  ...defaultOpts$2,
17270
17294
  ...this === null || this === void 0 ? void 0 : this._options,
@@ -17272,9 +17296,9 @@ function html$1(dom, options) {
17272
17296
  };
17273
17297
  return render(this, toRender, opts);
17274
17298
  }
17275
- function xml(dom) {
17299
+ function xml(dom2) {
17276
17300
  const options = { ...this._options, xmlMode: true };
17277
- return render(this, dom, options);
17301
+ return render(this, dom2, options);
17278
17302
  }
17279
17303
  function text$1(elements) {
17280
17304
  const elems = elements ? elements : this ? this.root() : [];
@@ -17364,8 +17388,8 @@ function domEach(array, fn) {
17364
17388
  fn(array[i], i);
17365
17389
  return array;
17366
17390
  }
17367
- function cloneDom(dom) {
17368
- const clone2 = "length" in dom ? Array.prototype.map.call(dom, (el) => cloneNode(el, true)) : [cloneNode(dom, true)];
17391
+ function cloneDom(dom2) {
17392
+ const clone2 = "length" in dom2 ? Array.prototype.map.call(dom2, (el) => cloneNode(el, true)) : [cloneNode(dom2, true)];
17369
17393
  const root2 = new Document$1(clone2);
17370
17394
  clone2.forEach((node) => {
17371
17395
  node.parent = root2;
@@ -19583,8 +19607,8 @@ function _insert(concatenator) {
19583
19607
  if (!hasChildren(el))
19584
19608
  return;
19585
19609
  const domSrc = typeof elems[0] === "function" ? elems[0].call(el, i, this._render(el.children)) : elems;
19586
- const dom = this._makeDomArray(domSrc, i < lastIdx);
19587
- concatenator(dom, el.children, el);
19610
+ const dom2 = this._makeDomArray(domSrc, i < lastIdx);
19611
+ concatenator(dom2, el.children, el);
19588
19612
  });
19589
19613
  };
19590
19614
  }
@@ -19638,11 +19662,11 @@ function prependTo(target) {
19638
19662
  prependTarget.prepend(this);
19639
19663
  return this;
19640
19664
  }
19641
- const append = _insert((dom, children2, parent2) => {
19642
- uniqueSplice(children2, children2.length, 0, dom, parent2);
19665
+ const append = _insert((dom2, children2, parent2) => {
19666
+ uniqueSplice(children2, children2.length, 0, dom2, parent2);
19643
19667
  });
19644
- const prepend = _insert((dom, children2, parent2) => {
19645
- uniqueSplice(children2, 0, 0, dom, parent2);
19668
+ const prepend = _insert((dom2, children2, parent2) => {
19669
+ uniqueSplice(children2, 0, 0, dom2, parent2);
19646
19670
  });
19647
19671
  function _wrap(insert) {
19648
19672
  return function(wrapper) {
@@ -19727,8 +19751,8 @@ function after(...elems) {
19727
19751
  if (index2 < 0)
19728
19752
  return;
19729
19753
  const domSrc = typeof elems[0] === "function" ? elems[0].call(el, i, this._render(el.children)) : elems;
19730
- const dom = this._makeDomArray(domSrc, i < lastIdx);
19731
- uniqueSplice(siblings2, index2 + 1, 0, dom, parent2);
19754
+ const dom2 = this._makeDomArray(domSrc, i < lastIdx);
19755
+ uniqueSplice(siblings2, index2 + 1, 0, dom2, parent2);
19732
19756
  });
19733
19757
  }
19734
19758
  function insertAfter(target) {
@@ -19764,8 +19788,8 @@ function before(...elems) {
19764
19788
  if (index2 < 0)
19765
19789
  return;
19766
19790
  const domSrc = typeof elems[0] === "function" ? elems[0].call(el, i, this._render(el.children)) : elems;
19767
- const dom = this._makeDomArray(domSrc, i < lastIdx);
19768
- uniqueSplice(siblings2, index2, 0, dom, parent2);
19791
+ const dom2 = this._makeDomArray(domSrc, i < lastIdx);
19792
+ uniqueSplice(siblings2, index2, 0, dom2, parent2);
19769
19793
  });
19770
19794
  }
19771
19795
  function insertBefore(target) {
@@ -19803,11 +19827,11 @@ function replaceWith(content) {
19803
19827
  }
19804
19828
  const siblings2 = parent2.children;
19805
19829
  const cont = typeof content === "function" ? content.call(el, i, el) : content;
19806
- const dom = this._makeDomArray(cont);
19807
- update(dom, null);
19830
+ const dom2 = this._makeDomArray(cont);
19831
+ update(dom2, null);
19808
19832
  const index2 = siblings2.indexOf(el);
19809
- uniqueSplice(siblings2, index2, 1, dom, parent2);
19810
- if (!dom.includes(el)) {
19833
+ uniqueSplice(siblings2, index2, 1, dom2, parent2);
19834
+ if (!dom2.includes(el)) {
19811
19835
  el.parent = el.prev = el.next = null;
19812
19836
  }
19813
19837
  });
@@ -20043,8 +20067,8 @@ function getLoad(parse2, render2) {
20043
20067
  _parse(content2, options2, isDocument3, context) {
20044
20068
  return parse2(content2, options2, isDocument3, context);
20045
20069
  }
20046
- _render(dom) {
20047
- return render2(dom, this.options);
20070
+ _render(dom2) {
20071
+ return render2(dom2, this.options);
20048
20072
  }
20049
20073
  }
20050
20074
  function initialize(selector, context, root2 = initialRoot, opts) {
@@ -28228,8 +28252,8 @@ function parseWithParse5(content, options, isDocument2, context) {
28228
28252
  return isDocument2 ? parse$2(content, opts) : parseFragment(context, content, opts);
28229
28253
  }
28230
28254
  const renderOpts = { treeAdapter: adapter };
28231
- function renderWithParse5(dom) {
28232
- const nodes = "length" in dom ? dom : [dom];
28255
+ function renderWithParse5(dom2) {
28256
+ const nodes = "length" in dom2 ? dom2 : [dom2];
28233
28257
  for (let index2 = 0; index2 < nodes.length; index2 += 1) {
28234
28258
  const node = nodes[index2];
28235
28259
  if (isDocument$1(node)) {
@@ -29481,7 +29505,7 @@ function parseDocument$1(data2, options) {
29481
29505
  return handler.root;
29482
29506
  }
29483
29507
  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, (dom, options) => options.xmlMode || options._useHtmlParser2 ? render$1(dom, options) : renderWithParse5(dom));
29508
+ const load = getLoad(parse$1, (dom2, options) => options.xmlMode || options._useHtmlParser2 ? render$1(dom2, options) : renderWithParse5(dom2));
29485
29509
  load([]);
29486
29510
  const defaultSelectorRules = {
29487
29511
  "div,p": ({ $node }) => ({
@@ -49562,7 +49586,7 @@ function ab_mdit(md, options) {
49562
49586
  el.appendChild(el_child);
49563
49587
  el_child.innerHTML = result;
49564
49588
  });
49565
- ABCSetting.env = "vuepress";
49589
+ ABCSetting.env = "markdown-it";
49566
49590
  md.use(abSelector_squareInline);
49567
49591
  md.use(abSelector_container);
49568
49592
  md.use(abRender_fence);
@@ -49575,13 +49599,16 @@ function ab_mdit_client(md, options) {
49575
49599
  el.appendChild(el_child);
49576
49600
  el_child.innerHTML = result;
49577
49601
  });
49578
- ABCSetting.env = "vuepress";
49602
+ ABCSetting.env = "markdown-it";
49579
49603
  md.use(abSelector_squareInline);
49580
49604
  md.use(abSelector_container);
49581
49605
  }
49582
49606
  exports.ABConvertManager = ABConvertManager;
49607
+ exports.ABReg = ABReg;
49583
49608
  exports.abConvertEvent = abConvertEvent;
49584
49609
  exports.ab_mdit = ab_mdit;
49585
49610
  exports.ab_mdit_client = ab_mdit_client;
49611
+ exports.jsdom_disable = jsdom_disable;
49612
+ exports.jsdom_enable = jsdom_enable;
49586
49613
  exports.jsdom_init = jsdom_init;
49587
49614
  //# sourceMappingURL=mdit-any-block.cjs.map
@@ -1,11 +1,15 @@
1
1
  import MarkdownIt from "markdown-it";
2
- async function jsdom_init() {
2
+ let dom = null;
3
+ async function jsdom_init(enable = true) {
3
4
  const { default: jsdom } = await import("jsdom");
4
5
  const { JSDOM } = jsdom;
5
- const dom = new JSDOM(`<!DOCTYPE html><html><body></body></html>`, {
6
+ dom = new JSDOM(`<!DOCTYPE html><html><body></body></html>`, {
6
7
  url: "http://localhost/"
7
8
  // @warn 若缺少该行,则在mdit+build环境下,编译报错
8
9
  });
10
+ if (enable) jsdom_enable();
11
+ }
12
+ function jsdom_enable() {
9
13
  global.Storage = dom.window.Storage;
10
14
  global.window = dom.window;
11
15
  global.history = dom.window.history;
@@ -23,6 +27,67 @@ async function jsdom_init() {
23
27
  };
24
28
  global.MutationObserver = dom.window.MutationObserver;
25
29
  }
30
+ function jsdom_disable() {
31
+ global.window = void 0;
32
+ global.history = void 0;
33
+ global.document = void 0;
34
+ }
35
+ const ABReg = {
36
+ /**
37
+ * AB块头部
38
+ *
39
+ * 例子:` > - > %%[d]:%% `
40
+ *
41
+ * - 前缀部分
42
+ * - $1: 前缀 | ` > - > ` | ((\s|>\s|-\s|\*\s|\+\s)*)
43
+ * - $2: 无用 | `>` | (\s|>\s|-\s|\*\s|\+\s)
44
+ * - 指令部分
45
+ * - $3: 无用 | `%%` | (%%)?
46
+ * - $4:无用 | `[header]` | (\[((?!toc)[0-9a-zA-Z].*)\])
47
+ * - $5:指令 | `header` | (?!toc)[0-9a-zA-Z].*)
48
+ * - $6: 无用 | `%%` | (%%)?
49
+ *
50
+ * 注意:
51
+ * - (?!\[) (?!\toc) 这种向后否定语句不作为一个匹配项
52
+ * - 允许 `%%` 和 `:` 的规则是V3新增的
53
+ * - 不允许 `::` 是避免与 dataview 的 inline property 冲突
54
+ */
55
+ // 有前缀版本(给选择器用)
56
+ reg_header: /^((\s|>\s|-\s|\*\s|\+\s)*)(%%)?(\[((?!toc|TOC|\!|< )[\|\!#:;\(\)\s0-9a-zA-Z\u4e00-\u9fa5](?!.*::).*)\]):?(%%)?\s*$/,
57
+ // 可以用空`|`来解除首字符限制。(`|`注意:可以用来弄严格模式,`#`注意:建议后面空一格避免变成“标签”,`!`注意:别易误触发 `> [!note]`
58
+ reg_header_up: /^((\s|>\s|-\s|\*\s|\+\s)*)(%%)?(\[((?!toc|TOC|\!)< [\|\!#:;\(\)\s0-9a-zA-Z\u4e00-\u9fa5](?!.*::).*)\]):?(%%)?\s*$/,
59
+ // 向上检查标志的 头部选择器
60
+ reg_mdit_head: /^((\s|>\s|-\s|\*\s|\+\s)*)(::::*)\s?(.*)/,
61
+ reg_mdit_tail: /^((\s|>\s|-\s|\*\s|\+\s)*)(::::*)/,
62
+ reg_list: /^((\s|>\s|-\s|\*\s|\+\s)*)(-\s|\*\s|\+\s)(.*)/,
63
+ //: /^\s*(>\s)*-\s(.*)$/
64
+ reg_code: /^((\s|>\s|-\s|\*\s|\+\s)*)(````*|~~~~*)(.*)/,
65
+ //: /^\s*(>\s|-\s)*(````*|~~~~*)(.*)$/
66
+ reg_quote: /^((\s|>\s|-\s|\*\s|\+\s)*)(>\s)(.*)/,
67
+ // `- > ` 不匹配,要认为这种是列表
68
+ reg_heading: /^((\s|>\s|-\s|\*\s|\+\s)*)(\#+\s)(.*)/,
69
+ reg_table: /^((\s|>\s|-\s|\*\s|\+\s)*)(\|(.*)\|)/,
70
+ // 无前缀版本(给处理器用,处理器不需要处理前缀,前缀在选择器阶段已经被去除了)
71
+ reg_header_noprefix: /^((\s)*)(%%)?(\[((?!toc|TOC|\!|< )[\|\!#:;\(\)\s0-9a-zA-Z\u4e00-\u9fa5](?!.*::).*)\]):?(%%)?\s*$/,
72
+ reg_header_up_noprefix: /^((\s)*)(%%)?(\[((?!toc|TOC|\!)< [\|\!#:;\(\)\s0-9a-zA-Z\u4e00-\u9fa5](?!.*::).*)\]):?(%%)?\s*$/,
73
+ reg_mdit_head_noprefix: /^((\s)*)(::::*)\s?(.*)/,
74
+ reg_mdit_tail_noprefix: /^((\s)*)(::::*)/,
75
+ reg_list_noprefix: /^((\s)*)(-\s|\*\s|\+\s)(.*)/,
76
+ reg_code_noprefix: /^((\s)*)(````*|~~~~*)(.*)/,
77
+ reg_quote_noprefix: /^((\s)*)(>\s)(.*)/,
78
+ reg_heading_noprefix: /^((\s)*)(\#+\s)(.*)/,
79
+ reg_table_noprefix: /^((\s)*)(\|(.*)\|)/,
80
+ reg_emptyline_noprefix: /^\s*$/,
81
+ reg_indentline_noprefix: /^\s+?\S/,
82
+ inline_split: /\| |, |, |\. |。 |: |: /
83
+ // 内联切分。`|`或全角符号+一空格,半角符号+两空格 (后者由于空格压缩,若经历了重渲染可能有问题)
84
+ };
85
+ const ABCSetting = {
86
+ env: "obsidian",
87
+ // MarkdownPostProcessorContext类型, obsidian专用
88
+ mermaid: void 0
89
+ // obsidian专用,表示使用哪种方式渲染mermaid
90
+ };
26
91
  var ABConvert_IOEnum = /* @__PURE__ */ ((ABConvert_IOEnum2) => {
27
92
  ABConvert_IOEnum2["text"] = "string";
28
93
  ABConvert_IOEnum2["el"] = "HTMLElement";
@@ -90,47 +155,6 @@ class ABConvert {
90
155
  }
91
156
  }
92
157
  }
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
158
  function autoABAlias(header, selectorName, content) {
135
159
  if (!header.trimEnd().endsWith("|")) header = header + "|";
136
160
  if (!header.trimStart().startsWith("|")) header = "|" + header;
@@ -3004,7 +3028,7 @@ ABConvert.factory({
3004
3028
  process_param: ABConvert_IOEnum.text,
3005
3029
  process_return: ABConvert_IOEnum.el,
3006
3030
  process: (el, header, content) => {
3007
- if (ABCSetting.env == "vuepress") {
3031
+ if (ABCSetting.env == "markdown-it") {
3008
3032
  ABConvertManager.getInstance().m_renderMarkdownFn(`::::: tabs
3009
3033
 
3010
3034
  @tab show
@@ -17231,16 +17255,16 @@ const DomUtils = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProp
17231
17255
  textContent,
17232
17256
  uniqueSort
17233
17257
  }, Symbol.toStringTag, { value: "Module" }));
17234
- function render(that, dom, options) {
17258
+ function render(that, dom2, options) {
17235
17259
  if (!that)
17236
17260
  return "";
17237
- return that(dom !== null && dom !== void 0 ? dom : that._root.children, null, void 0, options).toString();
17261
+ return that(dom2 !== null && dom2 !== void 0 ? dom2 : that._root.children, null, void 0, options).toString();
17238
17262
  }
17239
- function isOptions(dom, options) {
17240
- return typeof dom === "object" && dom != null && !("length" in dom) && !("type" in dom);
17263
+ function isOptions(dom2, options) {
17264
+ return typeof dom2 === "object" && dom2 != null && !("length" in dom2) && !("type" in dom2);
17241
17265
  }
17242
- function html$1(dom, options) {
17243
- const toRender = isOptions(dom) ? (options = dom, void 0) : dom;
17266
+ function html$1(dom2, options) {
17267
+ const toRender = isOptions(dom2) ? (options = dom2, void 0) : dom2;
17244
17268
  const opts = {
17245
17269
  ...defaultOpts$2,
17246
17270
  ...this === null || this === void 0 ? void 0 : this._options,
@@ -17248,9 +17272,9 @@ function html$1(dom, options) {
17248
17272
  };
17249
17273
  return render(this, toRender, opts);
17250
17274
  }
17251
- function xml(dom) {
17275
+ function xml(dom2) {
17252
17276
  const options = { ...this._options, xmlMode: true };
17253
- return render(this, dom, options);
17277
+ return render(this, dom2, options);
17254
17278
  }
17255
17279
  function text$1(elements) {
17256
17280
  const elems = elements ? elements : this ? this.root() : [];
@@ -17340,8 +17364,8 @@ function domEach(array, fn) {
17340
17364
  fn(array[i], i);
17341
17365
  return array;
17342
17366
  }
17343
- function cloneDom(dom) {
17344
- const clone2 = "length" in dom ? Array.prototype.map.call(dom, (el) => cloneNode(el, true)) : [cloneNode(dom, true)];
17367
+ function cloneDom(dom2) {
17368
+ const clone2 = "length" in dom2 ? Array.prototype.map.call(dom2, (el) => cloneNode(el, true)) : [cloneNode(dom2, true)];
17345
17369
  const root2 = new Document$1(clone2);
17346
17370
  clone2.forEach((node) => {
17347
17371
  node.parent = root2;
@@ -19559,8 +19583,8 @@ function _insert(concatenator) {
19559
19583
  if (!hasChildren(el))
19560
19584
  return;
19561
19585
  const domSrc = typeof elems[0] === "function" ? elems[0].call(el, i, this._render(el.children)) : elems;
19562
- const dom = this._makeDomArray(domSrc, i < lastIdx);
19563
- concatenator(dom, el.children, el);
19586
+ const dom2 = this._makeDomArray(domSrc, i < lastIdx);
19587
+ concatenator(dom2, el.children, el);
19564
19588
  });
19565
19589
  };
19566
19590
  }
@@ -19614,11 +19638,11 @@ function prependTo(target) {
19614
19638
  prependTarget.prepend(this);
19615
19639
  return this;
19616
19640
  }
19617
- const append = _insert((dom, children2, parent2) => {
19618
- uniqueSplice(children2, children2.length, 0, dom, parent2);
19641
+ const append = _insert((dom2, children2, parent2) => {
19642
+ uniqueSplice(children2, children2.length, 0, dom2, parent2);
19619
19643
  });
19620
- const prepend = _insert((dom, children2, parent2) => {
19621
- uniqueSplice(children2, 0, 0, dom, parent2);
19644
+ const prepend = _insert((dom2, children2, parent2) => {
19645
+ uniqueSplice(children2, 0, 0, dom2, parent2);
19622
19646
  });
19623
19647
  function _wrap(insert) {
19624
19648
  return function(wrapper) {
@@ -19703,8 +19727,8 @@ function after(...elems) {
19703
19727
  if (index2 < 0)
19704
19728
  return;
19705
19729
  const domSrc = typeof elems[0] === "function" ? elems[0].call(el, i, this._render(el.children)) : elems;
19706
- const dom = this._makeDomArray(domSrc, i < lastIdx);
19707
- uniqueSplice(siblings2, index2 + 1, 0, dom, parent2);
19730
+ const dom2 = this._makeDomArray(domSrc, i < lastIdx);
19731
+ uniqueSplice(siblings2, index2 + 1, 0, dom2, parent2);
19708
19732
  });
19709
19733
  }
19710
19734
  function insertAfter(target) {
@@ -19740,8 +19764,8 @@ function before(...elems) {
19740
19764
  if (index2 < 0)
19741
19765
  return;
19742
19766
  const domSrc = typeof elems[0] === "function" ? elems[0].call(el, i, this._render(el.children)) : elems;
19743
- const dom = this._makeDomArray(domSrc, i < lastIdx);
19744
- uniqueSplice(siblings2, index2, 0, dom, parent2);
19767
+ const dom2 = this._makeDomArray(domSrc, i < lastIdx);
19768
+ uniqueSplice(siblings2, index2, 0, dom2, parent2);
19745
19769
  });
19746
19770
  }
19747
19771
  function insertBefore(target) {
@@ -19779,11 +19803,11 @@ function replaceWith(content) {
19779
19803
  }
19780
19804
  const siblings2 = parent2.children;
19781
19805
  const cont = typeof content === "function" ? content.call(el, i, el) : content;
19782
- const dom = this._makeDomArray(cont);
19783
- update(dom, null);
19806
+ const dom2 = this._makeDomArray(cont);
19807
+ update(dom2, null);
19784
19808
  const index2 = siblings2.indexOf(el);
19785
- uniqueSplice(siblings2, index2, 1, dom, parent2);
19786
- if (!dom.includes(el)) {
19809
+ uniqueSplice(siblings2, index2, 1, dom2, parent2);
19810
+ if (!dom2.includes(el)) {
19787
19811
  el.parent = el.prev = el.next = null;
19788
19812
  }
19789
19813
  });
@@ -20019,8 +20043,8 @@ function getLoad(parse2, render2) {
20019
20043
  _parse(content2, options2, isDocument3, context) {
20020
20044
  return parse2(content2, options2, isDocument3, context);
20021
20045
  }
20022
- _render(dom) {
20023
- return render2(dom, this.options);
20046
+ _render(dom2) {
20047
+ return render2(dom2, this.options);
20024
20048
  }
20025
20049
  }
20026
20050
  function initialize(selector, context, root2 = initialRoot, opts) {
@@ -28204,8 +28228,8 @@ function parseWithParse5(content, options, isDocument2, context) {
28204
28228
  return isDocument2 ? parse$2(content, opts) : parseFragment(context, content, opts);
28205
28229
  }
28206
28230
  const renderOpts = { treeAdapter: adapter };
28207
- function renderWithParse5(dom) {
28208
- const nodes = "length" in dom ? dom : [dom];
28231
+ function renderWithParse5(dom2) {
28232
+ const nodes = "length" in dom2 ? dom2 : [dom2];
28209
28233
  for (let index2 = 0; index2 < nodes.length; index2 += 1) {
28210
28234
  const node = nodes[index2];
28211
28235
  if (isDocument$1(node)) {
@@ -29457,7 +29481,7 @@ function parseDocument$1(data2, options) {
29457
29481
  return handler.root;
29458
29482
  }
29459
29483
  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, (dom, options) => options.xmlMode || options._useHtmlParser2 ? render$1(dom, options) : renderWithParse5(dom));
29484
+ const load = getLoad(parse$1, (dom2, options) => options.xmlMode || options._useHtmlParser2 ? render$1(dom2, options) : renderWithParse5(dom2));
29461
29485
  load([]);
29462
29486
  const defaultSelectorRules = {
29463
29487
  "div,p": ({ $node }) => ({
@@ -49538,7 +49562,7 @@ function ab_mdit(md, options) {
49538
49562
  el.appendChild(el_child);
49539
49563
  el_child.innerHTML = result;
49540
49564
  });
49541
- ABCSetting.env = "vuepress";
49565
+ ABCSetting.env = "markdown-it";
49542
49566
  md.use(abSelector_squareInline);
49543
49567
  md.use(abSelector_container);
49544
49568
  md.use(abRender_fence);
@@ -49551,15 +49575,18 @@ function ab_mdit_client(md, options) {
49551
49575
  el.appendChild(el_child);
49552
49576
  el_child.innerHTML = result;
49553
49577
  });
49554
- ABCSetting.env = "vuepress";
49578
+ ABCSetting.env = "markdown-it";
49555
49579
  md.use(abSelector_squareInline);
49556
49580
  md.use(abSelector_container);
49557
49581
  }
49558
49582
  export {
49559
49583
  ABConvertManager,
49584
+ ABReg,
49560
49585
  abConvertEvent,
49561
49586
  ab_mdit,
49562
49587
  ab_mdit_client,
49588
+ jsdom_disable,
49589
+ jsdom_enable,
49563
49590
  jsdom_init
49564
49591
  };
49565
49592
  //# sourceMappingURL=mdit-any-block.js.map
package/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  // JsDom。仅用于提供document对象支持 (如果Ob环境中则不需要,用ob自带document对象的)
2
- export { jsdom_init } from './jsdom_init'
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
@@ -427,7 +427,7 @@ export function ab_mdit(md: MarkdownIt, options?: Partial<Options>): void {
427
427
  })
428
428
 
429
429
  // 定义环境条件
430
- ABCSetting.env = "vuepress"
430
+ ABCSetting.env = "markdown-it"
431
431
 
432
432
  md.use(abSelector_squareInline)
433
433
  md.use(abSelector_container)
@@ -444,7 +444,7 @@ export function ab_mdit_client(md: MarkdownIt, options?: Partial<Options>): void
444
444
  })
445
445
 
446
446
  // 定义环境条件
447
- ABCSetting.env = "vuepress"
447
+ ABCSetting.env = "markdown-it"
448
448
 
449
449
  md.use(abSelector_squareInline)
450
450
  md.use(abSelector_container)
package/jsdom_init.ts CHANGED
@@ -6,12 +6,19 @@
6
6
 
7
7
  // import jsdom from "jsdom"
8
8
 
9
- export async function jsdom_init() {
9
+ let dom: any = null;
10
+
11
+ export async function jsdom_init(enable: boolean = true) {
10
12
  const { default: jsdom } = await import('jsdom') // 废弃,要同步,避免docuemnt初始化不及时
11
13
  const { JSDOM } = jsdom
12
- const dom = new JSDOM(`<!DOCTYPE html><html><body></body></html>`, {
14
+ dom = new JSDOM(`<!DOCTYPE html><html><body></body></html>`, {
13
15
  url: 'http://localhost/', // @warn 若缺少该行,则在mdit+build环境下,编译报错
14
- });
16
+ })
17
+ if (enable) jsdom_enable()
18
+ }
19
+
20
+ /// 启用 jsdom 环境
21
+ export function jsdom_enable() {
15
22
  global.Storage = dom.window.Storage;
16
23
  global.window = dom.window as any
17
24
  global.history = dom.window.history // @warn 若缺少该行,则在mdit+build环境下,编译报错:ReferenceError: history is not defined
@@ -28,3 +35,10 @@ export async function jsdom_init() {
28
35
  dom.window.scrollTo = ()=>{} // @warn 若缺少该行,编译警告:Error: Not implemented: window.scrollTo
29
36
  global.MutationObserver = dom.window.MutationObserver
30
37
  }
38
+
39
+ /// 禁用 jsdom 环境
40
+ export function jsdom_disable() {
41
+ global.window = undefined
42
+ global.history = undefined
43
+ global.document = undefined
44
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markdown-it-any-block",
3
- "version": "3.3.5",
3
+ "version": "3.3.6",
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",