@ox-content/unplugin 2.8.0 → 2.10.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.
@@ -1,7 +1,7 @@
1
- import { a as OxContentOptions, d as ResolvedOptions, f as TocEntry, p as TransformResult, t as unplugin } from "./index.mjs";
1
+ import { C as ResolvedDocsConfig, D as UnifiedPreset, E as TransformResult, S as RemarkPlugin, T as TocEntry, _ as OxContentMdastPlugin, a as extractTocFromMdast, b as PluginConfig, c as toUnifiedMdastPlugin, d as MarkdownItPlugin, f as MdastNode, g as MdastTransformer, h as MdastRoot, i as defineMdastPlugin, l as transformMarkdown, m as MdastPluginContext, n as OxContentMdastOptions, o as oxContentMdast, p as MdastPlugin, r as createMdastPluginContext, s as parseMarkdownToMdast, t as unplugin, u as DocsConfig, v as OxContentOptions, w as ResolvedOptions, x as RehypePlugin, y as OxContentPlugin } from "./index.mjs";
2
2
  import * as unplugin$1 from "unplugin";
3
3
 
4
4
  //#region src/esbuild.d.ts
5
5
  declare const _default: (options?: OxContentOptions | undefined) => unplugin$1.EsbuildPlugin;
6
6
  //#endregion
7
- export { type OxContentOptions, type ResolvedOptions, type TocEntry, type TransformResult, _default as default, unplugin };
7
+ export { DocsConfig, MarkdownItPlugin, MdastNode, MdastPlugin, MdastPluginContext, MdastRoot, MdastTransformer, OxContentMdastOptions, OxContentMdastPlugin, OxContentOptions, OxContentPlugin, PluginConfig, RehypePlugin, RemarkPlugin, ResolvedDocsConfig, ResolvedOptions, TocEntry, TransformResult, UnifiedPreset, createMdastPluginContext, _default as default, defineMdastPlugin, extractTocFromMdast, oxContentMdast, parseMarkdownToMdast, toUnifiedMdastPlugin, transformMarkdown, unplugin };
package/dist/esbuild.mjs CHANGED
@@ -1,8 +1,8 @@
1
- import { t as unplugin } from "./src.mjs";
1
+ import { a as extractTocFromMdast, c as toUnifiedMdastPlugin, i as defineMdastPlugin, n as transformMarkdown, o as oxContentMdast, r as createMdastPluginContext, s as parseMarkdownToMdast, t as unplugin } from "./src.mjs";
2
2
  //#region src/esbuild.ts
3
3
  /**
4
4
  * esbuild plugin export for @ox-content/unplugin
5
5
  */
6
6
  var esbuild_default = unplugin.esbuild;
7
7
  //#endregion
8
- export { esbuild_default as default, unplugin };
8
+ export { createMdastPluginContext, esbuild_default as default, defineMdastPlugin, extractTocFromMdast, oxContentMdast, parseMarkdownToMdast, toUnifiedMdastPlugin, transformMarkdown, unplugin };
package/dist/index.d.mts CHANGED
@@ -10,16 +10,135 @@ type MarkdownItPluginFn = (md: MarkdownIt, ...options: unknown[]) => void;
10
10
  * Can be a single plugin or a tuple of [plugin, ...options].
11
11
  */
12
12
  type MarkdownItPlugin = MarkdownItPluginFn | [MarkdownItPluginFn, ...unknown[]];
