@ox-content/unplugin 3.0.0 → 3.1.1-beta.0
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/dist/index.d.mts +17 -0
- package/dist/src.mjs +36 -10
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -46,6 +46,7 @@ interface MdastNode {
|
|
|
46
46
|
align?: Array<"left" | "center" | "right" | null>;
|
|
47
47
|
identifier?: string;
|
|
48
48
|
label?: string;
|
|
49
|
+
data?: Record<string, unknown>;
|
|
49
50
|
[key: string]: unknown;
|
|
50
51
|
}
|
|
51
52
|
/**
|
|
@@ -325,6 +326,11 @@ interface OxContentOptions {
|
|
|
325
326
|
* @default false
|
|
326
327
|
*/
|
|
327
328
|
smartPunctuation?: boolean;
|
|
329
|
+
/**
|
|
330
|
+
* Enable Pandoc-style heading attribute blocks.
|
|
331
|
+
* @default false
|
|
332
|
+
*/
|
|
333
|
+
headingAttributes?: boolean;
|
|
328
334
|
/**
|
|
329
335
|
* Enable syntax highlighting for code blocks.
|
|
330
336
|
* @default false
|
|
@@ -439,6 +445,7 @@ interface ResolvedOptions {
|
|
|
439
445
|
superscript: boolean;
|
|
440
446
|
subscript: boolean;
|
|
441
447
|
smartPunctuation: boolean;
|
|
448
|
+
headingAttributes: boolean;
|
|
442
449
|
highlight: boolean;
|
|
443
450
|
codeAnnotations: ResolvedCodeAnnotationsOptions;
|
|
444
451
|
mermaid: boolean;
|
|
@@ -547,6 +554,16 @@ interface OxContentMdastOptions {
|
|
|
547
554
|
* @default false
|
|
548
555
|
*/
|
|
549
556
|
definitionLists?: boolean;
|
|
557
|
+
/**
|
|
558
|
+
* Enable Pandoc-style heading attribute blocks.
|
|
559
|
+
* @default false
|
|
560
|
+
*/
|
|
561
|
+
headingAttributes?: boolean;
|
|
562
|
+
/**
|
|
563
|
+
* Enable Obsidian-style wiki links as link nodes.
|
|
564
|
+
* @default false
|
|
565
|
+
*/
|
|
566
|
+
wikiLinks?: boolean;
|
|
550
567
|
}
|
|
551
568
|
//#endregion
|
|
552
569
|
//#region src/mdast.d.ts
|
package/dist/src.mjs
CHANGED
|
@@ -175,12 +175,21 @@ function deserializeMdastFromRaw(buffer, source) {
|
|
|
175
175
|
children: children ?? [],
|
|
176
176
|
position
|
|
177
177
|
};
|
|
178
|
-
case KIND_HEADING:
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
178
|
+
case KIND_HEADING: {
|
|
179
|
+
const node = {
|
|
180
|
+
type: "heading",
|
|
181
|
+
depth: num0,
|
|
182
|
+
children: children ?? [],
|
|
183
|
+
position
|
|
184
|
+
};
|
|
185
|
+
if (str0 !== void 0 || str1 !== void 0) {
|
|
186
|
+
const hProperties = {};
|
|
187
|
+
if (str0 !== void 0) hProperties.id = str0;
|
|
188
|
+
if (str1 !== void 0) hProperties.className = str1.split(/\s+/).filter(Boolean);
|
|
189
|
+
node.data = { hProperties };
|
|
190
|
+
}
|
|
191
|
+
return node;
|
|
192
|
+
}
|
|
184
193
|
case KIND_THEMATIC_BREAK: return {
|
|
185
194
|
type: "thematicBreak",
|
|
186
195
|
position
|
|
@@ -546,7 +555,9 @@ const DEFAULT_MDAST_OPTIONS = {
|
|
|
546
555
|
subscript: false,
|
|
547
556
|
smartPunctuation: false,
|
|
548
557
|
math: false,
|
|
549
|
-
definitionLists: false
|
|
558
|
+
definitionLists: false,
|
|
559
|
+
headingAttributes: false,
|
|
560
|
+
wikiLinks: false
|
|
550
561
|
};
|
|
551
562
|
function resolveMdastOptions(options) {
|
|
552
563
|
return {
|
|
@@ -561,7 +572,9 @@ function resolveMdastOptions(options) {
|
|
|
561
572
|
subscript: options.subscript ?? DEFAULT_MDAST_OPTIONS.subscript,
|
|
562
573
|
smartPunctuation: options.smartPunctuation ?? DEFAULT_MDAST_OPTIONS.smartPunctuation,
|
|
563
574
|
math: options.math ?? DEFAULT_MDAST_OPTIONS.math,
|
|
564
|
-
definitionLists: options.definitionLists ?? DEFAULT_MDAST_OPTIONS.definitionLists
|
|
575
|
+
definitionLists: options.definitionLists ?? DEFAULT_MDAST_OPTIONS.definitionLists,
|
|
576
|
+
headingAttributes: options.headingAttributes ?? DEFAULT_MDAST_OPTIONS.headingAttributes,
|
|
577
|
+
wikiLinks: options.wikiLinks ?? DEFAULT_MDAST_OPTIONS.wikiLinks
|
|
565
578
|
};
|
|
566
579
|
}
|
|
567
580
|
//#endregion
|
|
@@ -604,7 +617,9 @@ function parseMarkdownToMdast(source, options = {}) {
|
|
|
604
617
|
subscript: resolvedOptions.subscript,
|
|
605
618
|
smartPunctuation: resolvedOptions.smartPunctuation,
|
|
606
619
|
math: resolvedOptions.math,
|
|
607
|
-
definitionLists: resolvedOptions.definitionLists
|
|
620
|
+
definitionLists: resolvedOptions.definitionLists,
|
|
621
|
+
headingAttributes: resolvedOptions.headingAttributes,
|
|
622
|
+
wikiLinks: resolvedOptions.wikiLinks
|
|
608
623
|
};
|
|
609
624
|
return deserializeMdastFromRaw(requireNapiMethod$1(napi.parseTransferRaw, "parseTransferRaw")(source, "mdast", parserOptions), source);
|
|
610
625
|
}
|
|
@@ -631,7 +646,7 @@ function extractTocFromMdast(root, maxDepth) {
|
|
|
631
646
|
headings.push({
|
|
632
647
|
depth,
|
|
633
648
|
text,
|
|
634
|
-
slug: slugify$1(text),
|
|
649
|
+
slug: explicitHeadingId(node) ?? slugify$1(text),
|
|
635
650
|
children: []
|
|
636
651
|
});
|
|
637
652
|
});
|
|
@@ -693,6 +708,14 @@ function collectMdastText(node) {
|
|
|
693
708
|
if (!Array.isArray(node.children)) return "";
|
|
694
709
|
return node.children.map((child) => collectMdastText(child)).join("");
|
|
695
710
|
}
|
|
711
|
+
function explicitHeadingId(node) {
|
|
712
|
+
const data = node.data;
|
|
713
|
+
if (!data || typeof data !== "object" || Array.isArray(data)) return;
|
|
714
|
+
const hProperties = data.hProperties;
|
|
715
|
+
if (!hProperties || typeof hProperties !== "object" || Array.isArray(hProperties)) return;
|
|
716
|
+
const id = hProperties.id;
|
|
717
|
+
return typeof id === "string" && id.length > 0 ? id : void 0;
|
|
718
|
+
}
|
|
696
719
|
function slugify$1(text) {
|
|
697
720
|
return text.toLowerCase().replace(/[^\p{L}\p{N}\s-]+/gu, " ").trim().split(/\s+/).filter(Boolean).join("-");
|
|
698
721
|
}
|
|
@@ -772,6 +795,7 @@ function createNapiTransformOptions(options, filePath) {
|
|
|
772
795
|
superscript: options.superscript,
|
|
773
796
|
subscript: options.subscript,
|
|
774
797
|
smartPunctuation: options.smartPunctuation,
|
|
798
|
+
headingAttributes: options.headingAttributes,
|
|
775
799
|
frontmatter: options.frontmatter,
|
|
776
800
|
tocMaxDepth: options.tocMaxDepth,
|
|
777
801
|
codeAnnotations: codeAnnotations.enabled,
|
|
@@ -1019,6 +1043,7 @@ function installUnifiedParser(processor, strategy, options, filePath, nativeTree
|
|
|
1019
1043
|
superscript: options.superscript,
|
|
1020
1044
|
subscript: options.subscript,
|
|
1021
1045
|
smartPunctuation: options.smartPunctuation,
|
|
1046
|
+
headingAttributes: options.headingAttributes,
|
|
1022
1047
|
math: options.math,
|
|
1023
1048
|
definitionLists: options.definitionLists
|
|
1024
1049
|
});
|
|
@@ -1366,6 +1391,7 @@ function resolveOptions(options) {
|
|
|
1366
1391
|
superscript: options.superscript ?? false,
|
|
1367
1392
|
subscript: options.subscript ?? false,
|
|
1368
1393
|
smartPunctuation: options.smartPunctuation ?? false,
|
|
1394
|
+
headingAttributes: options.headingAttributes ?? false,
|
|
1369
1395
|
highlight: options.highlight ?? false,
|
|
1370
1396
|
codeAnnotations: resolveCodeAnnotationsOptions(options.codeAnnotations),
|
|
1371
1397
|
mermaid: options.mermaid ?? false,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ox-content/unplugin",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.1-beta.0",
|
|
4
4
|
"description": "Universal plugin for Ox Content - Markdown processing for webpack, rollup, esbuild, vite, and more",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"esbuild",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"provenance": true
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@ox-content/napi": "3.
|
|
58
|
+
"@ox-content/napi": "3.1.1-beta.0",
|
|
59
59
|
"@rollup/pluginutils": "^5.4.0",
|
|
60
60
|
"markdown-it": "^15.0.0",
|
|
61
61
|
"markdown-it-anchor": "^9.2.1",
|