@anyblock/remark-any-block 1.0.0-beta11 → 1.0.0-beta12
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/anyblock.ts +6 -3
- package/dist/remark-any-block.cjs +196 -197
- package/dist/remark-any-block.js +196 -197
- package/index.ts +1 -1
- package/package.json +1 -1
package/anyblock.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { Plugin } from "unified"
|
|
2
2
|
import { Root, RootContent, Paragraph, Text, Code, Html } from "mdast"
|
|
3
3
|
import type { VFile } from "vfile"
|
|
4
|
-
import { toMarkdown } from "mdast-util-to-markdown"
|
|
5
4
|
import { visit } from "unist-util-visit"
|
|
5
|
+
import { toMarkdown } from "mdast-util-to-markdown" // TODO 这里好像会有 document 依赖
|
|
6
|
+
// 而且不一定能反序列化成功 (有私有节点类型,甚至table类型都不能识别)
|
|
7
|
+
// 后期需要去除此 "修改树" 的 `transformer` / `mdast-util` 插件
|
|
8
|
+
// 修改成 `micromarkExtensions` 形式的插件
|
|
6
9
|
|
|
7
10
|
// 这里不想去依赖 Quartz 项目,所以用any。但是你可以去看具体的类型定义
|
|
8
11
|
// import { type QuartzTransformerPlugin } from "../types"
|
|
@@ -126,8 +129,8 @@ export const remark_anyblock_to_codeblock: Plugin<[Partial<AnyBlockOptions>?], R
|
|
|
126
129
|
node_next.type === "list" ||
|
|
127
130
|
node_next.type === "heading" ||
|
|
128
131
|
node_next.type === "code" ||
|
|
129
|
-
node_next.type === "blockquote"
|
|
130
|
-
node_next.type === "table"
|
|
132
|
+
node_next.type === "blockquote"
|
|
133
|
+
// node_next.type === "table"
|
|
131
134
|
) {
|
|
132
135
|
const codeValue = `[${header}]\n${nodesToMarkdown([node_next])}`;
|
|
133
136
|
out.push({
|
|
@@ -47,6 +47,201 @@ async function jsdom_init() {
|
|
|
47
47
|
};
|
|
48
48
|
global.MutationObserver = dom.window.MutationObserver;
|
|
49
49
|
}
|
|
50
|
+
const convert = (
|
|
51
|
+
// Note: overloads in JSDoc can’t yet use different `@template`s.
|
|
52
|
+
/**
|
|
53
|
+
* @type {(
|
|
54
|
+
* (<Condition extends string>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & {type: Condition}) &
|
|
55
|
+
* (<Condition extends Props>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Condition) &
|
|
56
|
+
* (<Condition extends TestFunction>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Predicate<Condition, Node>) &
|
|
57
|
+
* ((test?: null | undefined) => (node?: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node) &
|
|
58
|
+
* ((test?: Test) => Check)
|
|
59
|
+
* )}
|
|
60
|
+
*/
|
|
61
|
+
/**
|
|
62
|
+
* @param {Test} [test]
|
|
63
|
+
* @returns {Check}
|
|
64
|
+
*/
|
|
65
|
+
(function(test) {
|
|
66
|
+
if (test === null || test === void 0) {
|
|
67
|
+
return ok;
|
|
68
|
+
}
|
|
69
|
+
if (typeof test === "function") {
|
|
70
|
+
return castFactory(test);
|
|
71
|
+
}
|
|
72
|
+
if (typeof test === "object") {
|
|
73
|
+
return Array.isArray(test) ? anyFactory(test) : (
|
|
74
|
+
// Cast because `ReadonlyArray` goes into the above but `isArray`
|
|
75
|
+
// narrows to `Array`.
|
|
76
|
+
propertiesFactory(
|
|
77
|
+
/** @type {Props} */
|
|
78
|
+
test
|
|
79
|
+
)
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
if (typeof test === "string") {
|
|
83
|
+
return typeFactory(test);
|
|
84
|
+
}
|
|
85
|
+
throw new Error("Expected function, string, or object as test");
|
|
86
|
+
})
|
|
87
|
+
);
|
|
88
|
+
function anyFactory(tests) {
|
|
89
|
+
const checks = [];
|
|
90
|
+
let index2 = -1;
|
|
91
|
+
while (++index2 < tests.length) {
|
|
92
|
+
checks[index2] = convert(tests[index2]);
|
|
93
|
+
}
|
|
94
|
+
return castFactory(any);
|
|
95
|
+
function any(...parameters) {
|
|
96
|
+
let index3 = -1;
|
|
97
|
+
while (++index3 < checks.length) {
|
|
98
|
+
if (checks[index3].apply(this, parameters)) return true;
|
|
99
|
+
}
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function propertiesFactory(check) {
|
|
104
|
+
const checkAsRecord = (
|
|
105
|
+
/** @type {Record<string, unknown>} */
|
|
106
|
+
check
|
|
107
|
+
);
|
|
108
|
+
return castFactory(all2);
|
|
109
|
+
function all2(node2) {
|
|
110
|
+
const nodeAsRecord = (
|
|
111
|
+
/** @type {Record<string, unknown>} */
|
|
112
|
+
/** @type {unknown} */
|
|
113
|
+
node2
|
|
114
|
+
);
|
|
115
|
+
let key;
|
|
116
|
+
for (key in check) {
|
|
117
|
+
if (nodeAsRecord[key] !== checkAsRecord[key]) return false;
|
|
118
|
+
}
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function typeFactory(check) {
|
|
123
|
+
return castFactory(type);
|
|
124
|
+
function type(node2) {
|
|
125
|
+
return node2 && node2.type === check;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
function castFactory(testFunction) {
|
|
129
|
+
return check;
|
|
130
|
+
function check(value, index2, parent2) {
|
|
131
|
+
return Boolean(
|
|
132
|
+
looksLikeANode(value) && testFunction.call(
|
|
133
|
+
this,
|
|
134
|
+
value,
|
|
135
|
+
typeof index2 === "number" ? index2 : void 0,
|
|
136
|
+
parent2 || void 0
|
|
137
|
+
)
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
function ok() {
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
function looksLikeANode(value) {
|
|
145
|
+
return value !== null && typeof value === "object" && "type" in value;
|
|
146
|
+
}
|
|
147
|
+
function color(d) {
|
|
148
|
+
return d;
|
|
149
|
+
}
|
|
150
|
+
const empty$1 = [];
|
|
151
|
+
const CONTINUE = true;
|
|
152
|
+
const EXIT = false;
|
|
153
|
+
const SKIP$1 = "skip";
|
|
154
|
+
function visitParents(tree, test, visitor, reverse) {
|
|
155
|
+
let check;
|
|
156
|
+
if (typeof test === "function" && typeof visitor !== "function") {
|
|
157
|
+
reverse = visitor;
|
|
158
|
+
visitor = test;
|
|
159
|
+
} else {
|
|
160
|
+
check = test;
|
|
161
|
+
}
|
|
162
|
+
const is2 = convert(check);
|
|
163
|
+
const step = reverse ? -1 : 1;
|
|
164
|
+
factory(tree, void 0, [])();
|
|
165
|
+
function factory(node2, index2, parents2) {
|
|
166
|
+
const value = (
|
|
167
|
+
/** @type {Record<string, unknown>} */
|
|
168
|
+
node2 && typeof node2 === "object" ? node2 : {}
|
|
169
|
+
);
|
|
170
|
+
if (typeof value.type === "string") {
|
|
171
|
+
const name2 = (
|
|
172
|
+
// `hast`
|
|
173
|
+
typeof value.tagName === "string" ? value.tagName : (
|
|
174
|
+
// `xast`
|
|
175
|
+
typeof value.name === "string" ? value.name : void 0
|
|
176
|
+
)
|
|
177
|
+
);
|
|
178
|
+
Object.defineProperty(visit2, "name", {
|
|
179
|
+
value: "node (" + color(node2.type + (name2 ? "<" + name2 + ">" : "")) + ")"
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
return visit2;
|
|
183
|
+
function visit2() {
|
|
184
|
+
let result = empty$1;
|
|
185
|
+
let subresult;
|
|
186
|
+
let offset2;
|
|
187
|
+
let grandparents;
|
|
188
|
+
if (!test || is2(node2, index2, parents2[parents2.length - 1] || void 0)) {
|
|
189
|
+
result = toResult(visitor(node2, parents2));
|
|
190
|
+
if (result[0] === EXIT) {
|
|
191
|
+
return result;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
if ("children" in node2 && node2.children) {
|
|
195
|
+
const nodeAsParent = (
|
|
196
|
+
/** @type {UnistParent} */
|
|
197
|
+
node2
|
|
198
|
+
);
|
|
199
|
+
if (nodeAsParent.children && result[0] !== SKIP$1) {
|
|
200
|
+
offset2 = (reverse ? nodeAsParent.children.length : -1) + step;
|
|
201
|
+
grandparents = parents2.concat(nodeAsParent);
|
|
202
|
+
while (offset2 > -1 && offset2 < nodeAsParent.children.length) {
|
|
203
|
+
const child = nodeAsParent.children[offset2];
|
|
204
|
+
subresult = factory(child, offset2, grandparents)();
|
|
205
|
+
if (subresult[0] === EXIT) {
|
|
206
|
+
return subresult;
|
|
207
|
+
}
|
|
208
|
+
offset2 = typeof subresult[1] === "number" ? subresult[1] : offset2 + step;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return result;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
function toResult(value) {
|
|
217
|
+
if (Array.isArray(value)) {
|
|
218
|
+
return value;
|
|
219
|
+
}
|
|
220
|
+
if (typeof value === "number") {
|
|
221
|
+
return [CONTINUE, value];
|
|
222
|
+
}
|
|
223
|
+
return value === null || value === void 0 ? empty$1 : [value];
|
|
224
|
+
}
|
|
225
|
+
function visit$1(tree, testOrVisitor, visitorOrReverse, maybeReverse) {
|
|
226
|
+
let reverse;
|
|
227
|
+
let test;
|
|
228
|
+
let visitor;
|
|
229
|
+
if (typeof testOrVisitor === "function" && typeof visitorOrReverse !== "function") {
|
|
230
|
+
test = void 0;
|
|
231
|
+
visitor = testOrVisitor;
|
|
232
|
+
reverse = visitorOrReverse;
|
|
233
|
+
} else {
|
|
234
|
+
test = testOrVisitor;
|
|
235
|
+
visitor = visitorOrReverse;
|
|
236
|
+
reverse = maybeReverse;
|
|
237
|
+
}
|
|
238
|
+
visitParents(tree, test, overload, reverse);
|
|
239
|
+
function overload(node2, parents2) {
|
|
240
|
+
const parent2 = parents2[parents2.length - 1];
|
|
241
|
+
const index2 = parent2 ? parent2.children.indexOf(node2) : void 0;
|
|
242
|
+
return visitor(node2, index2, parent2);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
50
245
|
const own$1 = {}.hasOwnProperty;
|
|
51
246
|
function zwitch(key, options) {
|
|
52
247
|
const settings = options || {};
|
|
@@ -415,201 +610,6 @@ function emphasis(node2, _, state, info) {
|
|
|
415
610
|
function emphasisPeek(_, _1, state) {
|
|
416
611
|
return state.options.emphasis || "*";
|
|
417
612
|
}
|
|
418
|
-
const convert = (
|
|
419
|
-
// Note: overloads in JSDoc can’t yet use different `@template`s.
|
|
420
|
-
/**
|
|
421
|
-
* @type {(
|
|
422
|
-
* (<Condition extends string>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & {type: Condition}) &
|
|
423
|
-
* (<Condition extends Props>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Condition) &
|
|
424
|
-
* (<Condition extends TestFunction>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Predicate<Condition, Node>) &
|
|
425
|
-
* ((test?: null | undefined) => (node?: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node) &
|
|
426
|
-
* ((test?: Test) => Check)
|
|
427
|
-
* )}
|
|
428
|
-
*/
|
|
429
|
-
/**
|
|
430
|
-
* @param {Test} [test]
|
|
431
|
-
* @returns {Check}
|
|
432
|
-
*/
|
|
433
|
-
(function(test) {
|
|
434
|
-
if (test === null || test === void 0) {
|
|
435
|
-
return ok;
|
|
436
|
-
}
|
|
437
|
-
if (typeof test === "function") {
|
|
438
|
-
return castFactory(test);
|
|
439
|
-
}
|
|
440
|
-
if (typeof test === "object") {
|
|
441
|
-
return Array.isArray(test) ? anyFactory(test) : (
|
|
442
|
-
// Cast because `ReadonlyArray` goes into the above but `isArray`
|
|
443
|
-
// narrows to `Array`.
|
|
444
|
-
propertiesFactory(
|
|
445
|
-
/** @type {Props} */
|
|
446
|
-
test
|
|
447
|
-
)
|
|
448
|
-
);
|
|
449
|
-
}
|
|
450
|
-
if (typeof test === "string") {
|
|
451
|
-
return typeFactory(test);
|
|
452
|
-
}
|
|
453
|
-
throw new Error("Expected function, string, or object as test");
|
|
454
|
-
})
|
|
455
|
-
);
|
|
456
|
-
function anyFactory(tests) {
|
|
457
|
-
const checks = [];
|
|
458
|
-
let index2 = -1;
|
|
459
|
-
while (++index2 < tests.length) {
|
|
460
|
-
checks[index2] = convert(tests[index2]);
|
|
461
|
-
}
|
|
462
|
-
return castFactory(any);
|
|
463
|
-
function any(...parameters) {
|
|
464
|
-
let index3 = -1;
|
|
465
|
-
while (++index3 < checks.length) {
|
|
466
|
-
if (checks[index3].apply(this, parameters)) return true;
|
|
467
|
-
}
|
|
468
|
-
return false;
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
function propertiesFactory(check) {
|
|
472
|
-
const checkAsRecord = (
|
|
473
|
-
/** @type {Record<string, unknown>} */
|
|
474
|
-
check
|
|
475
|
-
);
|
|
476
|
-
return castFactory(all2);
|
|
477
|
-
function all2(node2) {
|
|
478
|
-
const nodeAsRecord = (
|
|
479
|
-
/** @type {Record<string, unknown>} */
|
|
480
|
-
/** @type {unknown} */
|
|
481
|
-
node2
|
|
482
|
-
);
|
|
483
|
-
let key;
|
|
484
|
-
for (key in check) {
|
|
485
|
-
if (nodeAsRecord[key] !== checkAsRecord[key]) return false;
|
|
486
|
-
}
|
|
487
|
-
return true;
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
function typeFactory(check) {
|
|
491
|
-
return castFactory(type);
|
|
492
|
-
function type(node2) {
|
|
493
|
-
return node2 && node2.type === check;
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
function castFactory(testFunction) {
|
|
497
|
-
return check;
|
|
498
|
-
function check(value, index2, parent2) {
|
|
499
|
-
return Boolean(
|
|
500
|
-
looksLikeANode(value) && testFunction.call(
|
|
501
|
-
this,
|
|
502
|
-
value,
|
|
503
|
-
typeof index2 === "number" ? index2 : void 0,
|
|
504
|
-
parent2 || void 0
|
|
505
|
-
)
|
|
506
|
-
);
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
function ok() {
|
|
510
|
-
return true;
|
|
511
|
-
}
|
|
512
|
-
function looksLikeANode(value) {
|
|
513
|
-
return value !== null && typeof value === "object" && "type" in value;
|
|
514
|
-
}
|
|
515
|
-
function color(d) {
|
|
516
|
-
return d;
|
|
517
|
-
}
|
|
518
|
-
const empty$1 = [];
|
|
519
|
-
const CONTINUE = true;
|
|
520
|
-
const EXIT = false;
|
|
521
|
-
const SKIP$1 = "skip";
|
|
522
|
-
function visitParents(tree, test, visitor, reverse) {
|
|
523
|
-
let check;
|
|
524
|
-
if (typeof test === "function" && typeof visitor !== "function") {
|
|
525
|
-
reverse = visitor;
|
|
526
|
-
visitor = test;
|
|
527
|
-
} else {
|
|
528
|
-
check = test;
|
|
529
|
-
}
|
|
530
|
-
const is2 = convert(check);
|
|
531
|
-
const step = reverse ? -1 : 1;
|
|
532
|
-
factory(tree, void 0, [])();
|
|
533
|
-
function factory(node2, index2, parents2) {
|
|
534
|
-
const value = (
|
|
535
|
-
/** @type {Record<string, unknown>} */
|
|
536
|
-
node2 && typeof node2 === "object" ? node2 : {}
|
|
537
|
-
);
|
|
538
|
-
if (typeof value.type === "string") {
|
|
539
|
-
const name2 = (
|
|
540
|
-
// `hast`
|
|
541
|
-
typeof value.tagName === "string" ? value.tagName : (
|
|
542
|
-
// `xast`
|
|
543
|
-
typeof value.name === "string" ? value.name : void 0
|
|
544
|
-
)
|
|
545
|
-
);
|
|
546
|
-
Object.defineProperty(visit2, "name", {
|
|
547
|
-
value: "node (" + color(node2.type + (name2 ? "<" + name2 + ">" : "")) + ")"
|
|
548
|
-
});
|
|
549
|
-
}
|
|
550
|
-
return visit2;
|
|
551
|
-
function visit2() {
|
|
552
|
-
let result = empty$1;
|
|
553
|
-
let subresult;
|
|
554
|
-
let offset2;
|
|
555
|
-
let grandparents;
|
|
556
|
-
if (!test || is2(node2, index2, parents2[parents2.length - 1] || void 0)) {
|
|
557
|
-
result = toResult(visitor(node2, parents2));
|
|
558
|
-
if (result[0] === EXIT) {
|
|
559
|
-
return result;
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
if ("children" in node2 && node2.children) {
|
|
563
|
-
const nodeAsParent = (
|
|
564
|
-
/** @type {UnistParent} */
|
|
565
|
-
node2
|
|
566
|
-
);
|
|
567
|
-
if (nodeAsParent.children && result[0] !== SKIP$1) {
|
|
568
|
-
offset2 = (reverse ? nodeAsParent.children.length : -1) + step;
|
|
569
|
-
grandparents = parents2.concat(nodeAsParent);
|
|
570
|
-
while (offset2 > -1 && offset2 < nodeAsParent.children.length) {
|
|
571
|
-
const child = nodeAsParent.children[offset2];
|
|
572
|
-
subresult = factory(child, offset2, grandparents)();
|
|
573
|
-
if (subresult[0] === EXIT) {
|
|
574
|
-
return subresult;
|
|
575
|
-
}
|
|
576
|
-
offset2 = typeof subresult[1] === "number" ? subresult[1] : offset2 + step;
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
return result;
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
function toResult(value) {
|
|
585
|
-
if (Array.isArray(value)) {
|
|
586
|
-
return value;
|
|
587
|
-
}
|
|
588
|
-
if (typeof value === "number") {
|
|
589
|
-
return [CONTINUE, value];
|
|
590
|
-
}
|
|
591
|
-
return value === null || value === void 0 ? empty$1 : [value];
|
|
592
|
-
}
|
|
593
|
-
function visit$1(tree, testOrVisitor, visitorOrReverse, maybeReverse) {
|
|
594
|
-
let reverse;
|
|
595
|
-
let test;
|
|
596
|
-
let visitor;
|
|
597
|
-
if (typeof testOrVisitor === "function" && typeof visitorOrReverse !== "function") {
|
|
598
|
-
test = void 0;
|
|
599
|
-
visitor = testOrVisitor;
|
|
600
|
-
reverse = visitorOrReverse;
|
|
601
|
-
} else {
|
|
602
|
-
test = testOrVisitor;
|
|
603
|
-
visitor = visitorOrReverse;
|
|
604
|
-
reverse = maybeReverse;
|
|
605
|
-
}
|
|
606
|
-
visitParents(tree, test, overload, reverse);
|
|
607
|
-
function overload(node2, parents2) {
|
|
608
|
-
const parent2 = parents2[parents2.length - 1];
|
|
609
|
-
const index2 = parent2 ? parent2.children.indexOf(node2) : void 0;
|
|
610
|
-
return visitor(node2, index2, parent2);
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
613
|
const emptyOptions = {};
|
|
614
614
|
function toString$1(value, options) {
|
|
615
615
|
const settings = emptyOptions;
|
|
@@ -51117,7 +51117,7 @@ const remark_anyblock_to_codeblock = (_options = {}) => (tree) => {
|
|
|
51117
51117
|
const header = matchAbHeader(node2);
|
|
51118
51118
|
if (header) {
|
|
51119
51119
|
const node_next = children2[i + 1];
|
|
51120
|
-
if (node_next.type === "list" || node_next.type === "heading" || node_next.type === "code" || node_next.type === "blockquote"
|
|
51120
|
+
if (node_next.type === "list" || node_next.type === "heading" || node_next.type === "code" || node_next.type === "blockquote") {
|
|
51121
51121
|
const codeValue = `[${header}]
|
|
51122
51122
|
${nodesToMarkdown([node_next])}`;
|
|
51123
51123
|
out.push({
|
|
@@ -51211,6 +51211,5 @@ exports.ABConvertManager = ABConvertManager;
|
|
|
51211
51211
|
exports.abConvertEvent = abConvertEvent;
|
|
51212
51212
|
exports.jsdom_init = jsdom_init;
|
|
51213
51213
|
exports.remark_anyblock_render_codeblock = remark_anyblock_render_codeblock;
|
|
51214
|
-
exports.remark_anyblock_to_codeblock = remark_anyblock_to_codeblock;
|
|
51215
51214
|
exports.transformer_anyblock = transformer_anyblock;
|
|
51216
51215
|
//# sourceMappingURL=remark-any-block.cjs.map
|
package/dist/remark-any-block.js
CHANGED
|
@@ -23,6 +23,201 @@ async function jsdom_init() {
|
|
|
23
23
|
};
|
|
24
24
|
global.MutationObserver = dom.window.MutationObserver;
|
|
25
25
|
}
|
|
26
|
+
const convert = (
|
|
27
|
+
// Note: overloads in JSDoc can’t yet use different `@template`s.
|
|
28
|
+
/**
|
|
29
|
+
* @type {(
|
|
30
|
+
* (<Condition extends string>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & {type: Condition}) &
|
|
31
|
+
* (<Condition extends Props>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Condition) &
|
|
32
|
+
* (<Condition extends TestFunction>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Predicate<Condition, Node>) &
|
|
33
|
+
* ((test?: null | undefined) => (node?: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node) &
|
|
34
|
+
* ((test?: Test) => Check)
|
|
35
|
+
* )}
|
|
36
|
+
*/
|
|
37
|
+
/**
|
|
38
|
+
* @param {Test} [test]
|
|
39
|
+
* @returns {Check}
|
|
40
|
+
*/
|
|
41
|
+
(function(test) {
|
|
42
|
+
if (test === null || test === void 0) {
|
|
43
|
+
return ok;
|
|
44
|
+
}
|
|
45
|
+
if (typeof test === "function") {
|
|
46
|
+
return castFactory(test);
|
|
47
|
+
}
|
|
48
|
+
if (typeof test === "object") {
|
|
49
|
+
return Array.isArray(test) ? anyFactory(test) : (
|
|
50
|
+
// Cast because `ReadonlyArray` goes into the above but `isArray`
|
|
51
|
+
// narrows to `Array`.
|
|
52
|
+
propertiesFactory(
|
|
53
|
+
/** @type {Props} */
|
|
54
|
+
test
|
|
55
|
+
)
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
if (typeof test === "string") {
|
|
59
|
+
return typeFactory(test);
|
|
60
|
+
}
|
|
61
|
+
throw new Error("Expected function, string, or object as test");
|
|
62
|
+
})
|
|
63
|
+
);
|
|
64
|
+
function anyFactory(tests) {
|
|
65
|
+
const checks = [];
|
|
66
|
+
let index2 = -1;
|
|
67
|
+
while (++index2 < tests.length) {
|
|
68
|
+
checks[index2] = convert(tests[index2]);
|
|
69
|
+
}
|
|
70
|
+
return castFactory(any);
|
|
71
|
+
function any(...parameters) {
|
|
72
|
+
let index3 = -1;
|
|
73
|
+
while (++index3 < checks.length) {
|
|
74
|
+
if (checks[index3].apply(this, parameters)) return true;
|
|
75
|
+
}
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function propertiesFactory(check) {
|
|
80
|
+
const checkAsRecord = (
|
|
81
|
+
/** @type {Record<string, unknown>} */
|
|
82
|
+
check
|
|
83
|
+
);
|
|
84
|
+
return castFactory(all2);
|
|
85
|
+
function all2(node2) {
|
|
86
|
+
const nodeAsRecord = (
|
|
87
|
+
/** @type {Record<string, unknown>} */
|
|
88
|
+
/** @type {unknown} */
|
|
89
|
+
node2
|
|
90
|
+
);
|
|
91
|
+
let key;
|
|
92
|
+
for (key in check) {
|
|
93
|
+
if (nodeAsRecord[key] !== checkAsRecord[key]) return false;
|
|
94
|
+
}
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function typeFactory(check) {
|
|
99
|
+
return castFactory(type);
|
|
100
|
+
function type(node2) {
|
|
101
|
+
return node2 && node2.type === check;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function castFactory(testFunction) {
|
|
105
|
+
return check;
|
|
106
|
+
function check(value, index2, parent2) {
|
|
107
|
+
return Boolean(
|
|
108
|
+
looksLikeANode(value) && testFunction.call(
|
|
109
|
+
this,
|
|
110
|
+
value,
|
|
111
|
+
typeof index2 === "number" ? index2 : void 0,
|
|
112
|
+
parent2 || void 0
|
|
113
|
+
)
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function ok() {
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
function looksLikeANode(value) {
|
|
121
|
+
return value !== null && typeof value === "object" && "type" in value;
|
|
122
|
+
}
|
|
123
|
+
function color(d) {
|
|
124
|
+
return d;
|
|
125
|
+
}
|
|
126
|
+
const empty$1 = [];
|
|
127
|
+
const CONTINUE = true;
|
|
128
|
+
const EXIT = false;
|
|
129
|
+
const SKIP$1 = "skip";
|
|
130
|
+
function visitParents(tree, test, visitor, reverse) {
|
|
131
|
+
let check;
|
|
132
|
+
if (typeof test === "function" && typeof visitor !== "function") {
|
|
133
|
+
reverse = visitor;
|
|
134
|
+
visitor = test;
|
|
135
|
+
} else {
|
|
136
|
+
check = test;
|
|
137
|
+
}
|
|
138
|
+
const is2 = convert(check);
|
|
139
|
+
const step = reverse ? -1 : 1;
|
|
140
|
+
factory(tree, void 0, [])();
|
|
141
|
+
function factory(node2, index2, parents2) {
|
|
142
|
+
const value = (
|
|
143
|
+
/** @type {Record<string, unknown>} */
|
|
144
|
+
node2 && typeof node2 === "object" ? node2 : {}
|
|
145
|
+
);
|
|
146
|
+
if (typeof value.type === "string") {
|
|
147
|
+
const name2 = (
|
|
148
|
+
// `hast`
|
|
149
|
+
typeof value.tagName === "string" ? value.tagName : (
|
|
150
|
+
// `xast`
|
|
151
|
+
typeof value.name === "string" ? value.name : void 0
|
|
152
|
+
)
|
|
153
|
+
);
|
|
154
|
+
Object.defineProperty(visit2, "name", {
|
|
155
|
+
value: "node (" + color(node2.type + (name2 ? "<" + name2 + ">" : "")) + ")"
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
return visit2;
|
|
159
|
+
function visit2() {
|
|
160
|
+
let result = empty$1;
|
|
161
|
+
let subresult;
|
|
162
|
+
let offset2;
|
|
163
|
+
let grandparents;
|
|
164
|
+
if (!test || is2(node2, index2, parents2[parents2.length - 1] || void 0)) {
|
|
165
|
+
result = toResult(visitor(node2, parents2));
|
|
166
|
+
if (result[0] === EXIT) {
|
|
167
|
+
return result;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if ("children" in node2 && node2.children) {
|
|
171
|
+
const nodeAsParent = (
|
|
172
|
+
/** @type {UnistParent} */
|
|
173
|
+
node2
|
|
174
|
+
);
|
|
175
|
+
if (nodeAsParent.children && result[0] !== SKIP$1) {
|
|
176
|
+
offset2 = (reverse ? nodeAsParent.children.length : -1) + step;
|
|
177
|
+
grandparents = parents2.concat(nodeAsParent);
|
|
178
|
+
while (offset2 > -1 && offset2 < nodeAsParent.children.length) {
|
|
179
|
+
const child = nodeAsParent.children[offset2];
|
|
180
|
+
subresult = factory(child, offset2, grandparents)();
|
|
181
|
+
if (subresult[0] === EXIT) {
|
|
182
|
+
return subresult;
|
|
183
|
+
}
|
|
184
|
+
offset2 = typeof subresult[1] === "number" ? subresult[1] : offset2 + step;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return result;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
function toResult(value) {
|
|
193
|
+
if (Array.isArray(value)) {
|
|
194
|
+
return value;
|
|
195
|
+
}
|
|
196
|
+
if (typeof value === "number") {
|
|
197
|
+
return [CONTINUE, value];
|
|
198
|
+
}
|
|
199
|
+
return value === null || value === void 0 ? empty$1 : [value];
|
|
200
|
+
}
|
|
201
|
+
function visit$1(tree, testOrVisitor, visitorOrReverse, maybeReverse) {
|
|
202
|
+
let reverse;
|
|
203
|
+
let test;
|
|
204
|
+
let visitor;
|
|
205
|
+
if (typeof testOrVisitor === "function" && typeof visitorOrReverse !== "function") {
|
|
206
|
+
test = void 0;
|
|
207
|
+
visitor = testOrVisitor;
|
|
208
|
+
reverse = visitorOrReverse;
|
|
209
|
+
} else {
|
|
210
|
+
test = testOrVisitor;
|
|
211
|
+
visitor = visitorOrReverse;
|
|
212
|
+
reverse = maybeReverse;
|
|
213
|
+
}
|
|
214
|
+
visitParents(tree, test, overload, reverse);
|
|
215
|
+
function overload(node2, parents2) {
|
|
216
|
+
const parent2 = parents2[parents2.length - 1];
|
|
217
|
+
const index2 = parent2 ? parent2.children.indexOf(node2) : void 0;
|
|
218
|
+
return visitor(node2, index2, parent2);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
26
221
|
const own$1 = {}.hasOwnProperty;
|
|
27
222
|
function zwitch(key, options) {
|
|
28
223
|
const settings = options || {};
|
|
@@ -391,201 +586,6 @@ function emphasis(node2, _, state, info) {
|
|
|
391
586
|
function emphasisPeek(_, _1, state) {
|
|
392
587
|
return state.options.emphasis || "*";
|
|
393
588
|
}
|
|
394
|
-
const convert = (
|
|
395
|
-
// Note: overloads in JSDoc can’t yet use different `@template`s.
|
|
396
|
-
/**
|
|
397
|
-
* @type {(
|
|
398
|
-
* (<Condition extends string>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & {type: Condition}) &
|
|
399
|
-
* (<Condition extends Props>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Condition) &
|
|
400
|
-
* (<Condition extends TestFunction>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Predicate<Condition, Node>) &
|
|
401
|
-
* ((test?: null | undefined) => (node?: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node) &
|
|
402
|
-
* ((test?: Test) => Check)
|
|
403
|
-
* )}
|
|
404
|
-
*/
|
|
405
|
-
/**
|
|
406
|
-
* @param {Test} [test]
|
|
407
|
-
* @returns {Check}
|
|
408
|
-
*/
|
|
409
|
-
(function(test) {
|
|
410
|
-
if (test === null || test === void 0) {
|
|
411
|
-
return ok;
|
|
412
|
-
}
|
|
413
|
-
if (typeof test === "function") {
|
|
414
|
-
return castFactory(test);
|
|
415
|
-
}
|
|
416
|
-
if (typeof test === "object") {
|
|
417
|
-
return Array.isArray(test) ? anyFactory(test) : (
|
|
418
|
-
// Cast because `ReadonlyArray` goes into the above but `isArray`
|
|
419
|
-
// narrows to `Array`.
|
|
420
|
-
propertiesFactory(
|
|
421
|
-
/** @type {Props} */
|
|
422
|
-
test
|
|
423
|
-
)
|
|
424
|
-
);
|
|
425
|
-
}
|
|
426
|
-
if (typeof test === "string") {
|
|
427
|
-
return typeFactory(test);
|
|
428
|
-
}
|
|
429
|
-
throw new Error("Expected function, string, or object as test");
|
|
430
|
-
})
|
|
431
|
-
);
|
|
432
|
-
function anyFactory(tests) {
|
|
433
|
-
const checks = [];
|
|
434
|
-
let index2 = -1;
|
|
435
|
-
while (++index2 < tests.length) {
|
|
436
|
-
checks[index2] = convert(tests[index2]);
|
|
437
|
-
}
|
|
438
|
-
return castFactory(any);
|
|
439
|
-
function any(...parameters) {
|
|
440
|
-
let index3 = -1;
|
|
441
|
-
while (++index3 < checks.length) {
|
|
442
|
-
if (checks[index3].apply(this, parameters)) return true;
|
|
443
|
-
}
|
|
444
|
-
return false;
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
function propertiesFactory(check) {
|
|
448
|
-
const checkAsRecord = (
|
|
449
|
-
/** @type {Record<string, unknown>} */
|
|
450
|
-
check
|
|
451
|
-
);
|
|
452
|
-
return castFactory(all2);
|
|
453
|
-
function all2(node2) {
|
|
454
|
-
const nodeAsRecord = (
|
|
455
|
-
/** @type {Record<string, unknown>} */
|
|
456
|
-
/** @type {unknown} */
|
|
457
|
-
node2
|
|
458
|
-
);
|
|
459
|
-
let key;
|
|
460
|
-
for (key in check) {
|
|
461
|
-
if (nodeAsRecord[key] !== checkAsRecord[key]) return false;
|
|
462
|
-
}
|
|
463
|
-
return true;
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
function typeFactory(check) {
|
|
467
|
-
return castFactory(type);
|
|
468
|
-
function type(node2) {
|
|
469
|
-
return node2 && node2.type === check;
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
function castFactory(testFunction) {
|
|
473
|
-
return check;
|
|
474
|
-
function check(value, index2, parent2) {
|
|
475
|
-
return Boolean(
|
|
476
|
-
looksLikeANode(value) && testFunction.call(
|
|
477
|
-
this,
|
|
478
|
-
value,
|
|
479
|
-
typeof index2 === "number" ? index2 : void 0,
|
|
480
|
-
parent2 || void 0
|
|
481
|
-
)
|
|
482
|
-
);
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
function ok() {
|
|
486
|
-
return true;
|
|
487
|
-
}
|
|
488
|
-
function looksLikeANode(value) {
|
|
489
|
-
return value !== null && typeof value === "object" && "type" in value;
|
|
490
|
-
}
|
|
491
|
-
function color(d) {
|
|
492
|
-
return d;
|
|
493
|
-
}
|
|
494
|
-
const empty$1 = [];
|
|
495
|
-
const CONTINUE = true;
|
|
496
|
-
const EXIT = false;
|
|
497
|
-
const SKIP$1 = "skip";
|
|
498
|
-
function visitParents(tree, test, visitor, reverse) {
|
|
499
|
-
let check;
|
|
500
|
-
if (typeof test === "function" && typeof visitor !== "function") {
|
|
501
|
-
reverse = visitor;
|
|
502
|
-
visitor = test;
|
|
503
|
-
} else {
|
|
504
|
-
check = test;
|
|
505
|
-
}
|
|
506
|
-
const is2 = convert(check);
|
|
507
|
-
const step = reverse ? -1 : 1;
|
|
508
|
-
factory(tree, void 0, [])();
|
|
509
|
-
function factory(node2, index2, parents2) {
|
|
510
|
-
const value = (
|
|
511
|
-
/** @type {Record<string, unknown>} */
|
|
512
|
-
node2 && typeof node2 === "object" ? node2 : {}
|
|
513
|
-
);
|
|
514
|
-
if (typeof value.type === "string") {
|
|
515
|
-
const name2 = (
|
|
516
|
-
// `hast`
|
|
517
|
-
typeof value.tagName === "string" ? value.tagName : (
|
|
518
|
-
// `xast`
|
|
519
|
-
typeof value.name === "string" ? value.name : void 0
|
|
520
|
-
)
|
|
521
|
-
);
|
|
522
|
-
Object.defineProperty(visit2, "name", {
|
|
523
|
-
value: "node (" + color(node2.type + (name2 ? "<" + name2 + ">" : "")) + ")"
|
|
524
|
-
});
|
|
525
|
-
}
|
|
526
|
-
return visit2;
|
|
527
|
-
function visit2() {
|
|
528
|
-
let result = empty$1;
|
|
529
|
-
let subresult;
|
|
530
|
-
let offset2;
|
|
531
|
-
let grandparents;
|
|
532
|
-
if (!test || is2(node2, index2, parents2[parents2.length - 1] || void 0)) {
|
|
533
|
-
result = toResult(visitor(node2, parents2));
|
|
534
|
-
if (result[0] === EXIT) {
|
|
535
|
-
return result;
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
if ("children" in node2 && node2.children) {
|
|
539
|
-
const nodeAsParent = (
|
|
540
|
-
/** @type {UnistParent} */
|
|
541
|
-
node2
|
|
542
|
-
);
|
|
543
|
-
if (nodeAsParent.children && result[0] !== SKIP$1) {
|
|
544
|
-
offset2 = (reverse ? nodeAsParent.children.length : -1) + step;
|
|
545
|
-
grandparents = parents2.concat(nodeAsParent);
|
|
546
|
-
while (offset2 > -1 && offset2 < nodeAsParent.children.length) {
|
|
547
|
-
const child = nodeAsParent.children[offset2];
|
|
548
|
-
subresult = factory(child, offset2, grandparents)();
|
|
549
|
-
if (subresult[0] === EXIT) {
|
|
550
|
-
return subresult;
|
|
551
|
-
}
|
|
552
|
-
offset2 = typeof subresult[1] === "number" ? subresult[1] : offset2 + step;
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
return result;
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
function toResult(value) {
|
|
561
|
-
if (Array.isArray(value)) {
|
|
562
|
-
return value;
|
|
563
|
-
}
|
|
564
|
-
if (typeof value === "number") {
|
|
565
|
-
return [CONTINUE, value];
|
|
566
|
-
}
|
|
567
|
-
return value === null || value === void 0 ? empty$1 : [value];
|
|
568
|
-
}
|
|
569
|
-
function visit$1(tree, testOrVisitor, visitorOrReverse, maybeReverse) {
|
|
570
|
-
let reverse;
|
|
571
|
-
let test;
|
|
572
|
-
let visitor;
|
|
573
|
-
if (typeof testOrVisitor === "function" && typeof visitorOrReverse !== "function") {
|
|
574
|
-
test = void 0;
|
|
575
|
-
visitor = testOrVisitor;
|
|
576
|
-
reverse = visitorOrReverse;
|
|
577
|
-
} else {
|
|
578
|
-
test = testOrVisitor;
|
|
579
|
-
visitor = visitorOrReverse;
|
|
580
|
-
reverse = maybeReverse;
|
|
581
|
-
}
|
|
582
|
-
visitParents(tree, test, overload, reverse);
|
|
583
|
-
function overload(node2, parents2) {
|
|
584
|
-
const parent2 = parents2[parents2.length - 1];
|
|
585
|
-
const index2 = parent2 ? parent2.children.indexOf(node2) : void 0;
|
|
586
|
-
return visitor(node2, index2, parent2);
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
589
|
const emptyOptions = {};
|
|
590
590
|
function toString$1(value, options) {
|
|
591
591
|
const settings = emptyOptions;
|
|
@@ -51093,7 +51093,7 @@ const remark_anyblock_to_codeblock = (_options = {}) => (tree) => {
|
|
|
51093
51093
|
const header = matchAbHeader(node2);
|
|
51094
51094
|
if (header) {
|
|
51095
51095
|
const node_next = children2[i + 1];
|
|
51096
|
-
if (node_next.type === "list" || node_next.type === "heading" || node_next.type === "code" || node_next.type === "blockquote"
|
|
51096
|
+
if (node_next.type === "list" || node_next.type === "heading" || node_next.type === "code" || node_next.type === "blockquote") {
|
|
51097
51097
|
const codeValue = `[${header}]
|
|
51098
51098
|
${nodesToMarkdown([node_next])}`;
|
|
51099
51099
|
out.push({
|
|
@@ -51188,7 +51188,6 @@ export {
|
|
|
51188
51188
|
abConvertEvent,
|
|
51189
51189
|
jsdom_init,
|
|
51190
51190
|
remark_anyblock_render_codeblock,
|
|
51191
|
-
remark_anyblock_to_codeblock,
|
|
51192
51191
|
transformer_anyblock
|
|
51193
51192
|
};
|
|
51194
51193
|
//# sourceMappingURL=remark-any-block.js.map
|
package/index.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
export { jsdom_init } from './jsdom_init'
|
|
3
3
|
export {
|
|
4
4
|
transformer_anyblock,
|
|
5
|
-
remark_anyblock_to_codeblock,
|
|
5
|
+
// remark_anyblock_to_codeblock,
|
|
6
6
|
remark_anyblock_render_codeblock,
|
|
7
7
|
} from './anyblock'
|
|
8
8
|
export { abConvertEvent } from '../ABConverter/ABConvertEvent'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anyblock/remark-any-block",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-beta12",
|
|
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",
|