13
+ /**
14
+ * mdast node aligned with the unified ecosystem.
15
+ *
16
+ * This is intentionally structural so Ox Content can expose mdast-shaped trees
17
+ * without forcing consumers into a separate type package.
18
+ */
19
+ interface MdastNode {
20
+ type: string;
21
+ children?: MdastNode[];
22
+ value?: string;
23
+ position?: {
24
+ start: {
25
+ line: number;
26
+ column: number;
27
+ offset: number;
28
+ };
29
+ end: {
30
+ line: number;
31
+ column: number;
32
+ offset: number;
33
+ };
34
+ };
35
+ depth?: number;
36
+ url?: string;
37
+ title?: string;
38
+ lang?: string;
39
+ meta?: string;
40
+ alt?: string;
41
+ ordered?: boolean;
42
+ spread?: boolean;
43
+ checked?: boolean;
44
+ start?: number;
45
+ align?: Array<"left" | "center" | "right" | null>;
46
+ identifier?: string;
47
+ label?: string;
48
+ [key: string]: unknown;
49
+ }
50
+ /**
51
+ * mdast root node.
52
+ */
53
+ interface MdastRoot extends MdastNode {
54
+ type: "root";
55
+ children: MdastNode[];
56
+ }
57
+ /**
58
+ * Context passed to Ox Content mdast plugins.
59
+ */
60
+ interface MdastPluginContext {
61
+ /**
62
+ * Markdown file path being processed.
63
+ */
64
+ filePath: string;
65
+ /**
66
+ * Original markdown source passed into the unified stage.
67
+ */
68
+ source: string;
69
+ /**
70
+ * Parsed frontmatter data.
71
+ */
72
+ frontmatter: Record<string, unknown>;
73
+ /**
74
+ * Position of the markdown content slice within the original source.
75
+ *
76
+ * This is present when frontmatter or other pre-processing strips bytes
77
+ * before the mdast stage runs.
78
+ */
79
+ sourceOffset?: {
80
+ byteOffset: number;
81
+ offset: number;
82
+ line: number;
83
+ column: number;
84
+ };
85
+ /**
86
+ * Resolved plugin options.
87
+ */
88
+ options: ResolvedOptions;
89
+ }
90
+ /**
91
+ * Ox Content-native mdast transformer.
92
+ */
93
+ type MdastTransformer = (tree: MdastRoot, context: MdastPluginContext) => MdastRoot | void | Promise<MdastRoot | void>;
94
+ /**
95
+ * Ox Content mdast plugin descriptor.
96
+ *
97
+ * Existing unified/remark plugins can also be passed through `plugin.mdast`,
98
+ * but this object form gives a more mdast-native authoring experience.
99
+ */
100
+ interface OxContentMdastPlugin {
101
+ /**
102
+ * Optional plugin name for debugging.
103
+ */
104
+ name?: string;
105
+ /**
106
+ * Tree transformer.
107
+ */
108
+ transform: MdastTransformer;
109
+ }
110
+ /**
111
+ * Unified attacher function type.
112
+ */
113
+ type UnifiedAttacher = (this: unknown, ...args: never[]) => unknown;
114
+ /**
115
+ * Unified preset object type.
116
+ */
117
+ interface UnifiedPreset {
118
+ plugins?: unknown[];
119
+ settings?: Record<string, unknown>;
120
+ }
121
+ /**
122
+ * Unified plugin tuple type.
123
+ */
124
+ type UnifiedPluginTuple = [UnifiedAttacher, ...unknown[]];
13
125
  /**
14
126
  * Remark plugin type.
15
- * Can be a single plugin or a tuple of [plugin, options].
127
+ * Can be a single plugin, a plugin tuple, or a unified preset.
16
128
  */
17
- type RemarkPlugin = [unknown, unknown] | unknown;
129
+ type RemarkPlugin = UnifiedAttacher | UnifiedPluginTuple | UnifiedPreset;
130
+ /**
131
+ * mdast plugin type.
132
+ *
133
+ * Accepts both Ox Content-native mdast plugins and existing unified/remark
134
+ * plugins so existing ecosystem plugins can run unchanged.
135
+ */
136
+ type MdastPlugin = OxContentMdastPlugin | RemarkPlugin;
18
137
  /**
19
138
  * Rehype plugin type.
20
- * Can be a single plugin or a tuple of [plugin, options].
139
+ * Can be a single plugin, a plugin tuple, or a unified preset.
21
140
  */
22
- type RehypePlugin = [unknown, unknown] | unknown;
141
+ type RehypePlugin = UnifiedAttacher | UnifiedPluginTuple | UnifiedPreset;
23
142
  /**
24
143
  * Ox-content native plugin type.
25
144
  * Transforms HTML after rendering.
@@ -92,8 +211,14 @@ interface PluginConfig {
92
211
  * @see https://www.npmjs.com/search?q=markdown-it-plugin
93
212
  */
94
213
  markdownIt?: MarkdownItPlugin[];
214
+ /**
215
+ * mdast plugins.
216
+ * Accepts both Ox Content-native mdast plugins and existing remark plugins.
217
+ */
218
+ mdast?: MdastPlugin[];
95
219
  /**
96
220
  * Remark plugins (unified ecosystem).
221
+ * Kept for compatibility; runs in the same mdast stage as `plugin.mdast`.
97
222
  * @see https://github.com/remarkjs/remark/blob/main/doc/plugins.md
98
223
  */
99
224
  remark?: RemarkPlugin[];
