@anyblock/remark-any-block 1.0.2 → 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.
@@ -24,7 +24,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
24
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
25
25
  const MarkdownIt = require("markdown-it");
26
26
  let dom = null;
27
- async function jsdom_init(enable = true) {
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;
28
31
  const { default: jsdom } = await import("jsdom");
29
32
  const { JSDOM } = jsdom;
30
33
  dom = new JSDOM(`<!DOCTYPE html><html><body></body></html>`, {
@@ -34,6 +37,7 @@ async function jsdom_init(enable = true) {
34
37
  if (enable) jsdom_enable();
35
38
  }
36
39
  function jsdom_enable() {
40
+ if (!dom) return;
37
41
  global.Storage = dom.window.Storage;
38
42
  global.window = dom.window;
39
43
  global.history = dom.window.history;
@@ -52,6 +56,8 @@ function jsdom_enable() {
52
56
  global.MutationObserver = dom.window.MutationObserver;
53
57
  }
54
58
  function jsdom_disable() {
59
+ if (disable_disable_flag) return;
60
+ if (!dom) return;
55
61
  global.window = void 0;
56
62
  global.history = void 0;
57
63
  global.document = void 0;
@@ -2504,7 +2510,26 @@ ABConvert.factory({
2504
2510
  sub_button.textContent = "折叠";
2505
2511
  }
2506
2512
  };
2507
- sub_button.onclick = fn_fold;
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
+ }
2508
2533
  mid_el.appendChild(sub_button);
2509
2534
  mid_el.appendChild(sub_el);
2510
2535
  const isListTable = sub_el.classList.contains("ab-list-table-parent");
@@ -1,6 +1,9 @@
1
1
  import MarkdownIt from "markdown-it";
2
2
  let dom = null;
3
- async function jsdom_init(enable = true) {
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;
4
7
  const { default: jsdom } = await import("jsdom");
5
8
  const { JSDOM } = jsdom;
6
9
  dom = new JSDOM(`<!DOCTYPE html><html><body></body></html>`, {
@@ -10,6 +13,7 @@ async function jsdom_init(enable = true) {
10
13
  if (enable) jsdom_enable();
11
14
  }
12
15
  function jsdom_enable() {
16
+ if (!dom) return;
13
17
  global.Storage = dom.window.Storage;
14
18
  global.window = dom.window;
15
19
  global.history = dom.window.history;
@@ -28,6 +32,8 @@ function jsdom_enable() {
28
32
  global.MutationObserver = dom.window.MutationObserver;
29
33
  }
30
34
  function jsdom_disable() {
35
+ if (disable_disable_flag) return;
36
+ if (!dom) return;
31
37
  global.window = void 0;
32
38
  global.history = void 0;
33
39
  global.document = void 0;
@@ -2480,7 +2486,26 @@ ABConvert.factory({
2480
2486
  sub_button.textContent = "折叠";
2481
2487
  }
2482
2488
  };
2483
- sub_button.onclick = fn_fold;
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
+ }
2484
2509
  mid_el.appendChild(sub_button);
2485
2510
  mid_el.appendChild(sub_el);
2486
2511
  const isListTable = sub_el.classList.contains("ab-list-table-parent");
package/jsdom_init.ts CHANGED
@@ -6,9 +6,16 @@
6
6
 
7
7
  // import jsdom from "jsdom"
8
8
 
9
- let dom: any = null;
9
+ let dom: any = null // 缓存 jsdom 实例
10
+ let disable_disable_flag: boolean = false // 禁止禁用
10
11
 
11
- export async function jsdom_init(enable: boolean = true) {
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 环境
12
19
  const { default: jsdom } = await import('jsdom') // 废弃,要同步,避免docuemnt初始化不及时
13
20
  const { JSDOM } = jsdom
14
21
  dom = new JSDOM(`<!DOCTYPE html><html><body></body></html>`, {
@@ -19,6 +26,7 @@ export async function jsdom_init(enable: boolean = true) {
19
26
 
20
27
  /// 启用 jsdom 环境
21
28
  export function jsdom_enable() {
29
+ if (!dom) return // console.error("jsdom_enable failed: please run jsdom_init first.") // 允许客户端中运行,不使用jsdom
22
30
  global.Storage = dom.window.Storage;
23
31
  global.window = dom.window as any
24
32
  global.history = dom.window.history // @warn 若缺少该行,则在mdit+build环境下,编译报错:ReferenceError: history is not defined
@@ -38,6 +46,8 @@ export function jsdom_enable() {
38
46
 
39
47
  /// 禁用 jsdom 环境
40
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
41
51
  global.window = undefined
42
52
  global.history = undefined
43
53
  global.document = undefined
package/package.json CHANGED
@@ -1,45 +1,45 @@
1
- {
2
- "name": "@anyblock/remark-any-block",
3
- "version": "1.0.2",
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
+ }