@anyblock/remark-any-block 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,9 +2,21 @@
2
2
 
3
3
  ## remark-any-block 使用
4
4
 
5
- 详见 github *any-block* 组织下的 *Remark Demo* 仓库
5
+ 当前使用 Remark 解析/渲染引擎的主流 SSG (静态网站生成器) 有:
6
6
 
7
- 暂时不属于完全通用的 Remark 插件 (doing, 或者你自己改改), 当前该插件测试于 Quartz V4 版本
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
- // 这是 Quartz 的 Transformer 插件定义
234
- export const transformer_anyblock: QuartzTransformerPlugin = (/*options: any*/) => {
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,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
  const convert = (
51
116
  // Note: overloads in JSDoc can’t yet use different `@template`s.
52
117
  /**
@@ -305,27 +370,6 @@ class ABConvert {
305
370
  }
306
371
  }
307
372
  }
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
373
  function autoABAlias(header, selectorName, content) {
330
374
  if (!header.trimEnd().endsWith("|")) header = header + "|";
331
375
  if (!header.trimStart().startsWith("|")) header = "|" + header;
@@ -17503,16 +17547,16 @@ const DomUtils = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProp
17503
17547
  textContent,
17504
17548
  uniqueSort
17505
17549
  }, Symbol.toStringTag, { value: "Module" }));
17506
- function render(that, dom, options) {
17550
+ function render(that, dom2, options) {
17507
17551
  if (!that)
17508
17552
  return "";
17509
- return that(dom !== null && dom !== void 0 ? dom : that._root.children, null, void 0, options).toString();
17553
+ return that(dom2 !== null && dom2 !== void 0 ? dom2 : that._root.children, null, void 0, options).toString();
17510
17554
  }
17511
- function isOptions(dom, options) {
17512
- return typeof dom === "object" && dom != null && !("length" in dom) && !("type" in dom);
17555
+ function isOptions(dom2, options) {
17556
+ return typeof dom2 === "object" && dom2 != null && !("length" in dom2) && !("type" in dom2);
17513
17557
  }
17514
- function html$1(dom, options) {
17515
- const toRender = isOptions(dom) ? (options = dom, void 0) : dom;
17558
+ function html$1(dom2, options) {
17559
+ const toRender = isOptions(dom2) ? (options = dom2, void 0) : dom2;
17516
17560
  const opts = {
17517
17561
  ...defaultOpts$2,
17518
17562
  ...this === null || this === void 0 ? void 0 : this._options,
@@ -17520,9 +17564,9 @@ function html$1(dom, options) {
17520
17564
  };
17521
17565
  return render(this, toRender, opts);
17522
17566
  }
17523
- function xml(dom) {
17567
+ function xml(dom2) {
17524
17568
  const options = { ...this._options, xmlMode: true };
17525
- return render(this, dom, options);
17569
+ return render(this, dom2, options);
17526
17570
  }
17527
17571
  function text$1(elements) {
17528
17572
  const elems = elements ? elements : this ? this.root() : [];
@@ -17612,8 +17656,8 @@ function domEach(array, fn) {
17612
17656
  fn(array[i], i);
17613
17657
  return array;
17614
17658
  }
17615
- function cloneDom(dom) {
17616
- const clone2 = "length" in dom ? Array.prototype.map.call(dom, (el) => cloneNode(el, true)) : [cloneNode(dom, true)];
17659
+ function cloneDom(dom2) {
17660
+ const clone2 = "length" in dom2 ? Array.prototype.map.call(dom2, (el) => cloneNode(el, true)) : [cloneNode(dom2, true)];
17617
17661
  const root2 = new Document$1(clone2);
17618
17662
  clone2.forEach((node) => {
17619
17663
  node.parent = root2;
@@ -19844,8 +19888,8 @@ function _insert(concatenator) {
19844
19888
  if (!hasChildren(el))
19845
19889
  return;
19846
19890
  const domSrc = typeof elems[0] === "function" ? elems[0].call(el, i, this._render(el.children)) : elems;
19847
- const dom = this._makeDomArray(domSrc, i < lastIdx);
19848
- concatenator(dom, el.children, el);
19891
+ const dom2 = this._makeDomArray(domSrc, i < lastIdx);
19892
+ concatenator(dom2, el.children, el);
19849
19893
  });
19850
19894
  };
19851
19895
  }
@@ -19899,11 +19943,11 @@ function prependTo(target) {
19899
19943
  prependTarget.prepend(this);
19900
19944
  return this;
19901
19945
  }
19902
- const append = _insert((dom, children2, parent2) => {
19903
- uniqueSplice(children2, children2.length, 0, dom, parent2);
19946
+ const append = _insert((dom2, children2, parent2) => {
19947
+ uniqueSplice(children2, children2.length, 0, dom2, parent2);
19904
19948
  });
19905
- const prepend = _insert((dom, children2, parent2) => {
19906
- uniqueSplice(children2, 0, 0, dom, parent2);
19949
+ const prepend = _insert((dom2, children2, parent2) => {
19950
+ uniqueSplice(children2, 0, 0, dom2, parent2);
19907
19951
  });
19908
19952
  function _wrap(insert) {
19909
19953
  return function(wrapper) {
@@ -19988,8 +20032,8 @@ function after(...elems) {
19988
20032
  if (index2 < 0)
19989
20033
  return;
19990
20034
  const domSrc = typeof elems[0] === "function" ? elems[0].call(el, i, this._render(el.children)) : elems;
19991
- const dom = this._makeDomArray(domSrc, i < lastIdx);
19992
- uniqueSplice(siblings2, index2 + 1, 0, dom, parent2);
20035
+ const dom2 = this._makeDomArray(domSrc, i < lastIdx);
20036
+ uniqueSplice(siblings2, index2 + 1, 0, dom2, parent2);
19993
20037
  });
19994
20038
  }
19995
20039
  function insertAfter(target) {
@@ -20025,8 +20069,8 @@ function before(...elems) {
20025
20069
  if (index2 < 0)
20026
20070
  return;
20027
20071
  const domSrc = typeof elems[0] === "function" ? elems[0].call(el, i, this._render(el.children)) : elems;
20028
- const dom = this._makeDomArray(domSrc, i < lastIdx);
20029
- uniqueSplice(siblings2, index2, 0, dom, parent2);
20072
+ const dom2 = this._makeDomArray(domSrc, i < lastIdx);
20073
+ uniqueSplice(siblings2, index2, 0, dom2, parent2);
20030
20074
  });
20031
20075
  }
20032
20076
  function insertBefore(target) {
@@ -20064,11 +20108,11 @@ function replaceWith(content) {
20064
20108
  }
20065
20109
  const siblings2 = parent2.children;
20066
20110
  const cont = typeof content === "function" ? content.call(el, i, el) : content;
20067
- const dom = this._makeDomArray(cont);
20068
- update(dom, null);
20111
+ const dom2 = this._makeDomArray(cont);
20112
+ update(dom2, null);
20069
20113
  const index2 = siblings2.indexOf(el);
20070
- uniqueSplice(siblings2, index2, 1, dom, parent2);
20071
- if (!dom.includes(el)) {
20114
+ uniqueSplice(siblings2, index2, 1, dom2, parent2);
20115
+ if (!dom2.includes(el)) {
20072
20116
  el.parent = el.prev = el.next = null;
20073
20117
  }
20074
20118
  });
@@ -20304,8 +20348,8 @@ function getLoad(parse2, render2) {
20304
20348
  _parse(content2, options2, isDocument3, context) {
20305
20349
  return parse2(content2, options2, isDocument3, context);
20306
20350
  }
20307
- _render(dom) {
20308
- return render2(dom, this.options);
20351
+ _render(dom2) {
20352
+ return render2(dom2, this.options);
20309
20353
  }
20310
20354
  }
20311
20355
  function initialize(selector, context, root2 = initialRoot, opts) {
@@ -28492,8 +28536,8 @@ function parseWithParse5(content, options, isDocument2, context) {
28492
28536
  return isDocument2 ? parse$2(content, opts) : parseFragment(context, content, opts);
28493
28537
  }
28494
28538
  const renderOpts = { treeAdapter: adapter };
28495
- function renderWithParse5(dom) {
28496
- const nodes = "length" in dom ? dom : [dom];
28539
+ function renderWithParse5(dom2) {
28540
+ const nodes = "length" in dom2 ? dom2 : [dom2];
28497
28541
  for (let index2 = 0; index2 < nodes.length; index2 += 1) {
28498
28542
  const node = nodes[index2];
28499
28543
  if (isDocument$1(node)) {
@@ -29745,7 +29789,7 @@ function parseDocument$1(data2, options) {
29745
29789
  return handler.root;
29746
29790
  }
29747
29791
  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, (dom, options) => options.xmlMode || options._useHtmlParser2 ? render$1(dom, options) : renderWithParse5(dom));
29792
+ const load = getLoad(parse$1, (dom2, options) => options.xmlMode || options._useHtmlParser2 ? render$1(dom2, options) : renderWithParse5(dom2));
29749
29793
  load([]);
29750
29794
  const defaultSelectorRules = {
29751
29795
  "div,p": ({ $node }) => ({
@@ -49621,7 +49665,7 @@ const remark_anyblock_render_codeblock = () => {
49621
49665
  if (typeof document == "undefined") return;
49622
49666
  return (tree, _file) => {
49623
49667
  visit$1(tree, "code", (node, index2, parent2) => {
49624
- if (node.lang.toLowerCase() != "anyblock") return;
49668
+ if (typeof node.lang != "string" || node.lang.toLowerCase() != "anyblock") return;
49625
49669
  if (!parent2 || !index2) return;
49626
49670
  const lines = node.value.split("\n");
49627
49671
  const head = lines.shift();
@@ -49651,7 +49695,7 @@ const remark_anyblock_render_codeblock = () => {
49651
49695
  el_child.innerHTML = result;
49652
49696
  });
49653
49697
  }
49654
- const transformer_anyblock = () => {
49698
+ const quartz_transformer_anyblock = () => {
49655
49699
  return {
49656
49700
  name: "AnyBlock",
49657
49701
  markdownPlugins(_ctx) {
@@ -49667,8 +49711,11 @@ const transformer_anyblock = () => {
49667
49711
  };
49668
49712
  };
49669
49713
  exports.ABConvertManager = ABConvertManager;
49714
+ exports.ABReg = ABReg;
49670
49715
  exports.abConvertEvent = abConvertEvent;
49716
+ exports.jsdom_disable = jsdom_disable;
49717
+ exports.jsdom_enable = jsdom_enable;
49671
49718
  exports.jsdom_init = jsdom_init;
49672
49719
  exports.remark_anyblock_render_codeblock = remark_anyblock_render_codeblock;
49673
- exports.transformer_anyblock = transformer_anyblock;
49720
+ exports.transformer_anyblock = quartz_transformer_anyblock;
49674
49721
  //# sourceMappingURL=remark-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
  const convert = (
27
92
  // Note: overloads in JSDoc can’t yet use different `@template`s.
28
93
  /**
@@ -281,27 +346,6 @@ class ABConvert {
281
346
  }
282
347
  }
283
348
  }
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
349
  function autoABAlias(header, selectorName, content) {
306
350
  if (!header.trimEnd().endsWith("|")) header = header + "|";
307
351
  if (!header.trimStart().startsWith("|")) header = "|" + header;
@@ -17479,16 +17523,16 @@ const DomUtils = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProp
17479
17523
  textContent,
17480
17524
  uniqueSort
17481
17525
  }, Symbol.toStringTag, { value: "Module" }));
17482
- function render(that, dom, options) {
17526
+ function render(that, dom2, options) {
17483
17527
  if (!that)
17484
17528
  return "";
17485
- return that(dom !== null && dom !== void 0 ? dom : that._root.children, null, void 0, options).toString();
17529
+ return that(dom2 !== null && dom2 !== void 0 ? dom2 : that._root.children, null, void 0, options).toString();
17486
17530
  }
17487
- function isOptions(dom, options) {
17488
- return typeof dom === "object" && dom != null && !("length" in dom) && !("type" in dom);
17531
+ function isOptions(dom2, options) {
17532
+ return typeof dom2 === "object" && dom2 != null && !("length" in dom2) && !("type" in dom2);
17489
17533
  }
17490
- function html$1(dom, options) {
17491
- const toRender = isOptions(dom) ? (options = dom, void 0) : dom;
17534
+ function html$1(dom2, options) {
17535
+ const toRender = isOptions(dom2) ? (options = dom2, void 0) : dom2;
17492
17536
  const opts = {
17493
17537
  ...defaultOpts$2,
17494
17538
  ...this === null || this === void 0 ? void 0 : this._options,
@@ -17496,9 +17540,9 @@ function html$1(dom, options) {
17496
17540
  };
17497
17541
  return render(this, toRender, opts);
17498
17542
  }
17499
- function xml(dom) {
17543
+ function xml(dom2) {
17500
17544
  const options = { ...this._options, xmlMode: true };
17501
- return render(this, dom, options);
17545
+ return render(this, dom2, options);
17502
17546
  }
17503
17547
  function text$1(elements) {
17504
17548
  const elems = elements ? elements : this ? this.root() : [];
@@ -17588,8 +17632,8 @@ function domEach(array, fn) {
17588
17632
  fn(array[i], i);
17589
17633
  return array;
17590
17634
  }
17591
- function cloneDom(dom) {
17592
- const clone2 = "length" in dom ? Array.prototype.map.call(dom, (el) => cloneNode(el, true)) : [cloneNode(dom, true)];
17635
+ function cloneDom(dom2) {
17636
+ const clone2 = "length" in dom2 ? Array.prototype.map.call(dom2, (el) => cloneNode(el, true)) : [cloneNode(dom2, true)];
17593
17637
  const root2 = new Document$1(clone2);
17594
17638
  clone2.forEach((node) => {
17595
17639
  node.parent = root2;
@@ -19820,8 +19864,8 @@ function _insert(concatenator) {
19820
19864
  if (!hasChildren(el))
19821
19865
  return;
19822
19866
  const domSrc = typeof elems[0] === "function" ? elems[0].call(el, i, this._render(el.children)) : elems;
19823
- const dom = this._makeDomArray(domSrc, i < lastIdx);
19824
- concatenator(dom, el.children, el);
19867
+ const dom2 = this._makeDomArray(domSrc, i < lastIdx);
19868
+ concatenator(dom2, el.children, el);
19825
19869
  });
19826
19870
  };
19827
19871
  }
@@ -19875,11 +19919,11 @@ function prependTo(target) {
19875
19919
  prependTarget.prepend(this);
19876
19920
  return this;
19877
19921
  }
19878
- const append = _insert((dom, children2, parent2) => {
19879
- uniqueSplice(children2, children2.length, 0, dom, parent2);
19922
+ const append = _insert((dom2, children2, parent2) => {
19923
+ uniqueSplice(children2, children2.length, 0, dom2, parent2);
19880
19924
  });
19881
- const prepend = _insert((dom, children2, parent2) => {
19882
- uniqueSplice(children2, 0, 0, dom, parent2);
19925
+ const prepend = _insert((dom2, children2, parent2) => {
19926
+ uniqueSplice(children2, 0, 0, dom2, parent2);
19883
19927
  });
19884
19928
  function _wrap(insert) {
19885
19929
  return function(wrapper) {
@@ -19964,8 +20008,8 @@ function after(...elems) {
19964
20008
  if (index2 < 0)
19965
20009
  return;
19966
20010
  const domSrc = typeof elems[0] === "function" ? elems[0].call(el, i, this._render(el.children)) : elems;
19967
- const dom = this._makeDomArray(domSrc, i < lastIdx);
19968
- uniqueSplice(siblings2, index2 + 1, 0, dom, parent2);
20011
+ const dom2 = this._makeDomArray(domSrc, i < lastIdx);
20012
+ uniqueSplice(siblings2, index2 + 1, 0, dom2, parent2);
19969
20013
  });
19970
20014
  }
19971
20015
  function insertAfter(target) {
@@ -20001,8 +20045,8 @@ function before(...elems) {
20001
20045
  if (index2 < 0)
20002
20046
  return;
20003
20047
  const domSrc = typeof elems[0] === "function" ? elems[0].call(el, i, this._render(el.children)) : elems;
20004
- const dom = this._makeDomArray(domSrc, i < lastIdx);
20005
- uniqueSplice(siblings2, index2, 0, dom, parent2);
20048
+ const dom2 = this._makeDomArray(domSrc, i < lastIdx);
20049
+ uniqueSplice(siblings2, index2, 0, dom2, parent2);
20006
20050
  });
20007
20051
  }
20008
20052
  function insertBefore(target) {
@@ -20040,11 +20084,11 @@ function replaceWith(content) {
20040
20084
  }
20041
20085
  const siblings2 = parent2.children;
20042
20086
  const cont = typeof content === "function" ? content.call(el, i, el) : content;
20043
- const dom = this._makeDomArray(cont);
20044
- update(dom, null);
20087
+ const dom2 = this._makeDomArray(cont);
20088
+ update(dom2, null);
20045
20089
  const index2 = siblings2.indexOf(el);
20046
- uniqueSplice(siblings2, index2, 1, dom, parent2);
20047
- if (!dom.includes(el)) {
20090
+ uniqueSplice(siblings2, index2, 1, dom2, parent2);
20091
+ if (!dom2.includes(el)) {
20048
20092
  el.parent = el.prev = el.next = null;
20049
20093
  }
20050
20094
  });
@@ -20280,8 +20324,8 @@ function getLoad(parse2, render2) {
20280
20324
  _parse(content2, options2, isDocument3, context) {
20281
20325
  return parse2(content2, options2, isDocument3, context);
20282
20326
  }
20283
- _render(dom) {
20284
- return render2(dom, this.options);
20327
+ _render(dom2) {
20328
+ return render2(dom2, this.options);
20285
20329
  }
20286
20330
  }
20287
20331
  function initialize(selector, context, root2 = initialRoot, opts) {
@@ -28468,8 +28512,8 @@ function parseWithParse5(content, options, isDocument2, context) {
28468
28512
  return isDocument2 ? parse$2(content, opts) : parseFragment(context, content, opts);
28469
28513
  }
28470
28514
  const renderOpts = { treeAdapter: adapter };
28471
- function renderWithParse5(dom) {
28472
- const nodes = "length" in dom ? dom : [dom];
28515
+ function renderWithParse5(dom2) {
28516
+ const nodes = "length" in dom2 ? dom2 : [dom2];
28473
28517
  for (let index2 = 0; index2 < nodes.length; index2 += 1) {
28474
28518
  const node = nodes[index2];
28475
28519
  if (isDocument$1(node)) {
@@ -29721,7 +29765,7 @@ function parseDocument$1(data2, options) {
29721
29765
  return handler.root;
29722
29766
  }
29723
29767
  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, (dom, options) => options.xmlMode || options._useHtmlParser2 ? render$1(dom, options) : renderWithParse5(dom));
29768
+ const load = getLoad(parse$1, (dom2, options) => options.xmlMode || options._useHtmlParser2 ? render$1(dom2, options) : renderWithParse5(dom2));
29725
29769
  load([]);
29726
29770
  const defaultSelectorRules = {
29727
29771
  "div,p": ({ $node }) => ({
@@ -49597,7 +49641,7 @@ const remark_anyblock_render_codeblock = () => {
49597
49641
  if (typeof document == "undefined") return;
49598
49642
  return (tree, _file) => {
49599
49643
  visit$1(tree, "code", (node, index2, parent2) => {
49600
- if (node.lang.toLowerCase() != "anyblock") return;
49644
+ if (typeof node.lang != "string" || node.lang.toLowerCase() != "anyblock") return;
49601
49645
  if (!parent2 || !index2) return;
49602
49646
  const lines = node.value.split("\n");
49603
49647
  const head = lines.shift();
@@ -49627,7 +49671,7 @@ const remark_anyblock_render_codeblock = () => {
49627
49671
  el_child.innerHTML = result;
49628
49672
  });
49629
49673
  }
49630
- const transformer_anyblock = () => {
49674
+ const quartz_transformer_anyblock = () => {
49631
49675
  return {
49632
49676
  name: "AnyBlock",
49633
49677
  markdownPlugins(_ctx) {
@@ -49644,9 +49688,12 @@ const transformer_anyblock = () => {
49644
49688
  };
49645
49689
  export {
49646
49690
  ABConvertManager,
49691
+ ABReg,
49647
49692
  abConvertEvent,
49693
+ jsdom_disable,
49694
+ jsdom_enable,
49648
49695
  jsdom_init,
49649
49696
  remark_anyblock_render_codeblock,
49650
- transformer_anyblock
49697
+ quartz_transformer_anyblock as transformer_anyblock
49651
49698
  };
49652
49699
  //# sourceMappingURL=remark-any-block.js.map
package/index.ts CHANGED
@@ -1,7 +1,8 @@
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 {
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,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": "@anyblock/remark-any-block",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "You can flexibility to create a 'Block' by many means. It also provides many useful features, like `list to table`.",
5
5
  "types": "@types/index_remark.d.ts",
6
6
  "type": "module",