@@ -256,17 +381,84 @@ interface TocEntry {
256
381
  //#region src/transform.d.ts
257
382
  /**
258
383
  * Transforms Markdown content into a JavaScript module.
259
- * Uses Rust-based renderer via NAPI bindings for optimal performance.
384
+ * Uses Rust-based parsing, and switches to a unified/mdast pipeline when
385
+ * JavaScript mdast/remark/rehype plugins are configured.
260
386
  *
261
387
  * Note: This requires the @ox-content/napi package to be built.
262
- * NAPI bindings are loaded dynamically to support both Node.js and build-time execution.
263
388
  */
264
389
  declare function transformMarkdown(source: string, filePath: string, options: ResolvedOptions): Promise<TransformResult>;
265
390
  //#endregion
391
+ //#region src/mdast.d.ts
392
+ /**
393
+ * Parser options for the Ox Content mdast unified plugin.
394
+ */
395
+ interface OxContentMdastOptions {
396
+ /**
397
+ * Enable GitHub Flavored Markdown extensions.
398
+ * @default true
399
+ */
400
+ gfm?: boolean;
401
+ /**
402
+ * Enable footnotes.
403
+ * @default true
404
+ */
405
+ footnotes?: boolean;
406
+ /**
407
+ * Enable task lists.
408
+ * @default true
409
+ */
410
+ taskLists?: boolean;
411
+ /**
412
+ * Enable tables.
413
+ * @default true
414
+ */
415
+ tables?: boolean;
416
+ /**
417
+ * Enable strikethrough.
418
+ * @default true
419
+ */
420
+ strikethrough?: boolean;
421
+ /**
422
+ * Enable autolinks.
423
+ * @default true
424
+ */
425
+ autolinks?: boolean;
426
+ }
427
+ type ProcessorWithParser = {
428
+ parser?: (document: string) => MdastRoot;
429
+ };
430
+ /**
431
+ * Unified parser plugin backed by Ox Content's native mdast parser.
432
+ *
433
+ * This lets existing remark/unified plugins run on top of Ox Content's parser
434
+ * while keeping a more mdast-native integration point.
435
+ */
436
+ declare function oxContentMdast(this: ProcessorWithParser, options?: OxContentMdastOptions): void;
437
+ /**
438
+ * Defines an Ox Content-native mdast plugin.
439
+ */
440
+ declare function defineMdastPlugin(name: string, transform: MdastTransformer): OxContentMdastPlugin;
441
+ /**
442
+ * Parses markdown source into an mdast-compatible tree using the native parser.
443
+ */
444
+ declare function parseMarkdownToMdast(source: string, options?: OxContentMdastOptions): MdastRoot;
445
+ /**
446
+ * Wraps an Ox Content-native mdast plugin as a standard unified transformer.
447
+ */
448
+ declare function toUnifiedMdastPlugin(plugin: OxContentMdastPlugin, context: MdastPluginContext): () => (tree: MdastRoot) => MdastRoot | Promise<MdastRoot>;
449
+ /**
450
+ * Extracts a nested TOC tree from mdast after mdast-stage plugins have run.
451
+ */
452
+ declare function extractTocFromMdast(root: MdastRoot, maxDepth: number): TocEntry[];
453
+ /**
454
+ * Creates the context passed to Ox Content-native mdast plugins.
455
+ */
456
+ declare function createMdastPluginContext(filePath: string, source: string, frontmatter: Record<string, unknown>, options: ResolvedOptions, sourceOffset?: MdastPluginContext["sourceOffset"]): MdastPluginContext;
457
+ //#endregion
266
458
  //#region src/index.d.ts
267
459
  /**
268
460
  * The unplugin instance.
269
461
  */
270
462
  declare const unplugin: unplugin.UnpluginInstance<OxContentOptions | undefined, boolean>;
271
463
  //#endregion
272
- export { OxContentOptions as a, RehypePlugin as c, ResolvedOptions as d, TocEntry as f, MarkdownItPlugin as i, RemarkPlugin as l, transformMarkdown as n, OxContentPlugin as o, TransformResult as p, DocsConfig as r, PluginConfig as s, unplugin as t, ResolvedDocsConfig as u };
464
+ export { ResolvedDocsConfig as C, UnifiedPreset as D, TransformResult as E, RemarkPlugin as S, TocEntry as T, OxContentMdastPlugin as _, extractTocFromMdast as a, PluginConfig as b, toUnifiedMdastPlugin as c, MarkdownItPlugin as d, MdastNode as f, MdastTransformer as g, MdastRoot as h, defineMdastPlugin as i, transformMarkdown as l, MdastPluginContext as m, OxContentMdastOptions as n, oxContentMdast as o, MdastPlugin as p, createMdastPluginContext as r, parseMarkdownToMdast as s, unplugin as t, DocsConfig as u, OxContentOptions as v, ResolvedOptions as w, RehypePlugin as x, OxContentPlugin as y };
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { n as transformMarkdown, t as unplugin } from "./src.mjs";
2
- export { unplugin as default, unplugin, transformMarkdown };
1
+ import { a as extractTocFromMdast, c as toUnifiedMdastPlugin, i as defineMdastPlugin, n as transformMarkdown, o as oxContentMdast, r as createMdastPluginContext, s as parseMarkdownToMdast, t as unplugin } from "./src.mjs";
2
+ export { createMdastPluginContext, unplugin as default, unplugin, defineMdastPlugin, extractTocFromMdast, oxContentMdast, parseMarkdownToMdast, toUnifiedMdastPlugin, transformMarkdown };
package/dist/index2.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as OxContentOptions, c as RehypePlugin, d as ResolvedOptions, f as TocEntry, i as MarkdownItPlugin, l as RemarkPlugin, n as transformMarkdown, o as OxContentPlugin, p as TransformResult, r as DocsConfig, s as PluginConfig, t as unplugin, u as ResolvedDocsConfig } from "./index.mjs";
2
- export { DocsConfig, MarkdownItPlugin, OxContentOptions, OxContentPlugin, PluginConfig, RehypePlugin, RemarkPlugin, ResolvedDocsConfig, ResolvedOptions, TocEntry, TransformResult, unplugin as default, unplugin, transformMarkdown };
1
+ import { C as ResolvedDocsConfig, D as UnifiedPreset, E as TransformResult, S as RemarkPlugin, T as TocEntry, _ as OxContentMdastPlugin, a as extractTocFromMdast, b as PluginConfig, c as toUnifiedMdastPlugin, d as MarkdownItPlugin, f as MdastNode, g as MdastTransformer, h as MdastRoot, i as defineMdastPlugin, l as transformMarkdown, m as MdastPluginContext, n as OxContentMdastOptions, o as oxContentMdast, p as MdastPlugin, r as createMdastPluginContext, s as parseMarkdownToMdast, t as unplugin, u as DocsConfig, v as OxContentOptions, w as ResolvedOptions, x as RehypePlugin, y as OxContentPlugin } from "./index.mjs";
2
+ export { DocsConfig, MarkdownItPlugin, MdastNode, MdastPlugin, MdastPluginContext, MdastRoot, MdastTransformer, OxContentMdastOptions, OxContentMdastPlugin, OxContentOptions, OxContentPlugin, PluginConfig, RehypePlugin, RemarkPlugin, ResolvedDocsConfig, ResolvedOptions, TocEntry, TransformResult, UnifiedPreset, createMdastPluginContext, unplugin as default, unplugin, defineMdastPlugin, extractTocFromMdast, oxContentMdast, parseMarkdownToMdast, toUnifiedMdastPlugin, transformMarkdown };
package/dist/rollup.d.mts CHANGED
@@ -1,7 +1,7 @@
1
- import { a as OxContentOptions, d as ResolvedOptions, f as TocEntry, p as TransformResult, t as unplugin } from "./index.mjs";
1
+ import { C as ResolvedDocsConfig, D as UnifiedPreset, E as TransformResult, S as RemarkPlugin, T as TocEntry, _ as OxContentMdastPlugin, a as extractTocFromMdast, b as PluginConfig, c as toUnifiedMdastPlugin, d as MarkdownItPlugin, f as MdastNode, g as MdastTransformer, h as MdastRoot, i as defineMdastPlugin, l as transformMarkdown, m as MdastPluginContext, n as OxContentMdastOptions, o as oxContentMdast, p as MdastPlugin, r as createMdastPluginContext, s as parseMarkdownToMdast, t as unplugin, u as DocsConfig, v as OxContentOptions, w as ResolvedOptions, x as RehypePlugin, y as OxContentPlugin } from "./index.mjs";
2
2
  import * as unplugin$1 from "unplugin";
3
3
 
4
4
  //#region src/rollup.d.ts
5
5
  declare const _default: (options?: OxContentOptions | undefined) => unplugin$1.RollupPlugin<any> | unplugin$1.RollupPlugin<any>[];
6
6
  //#endregion
7
- export { type OxContentOptions, type ResolvedOptions, type TocEntry, type TransformResult, _default as default, unplugin };
7
+ export { DocsConfig, MarkdownItPlugin, MdastNode, MdastPlugin, MdastPluginContext, MdastRoot, MdastTransformer, OxContentMdastOptions, OxContentMdastPlugin, OxContentOptions, OxContentPlugin, PluginConfig, RehypePlugin, RemarkPlugin, ResolvedDocsConfig, ResolvedOptions, TocEntry, TransformResult, UnifiedPreset, createMdastPluginContext, _default as default, defineMdastPlugin, extractTocFromMdast, oxContentMdast, parseMarkdownToMdast, toUnifiedMdastPlugin, transformMarkdown, unplugin };
package/dist/rollup.mjs CHANGED
@@ -1,8 +1,8 @@
1
- import { t as unplugin } from "./src.mjs";
1
+ import { a as extractTocFromMdast, c as toUnifiedMdastPlugin, i as defineMdastPlugin, n as transformMarkdown, o as oxContentMdast, r as createMdastPluginContext, s as parseMarkdownToMdast, t as unplugin } from "./src.mjs";
2
2
  //#region src/rollup.ts
3
3
  /**
4
4
  * Rollup plugin export for @ox-content/unplugin
5
5
  */
6
6
  var rollup_default = unplugin.rollup;
7
7
  //#endregion
8
- export { rollup_default as default, unplugin };
8
+ export { createMdastPluginContext, rollup_default as default, defineMdastPlugin, extractTocFromMdast, oxContentMdast, parseMarkdownToMdast, toUnifiedMdastPlugin, transformMarkdown, unplugin };
package/dist/rspack.d.mts CHANGED
@@ -1,6 +1,6 @@
1
- import { a as OxContentOptions, d as ResolvedOptions, f as TocEntry, p as TransformResult, t as unplugin } from "./index.mjs";
1
+ import { C as ResolvedDocsConfig, D as UnifiedPreset, E as TransformResult, S as RemarkPlugin, T as TocEntry, _ as OxContentMdastPlugin, a as extractTocFromMdast, b as PluginConfig, c as toUnifiedMdastPlugin, d as MarkdownItPlugin, f as MdastNode, g as MdastTransformer, h as MdastRoot, i as defineMdastPlugin, l as transformMarkdown, m as MdastPluginContext, n as OxContentMdastOptions, o as oxContentMdast, p as MdastPlugin, r as createMdastPluginContext, s as parseMarkdownToMdast, t as unplugin, u as DocsConfig, v as OxContentOptions, w as ResolvedOptions, x as RehypePlugin, y as OxContentPlugin } from "./index.mjs";
2
2
 
3
3
  //#region src/rspack.d.ts
4
4
  declare const _default: (options?: OxContentOptions | undefined) => RspackPluginInstance;
5
5
  //#endregion
6
- export { type OxContentOptions, type ResolvedOptions, type TocEntry, type TransformResult, _default as default, unplugin };
6
+ export { DocsConfig, MarkdownItPlugin, MdastNode, MdastPlugin, MdastPluginContext, MdastRoot, MdastTransformer, OxContentMdastOptions, OxContentMdastPlugin, OxContentOptions, OxContentPlugin, PluginConfig, RehypePlugin, RemarkPlugin, ResolvedDocsConfig, ResolvedOptions, TocEntry, TransformResult, UnifiedPreset, createMdastPluginContext, _default as default, defineMdastPlugin, extractTocFromMdast, oxContentMdast, parseMarkdownToMdast, toUnifiedMdastPlugin, transformMarkdown, unplugin };
package/dist/rspack.mjs CHANGED
@@ -1,8 +1,8 @@
1
- import { t as unplugin } from "./src.mjs";
1
+ import { a as extractTocFromMdast, c as toUnifiedMdastPlugin, i as defineMdastPlugin, n as transformMarkdown, o as oxContentMdast, r as createMdastPluginContext, s as parseMarkdownToMdast, t as unplugin } from "./src.mjs";
2
2
  //#region src/rspack.ts
3
3
  /**
4
4
  * Rspack plugin export for @ox-content/unplugin
5
5
  */
6
6
  var rspack_default = unplugin.rspack;
7
7
  //#endregion
8
- export { rspack_default as default, unplugin };
8
+ export { createMdastPluginContext, rspack_default as default, defineMdastPlugin, extractTocFromMdast, oxContentMdast, parseMarkdownToMdast, toUnifiedMdastPlugin, transformMarkdown, unplugin };