@ox-content/unplugin 0.3.0-alpha.11
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/esbuild.d.ts +8 -0
- package/dist/esbuild.js +10 -0
- package/dist/index.d.ts +260 -0
- package/dist/index.js +3 -0
- package/dist/index2.d.ts +2 -0
- package/dist/rollup.d.ts +8 -0
- package/dist/rollup.js +10 -0
- package/dist/rspack.d.ts +7 -0
- package/dist/rspack.js +10 -0
- package/dist/src.js +244 -0
- package/dist/vite.d.ts +8 -0
- package/dist/vite.js +10 -0
- package/dist/webpack.d.ts +8 -0
- package/dist/webpack.js +10 -0
- package/package.json +84 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { a as OxContentOptions, d as ResolvedOptions, f as TocEntry, p as TransformResult, t as unplugin } from "./index.js";
|
|
2
|
+
import * as unplugin3 from "unplugin";
|
|
3
|
+
|
|
4
|
+
//#region src/esbuild.d.ts
|
|
5
|
+
|
|
6
|
+
declare const _default: (options?: OxContentOptions | undefined) => unplugin3.EsbuildPlugin;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { type OxContentOptions, type ResolvedOptions, type TocEntry, type TransformResult, _default as default, unplugin };
|
package/dist/esbuild.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { t as src_default } from "./src.js";
|
|
2
|
+
|
|
3
|
+
//#region src/esbuild.ts
|
|
4
|
+
/**
|
|
5
|
+
* esbuild plugin export for @ox-content/unplugin
|
|
6
|
+
*/
|
|
7
|
+
var esbuild_default = src_default.esbuild;
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
10
|
+
export { esbuild_default as default, src_default as unplugin };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import * as unplugin5 from "unplugin";
|
|
2
|
+
import MarkdownIt from "markdown-it";
|
|
3
|
+
|
|
4
|
+
//#region src/types.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Markdown-it plugin function type.
|
|
8
|
+
*/
|
|
9
|
+
type MarkdownItPluginFn = (md: MarkdownIt, ...options: unknown[]) => void;
|
|
10
|
+
/**
|
|
11
|
+
* Markdown-it plugin type.
|
|
12
|
+
* Can be a single plugin or a tuple of [plugin, ...options].
|
|
13
|
+
*/
|
|
14
|
+
type MarkdownItPlugin = MarkdownItPluginFn | [MarkdownItPluginFn, ...unknown[]];
|
|
15
|
+
/**
|
|
16
|
+
* Remark plugin type.
|
|
17
|
+
* Can be a single plugin or a tuple of [plugin, options].
|
|
18
|
+
*/
|
|
19
|
+
type RemarkPlugin = [unknown, unknown] | unknown;
|
|
20
|
+
/**
|
|
21
|
+
* Rehype plugin type.
|
|
22
|
+
* Can be a single plugin or a tuple of [plugin, options].
|
|
23
|
+
*/
|
|
24
|
+
type RehypePlugin = [unknown, unknown] | unknown;
|
|
25
|
+
/**
|
|
26
|
+
* Ox-content native plugin type.
|
|
27
|
+
* Transforms HTML after rendering.
|
|
28
|
+
*/
|
|
29
|
+
type OxContentPlugin = (html: string) => string | Promise<string>;
|
|
30
|
+
/**
|
|
31
|
+
* API documentation generation configuration.
|
|
32
|
+
* Similar to cargo docs for Rust.
|
|
33
|
+
*/
|
|
34
|
+
interface DocsConfig {
|
|
35
|
+
/**
|
|
36
|
+
* Enable API documentation generation.
|
|
37
|
+
* @default false
|
|
38
|
+
*/
|
|
39
|
+
enabled?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Source directories to scan for documentation.
|
|
42
|
+
* @default ['./src']
|
|
43
|
+
*/
|
|
44
|
+
src?: string[];
|
|
45
|
+
/**
|
|
46
|
+
* Output directory for generated documentation.
|
|
47
|
+
* @default 'docs/api'
|
|
48
|
+
*/
|
|
49
|
+
out?: string;
|
|
50
|
+
/**
|
|
51
|
+
* File patterns to include.
|
|
52
|
+
* @default ['**\/*.ts', '**\/*.tsx', '**\/*.js', '**\/*.jsx']
|
|
53
|
+
*/
|
|
54
|
+
include?: string[];
|
|
55
|
+
/**
|
|
56
|
+
* File patterns to exclude.
|
|
57
|
+
* @default ['**\/*.test.*', '**\/*.spec.*', '**\/node_modules/**']
|
|
58
|
+
*/
|
|
59
|
+
exclude?: string[];
|
|
60
|
+
/**
|
|
61
|
+
* Include private items (starting with _).
|
|
62
|
+
* @default false
|
|
63
|
+
*/
|
|
64
|
+
includePrivate?: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Generate table of contents.
|
|
67
|
+
* @default true
|
|
68
|
+
*/
|
|
69
|
+
toc?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Group documentation by file or by kind.
|
|
72
|
+
* @default 'file'
|
|
73
|
+
*/
|
|
74
|
+
groupBy?: "file" | "kind";
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Plugin configuration for various markdown ecosystems.
|
|
78
|
+
*/
|
|
79
|
+
interface PluginConfig {
|
|
80
|
+
/**
|
|
81
|
+
* Ox-content native plugins.
|
|
82
|
+
* Transform HTML after rendering.
|
|
83
|
+
*/
|
|
84
|
+
oxContent?: OxContentPlugin[];
|
|
85
|
+
/**
|
|
86
|
+
* Markdown-it plugins.
|
|
87
|
+
* @see https://www.npmjs.com/search?q=markdown-it-plugin
|
|
88
|
+
*/
|
|
89
|
+
markdownIt?: MarkdownItPlugin[];
|
|
90
|
+
/**
|
|
91
|
+
* Remark plugins (unified ecosystem).
|
|
92
|
+
* @see https://github.com/remarkjs/remark/blob/main/doc/plugins.md
|
|
93
|
+
*/
|
|
94
|
+
remark?: RemarkPlugin[];
|
|
95
|
+
/**
|
|
96
|
+
* Rehype plugins (unified ecosystem).
|
|
97
|
+
* @see https://github.com/rehypejs/rehype/blob/main/doc/plugins.md
|
|
98
|
+
*/
|
|
99
|
+
rehype?: RehypePlugin[];
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Plugin options.
|
|
103
|
+
*/
|
|
104
|
+
interface OxContentOptions {
|
|
105
|
+
/**
|
|
106
|
+
* Source directory for Markdown files.
|
|
107
|
+
* @default 'docs'
|
|
108
|
+
*/
|
|
109
|
+
srcDir?: string;
|
|
110
|
+
/**
|
|
111
|
+
* Enable GitHub Flavored Markdown extensions.
|
|
112
|
+
* @default true
|
|
113
|
+
*/
|
|
114
|
+
gfm?: boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Enable footnotes.
|
|
117
|
+
* @default true
|
|
118
|
+
*/
|
|
119
|
+
footnotes?: boolean;
|
|
120
|
+
/**
|
|
121
|
+
* Enable tables.
|
|
122
|
+
* @default true
|
|
123
|
+
*/
|
|
124
|
+
tables?: boolean;
|
|
125
|
+
/**
|
|
126
|
+
* Enable task lists.
|
|
127
|
+
* @default true
|
|
128
|
+
*/
|
|
129
|
+
taskLists?: boolean;
|
|
130
|
+
/**
|
|
131
|
+
* Enable strikethrough.
|
|
132
|
+
* @default true
|
|
133
|
+
*/
|
|
134
|
+
strikethrough?: boolean;
|
|
135
|
+
/**
|
|
136
|
+
* Enable syntax highlighting for code blocks.
|
|
137
|
+
* @default false
|
|
138
|
+
*/
|
|
139
|
+
highlight?: boolean;
|
|
140
|
+
/**
|
|
141
|
+
* Syntax highlighting theme.
|
|
142
|
+
* @default 'github-dark'
|
|
143
|
+
*/
|
|
144
|
+
highlightTheme?: string;
|
|
145
|
+
/**
|
|
146
|
+
* Enable mermaid diagram rendering.
|
|
147
|
+
* @default false
|
|
148
|
+
*/
|
|
149
|
+
mermaid?: boolean;
|
|
150
|
+
/**
|
|
151
|
+
* Parse YAML frontmatter.
|
|
152
|
+
* @default true
|
|
153
|
+
*/
|
|
154
|
+
frontmatter?: boolean;
|
|
155
|
+
/**
|
|
156
|
+
* Generate table of contents.
|
|
157
|
+
* @default true
|
|
158
|
+
*/
|
|
159
|
+
toc?: boolean;
|
|
160
|
+
/**
|
|
161
|
+
* Maximum heading depth for TOC.
|
|
162
|
+
* @default 3
|
|
163
|
+
*/
|
|
164
|
+
tocMaxDepth?: number;
|
|
165
|
+
/**
|
|
166
|
+
* File extensions to process.
|
|
167
|
+
* @default ['.md', '.markdown']
|
|
168
|
+
*/
|
|
169
|
+
extensions?: string[];
|
|
170
|
+
/**
|
|
171
|
+
* Files/patterns to include.
|
|
172
|
+
*/
|
|
173
|
+
include?: string | RegExp | RegExp[];
|
|
174
|
+
/**
|
|
175
|
+
* Files/patterns to exclude.
|
|
176
|
+
*/
|
|
177
|
+
exclude?: string | RegExp | RegExp[];
|
|
178
|
+
/**
|
|
179
|
+
* Plugin configuration for markdown processing.
|
|
180
|
+
*/
|
|
181
|
+
plugin?: PluginConfig;
|
|
182
|
+
/**
|
|
183
|
+
* API documentation generation configuration.
|
|
184
|
+
* Set to false to disable, true to enable with defaults,
|
|
185
|
+
* or provide a DocsConfig object for customization.
|
|
186
|
+
* @default false
|
|
187
|
+
*/
|
|
188
|
+
docs?: boolean | DocsConfig;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Resolved docs configuration.
|
|
192
|
+
*/
|
|
193
|
+
interface ResolvedDocsConfig {
|
|
194
|
+
enabled: boolean;
|
|
195
|
+
src: string[];
|
|
196
|
+
out: string;
|
|
197
|
+
include: string[];
|
|
198
|
+
exclude: string[];
|
|
199
|
+
includePrivate: boolean;
|
|
200
|
+
toc: boolean;
|
|
201
|
+
groupBy: "file" | "kind";
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Resolved options with all defaults applied.
|
|
205
|
+
*/
|
|
206
|
+
interface ResolvedOptions {
|
|
207
|
+
srcDir: string;
|
|
208
|
+
gfm: boolean;
|
|
209
|
+
footnotes: boolean;
|
|
210
|
+
tables: boolean;
|
|
211
|
+
taskLists: boolean;
|
|
212
|
+
strikethrough: boolean;
|
|
213
|
+
highlight: boolean;
|
|
214
|
+
highlightTheme: string;
|
|
215
|
+
mermaid: boolean;
|
|
216
|
+
frontmatter: boolean;
|
|
217
|
+
toc: boolean;
|
|
218
|
+
tocMaxDepth: number;
|
|
219
|
+
extensions: string[];
|
|
220
|
+
include: (string | RegExp)[];
|
|
221
|
+
exclude: (string | RegExp)[];
|
|
222
|
+
plugin: Required<PluginConfig>;
|
|
223
|
+
docs: ResolvedDocsConfig;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Transform result.
|
|
227
|
+
*/
|
|
228
|
+
interface TransformResult {
|
|
229
|
+
code: string;
|
|
230
|
+
html: string;
|
|
231
|
+
frontmatter: Record<string, unknown>;
|
|
232
|
+
toc: TocEntry[];
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Table of contents entry.
|
|
236
|
+
*/
|
|
237
|
+
interface TocEntry {
|
|
238
|
+
depth: number;
|
|
239
|
+
text: string;
|
|
240
|
+
slug: string;
|
|
241
|
+
children: TocEntry[];
|
|
242
|
+
}
|
|
243
|
+
//#endregion
|
|
244
|
+
//#region src/transform.d.ts
|
|
245
|
+
/**
|
|
246
|
+
* Transforms Markdown content into a JavaScript module.
|
|
247
|
+
* Uses Rust-based renderer via NAPI bindings for optimal performance.
|
|
248
|
+
*
|
|
249
|
+
* Note: This requires the @ox-content/napi package to be built.
|
|
250
|
+
* NAPI bindings are loaded dynamically to support both Node.js and build-time execution.
|
|
251
|
+
*/
|
|
252
|
+
declare function transformMarkdown(source: string, filePath: string, options: ResolvedOptions): Promise<TransformResult>;
|
|
253
|
+
//#endregion
|
|
254
|
+
//#region src/index.d.ts
|
|
255
|
+
/**
|
|
256
|
+
* The unplugin instance.
|
|
257
|
+
*/
|
|
258
|
+
declare const unplugin: unplugin5.UnpluginInstance<OxContentOptions | undefined, boolean>;
|
|
259
|
+
//#endregion
|
|
260
|
+
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 };
|
package/dist/index.js
ADDED
package/dist/index2.d.ts
ADDED
|
@@ -0,0 +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.js";
|
|
2
|
+
export { DocsConfig, MarkdownItPlugin, OxContentOptions, OxContentPlugin, PluginConfig, RehypePlugin, RemarkPlugin, ResolvedDocsConfig, ResolvedOptions, TocEntry, TransformResult, unplugin as default, unplugin, transformMarkdown };
|
package/dist/rollup.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { a as OxContentOptions, d as ResolvedOptions, f as TocEntry, p as TransformResult, t as unplugin } from "./index.js";
|
|
2
|
+
import * as unplugin1 from "unplugin";
|
|
3
|
+
|
|
4
|
+
//#region src/rollup.d.ts
|
|
5
|
+
|
|
6
|
+
declare const _default: (options?: OxContentOptions | undefined) => unplugin1.RollupPlugin<any> | unplugin1.RollupPlugin<any>[];
|
|
7
|
+
//#endregion
|
|
8
|
+
export { type OxContentOptions, type ResolvedOptions, type TocEntry, type TransformResult, _default as default, unplugin };
|
package/dist/rollup.js
ADDED
package/dist/rspack.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { a as OxContentOptions, d as ResolvedOptions, f as TocEntry, p as TransformResult, t as unplugin } from "./index.js";
|
|
2
|
+
|
|
3
|
+
//#region src/rspack.d.ts
|
|
4
|
+
|
|
5
|
+
declare const _default: (options?: OxContentOptions | undefined) => RspackPluginInstance;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { type OxContentOptions, type ResolvedOptions, type TocEntry, type TransformResult, _default as default, unplugin };
|
package/dist/rspack.js
ADDED
package/dist/src.js
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { createUnplugin } from "unplugin";
|
|
2
|
+
import { createFilter } from "@rollup/pluginutils";
|
|
3
|
+
|
|
4
|
+
//#region src/transform.ts
|
|
5
|
+
/**
|
|
6
|
+
* Transforms Markdown content into a JavaScript module.
|
|
7
|
+
* Uses Rust-based renderer via NAPI bindings for optimal performance.
|
|
8
|
+
*
|
|
9
|
+
* Note: This requires the @ox-content/napi package to be built.
|
|
10
|
+
* NAPI bindings are loaded dynamically to support both Node.js and build-time execution.
|
|
11
|
+
*/
|
|
12
|
+
async function transformMarkdown(source, filePath, options) {
|
|
13
|
+
let napi;
|
|
14
|
+
try {
|
|
15
|
+
napi = await import("@ox-content/napi");
|
|
16
|
+
} catch {
|
|
17
|
+
throw new Error("[ox-content] Failed to load @ox-content/napi. Please ensure the NAPI module is built. Run: pnpm build:napi");
|
|
18
|
+
}
|
|
19
|
+
const result = napi.transform(source, {
|
|
20
|
+
gfm: options.gfm,
|
|
21
|
+
footnotes: options.footnotes,
|
|
22
|
+
task_lists: options.taskLists,
|
|
23
|
+
tables: options.tables,
|
|
24
|
+
strikethrough: options.strikethrough,
|
|
25
|
+
toc_max_depth: options.tocMaxDepth
|
|
26
|
+
});
|
|
27
|
+
if (result.errors.length > 0) console.warn("[ox-content] Transform warnings:", result.errors);
|
|
28
|
+
let frontmatter;
|
|
29
|
+
try {
|
|
30
|
+
frontmatter = JSON.parse(result.frontmatter);
|
|
31
|
+
} catch {
|
|
32
|
+
frontmatter = {};
|
|
33
|
+
}
|
|
34
|
+
const flatToc = result.toc.map((item) => ({
|
|
35
|
+
...item,
|
|
36
|
+
children: []
|
|
37
|
+
}));
|
|
38
|
+
const toc = options.toc ? buildTocTree(flatToc) : [];
|
|
39
|
+
let html = result.html;
|
|
40
|
+
for (const plugin of options.plugin.oxContent) html = await plugin(html);
|
|
41
|
+
return {
|
|
42
|
+
code: generateModuleCode(html, frontmatter, toc, filePath),
|
|
43
|
+
html,
|
|
44
|
+
frontmatter,
|
|
45
|
+
toc
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Builds nested TOC tree from flat list.
|
|
50
|
+
*/
|
|
51
|
+
function buildTocTree(entries) {
|
|
52
|
+
const result = [];
|
|
53
|
+
const stack = [];
|
|
54
|
+
for (const entry of entries) {
|
|
55
|
+
const tocEntry = {
|
|
56
|
+
depth: entry.depth,
|
|
57
|
+
text: entry.text,
|
|
58
|
+
slug: entry.slug,
|
|
59
|
+
children: []
|
|
60
|
+
};
|
|
61
|
+
while (stack.length > 0 && stack[stack.length - 1].depth >= entry.depth) stack.pop();
|
|
62
|
+
if (stack.length === 0) result.push(tocEntry);
|
|
63
|
+
else stack[stack.length - 1].children.push(tocEntry);
|
|
64
|
+
stack.push(tocEntry);
|
|
65
|
+
}
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Generates the JavaScript module code.
|
|
70
|
+
*/
|
|
71
|
+
function generateModuleCode(html, frontmatter, toc, filePath) {
|
|
72
|
+
return `
|
|
73
|
+
// Generated by @ox-content/unplugin
|
|
74
|
+
// Source: ${filePath}
|
|
75
|
+
|
|
76
|
+
export const html = ${JSON.stringify(html)};
|
|
77
|
+
export const frontmatter = ${JSON.stringify(frontmatter)};
|
|
78
|
+
export const toc = ${JSON.stringify(toc)};
|
|
79
|
+
|
|
80
|
+
export default {
|
|
81
|
+
html,
|
|
82
|
+
frontmatter,
|
|
83
|
+
toc,
|
|
84
|
+
};
|
|
85
|
+
`;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/index.ts
|
|
90
|
+
/**
|
|
91
|
+
* @ox-content/unplugin
|
|
92
|
+
*
|
|
93
|
+
* Universal plugin for Ox Content - Markdown processing for
|
|
94
|
+
* webpack, rollup, esbuild, vite, and more.
|
|
95
|
+
*/
|
|
96
|
+
/**
|
|
97
|
+
* Resolves docs configuration.
|
|
98
|
+
*/
|
|
99
|
+
function resolveDocsConfig(docs) {
|
|
100
|
+
if (docs === false || docs === void 0) return {
|
|
101
|
+
enabled: false,
|
|
102
|
+
src: ["./src"],
|
|
103
|
+
out: "docs/api",
|
|
104
|
+
include: [
|
|
105
|
+
"**/*.ts",
|
|
106
|
+
"**/*.tsx",
|
|
107
|
+
"**/*.js",
|
|
108
|
+
"**/*.jsx"
|
|
109
|
+
],
|
|
110
|
+
exclude: [
|
|
111
|
+
"**/*.test.*",
|
|
112
|
+
"**/*.spec.*",
|
|
113
|
+
"**/node_modules/**"
|
|
114
|
+
],
|
|
115
|
+
includePrivate: false,
|
|
116
|
+
toc: true,
|
|
117
|
+
groupBy: "file"
|
|
118
|
+
};
|
|
119
|
+
if (docs === true) return {
|
|
120
|
+
enabled: true,
|
|
121
|
+
src: ["./src"],
|
|
122
|
+
out: "docs/api",
|
|
123
|
+
include: [
|
|
124
|
+
"**/*.ts",
|
|
125
|
+
"**/*.tsx",
|
|
126
|
+
"**/*.js",
|
|
127
|
+
"**/*.jsx"
|
|
128
|
+
],
|
|
129
|
+
exclude: [
|
|
130
|
+
"**/*.test.*",
|
|
131
|
+
"**/*.spec.*",
|
|
132
|
+
"**/node_modules/**"
|
|
133
|
+
],
|
|
134
|
+
includePrivate: false,
|
|
135
|
+
toc: true,
|
|
136
|
+
groupBy: "file"
|
|
137
|
+
};
|
|
138
|
+
return {
|
|
139
|
+
enabled: docs.enabled ?? true,
|
|
140
|
+
src: docs.src ?? ["./src"],
|
|
141
|
+
out: docs.out ?? "docs/api",
|
|
142
|
+
include: docs.include ?? [
|
|
143
|
+
"**/*.ts",
|
|
144
|
+
"**/*.tsx",
|
|
145
|
+
"**/*.js",
|
|
146
|
+
"**/*.jsx"
|
|
147
|
+
],
|
|
148
|
+
exclude: docs.exclude ?? [
|
|
149
|
+
"**/*.test.*",
|
|
150
|
+
"**/*.spec.*",
|
|
151
|
+
"**/node_modules/**"
|
|
152
|
+
],
|
|
153
|
+
includePrivate: docs.includePrivate ?? false,
|
|
154
|
+
toc: docs.toc ?? true,
|
|
155
|
+
groupBy: docs.groupBy ?? "file"
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Resolves plugin options with defaults.
|
|
160
|
+
*/
|
|
161
|
+
function resolveOptions(options) {
|
|
162
|
+
const extensions = options.extensions ?? [".md", ".markdown"];
|
|
163
|
+
return {
|
|
164
|
+
srcDir: options.srcDir ?? "docs",
|
|
165
|
+
gfm: options.gfm ?? true,
|
|
166
|
+
footnotes: options.footnotes ?? true,
|
|
167
|
+
tables: options.tables ?? true,
|
|
168
|
+
taskLists: options.taskLists ?? true,
|
|
169
|
+
strikethrough: options.strikethrough ?? true,
|
|
170
|
+
highlight: options.highlight ?? false,
|
|
171
|
+
highlightTheme: options.highlightTheme ?? "github-dark",
|
|
172
|
+
mermaid: options.mermaid ?? false,
|
|
173
|
+
frontmatter: options.frontmatter ?? true,
|
|
174
|
+
toc: options.toc ?? true,
|
|
175
|
+
tocMaxDepth: options.tocMaxDepth ?? 3,
|
|
176
|
+
extensions,
|
|
177
|
+
include: Array.isArray(options.include) ? options.include : options.include ? [options.include] : [],
|
|
178
|
+
exclude: Array.isArray(options.exclude) ? options.exclude : options.exclude ? [options.exclude] : [],
|
|
179
|
+
plugin: {
|
|
180
|
+
oxContent: options.plugin?.oxContent ?? [],
|
|
181
|
+
markdownIt: options.plugin?.markdownIt ?? [],
|
|
182
|
+
remark: options.plugin?.remark ?? [],
|
|
183
|
+
rehype: options.plugin?.rehype ?? []
|
|
184
|
+
},
|
|
185
|
+
docs: resolveDocsConfig(options.docs)
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Check if the file should be processed.
|
|
190
|
+
*/
|
|
191
|
+
function isMarkdownFile(id, options) {
|
|
192
|
+
return options.extensions.some((ext) => id.endsWith(ext));
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* The unplugin factory function.
|
|
196
|
+
*/
|
|
197
|
+
const unpluginFactory = (rawOptions = {}) => {
|
|
198
|
+
const options = resolveOptions(rawOptions);
|
|
199
|
+
const filter = createFilter(options.include.length > 0 ? options.include : void 0, options.exclude.length > 0 ? options.exclude : void 0);
|
|
200
|
+
return {
|
|
201
|
+
name: "@ox-content/unplugin",
|
|
202
|
+
resolveId(id) {
|
|
203
|
+
if (id.startsWith("virtual:ox-content/")) return "\0" + id;
|
|
204
|
+
return null;
|
|
205
|
+
},
|
|
206
|
+
loadInclude(id) {
|
|
207
|
+
return id.startsWith("\0virtual:ox-content/");
|
|
208
|
+
},
|
|
209
|
+
load(id) {
|
|
210
|
+
if (id.startsWith("\0virtual:ox-content/")) {
|
|
211
|
+
const path = id.slice(20);
|
|
212
|
+
if (path === "config") return `export default ${JSON.stringify(options)};`;
|
|
213
|
+
if (path === "runtime") return `
|
|
214
|
+
export function useMarkdown() {
|
|
215
|
+
return {
|
|
216
|
+
render: (content) => content,
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
`;
|
|
220
|
+
return "export default {};";
|
|
221
|
+
}
|
|
222
|
+
return null;
|
|
223
|
+
},
|
|
224
|
+
transformInclude(id) {
|
|
225
|
+
return isMarkdownFile(id, options) && filter(id);
|
|
226
|
+
},
|
|
227
|
+
async transform(code, id) {
|
|
228
|
+
if (!isMarkdownFile(id, options)) return null;
|
|
229
|
+
if (!filter(id)) return null;
|
|
230
|
+
return {
|
|
231
|
+
code: (await transformMarkdown(code, id, options)).code,
|
|
232
|
+
map: null
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
};
|
|
237
|
+
/**
|
|
238
|
+
* The unplugin instance.
|
|
239
|
+
*/
|
|
240
|
+
const unplugin = /* @__PURE__ */ createUnplugin(unpluginFactory);
|
|
241
|
+
var src_default = unplugin;
|
|
242
|
+
|
|
243
|
+
//#endregion
|
|
244
|
+
export { unplugin as n, transformMarkdown as r, src_default as t };
|
package/dist/vite.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { a as OxContentOptions, d as ResolvedOptions, f as TocEntry, p as TransformResult, t as unplugin } from "./index.js";
|
|
2
|
+
import * as unplugin0 from "unplugin";
|
|
3
|
+
|
|
4
|
+
//#region src/vite.d.ts
|
|
5
|
+
|
|
6
|
+
declare const _default: (options?: OxContentOptions | undefined) => unplugin0.VitePlugin<any> | unplugin0.VitePlugin<any>[];
|
|
7
|
+
//#endregion
|
|
8
|
+
export { type OxContentOptions, type ResolvedOptions, type TocEntry, type TransformResult, _default as default, unplugin };
|
package/dist/vite.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { a as OxContentOptions, d as ResolvedOptions, f as TocEntry, p as TransformResult, t as unplugin } from "./index.js";
|
|
2
|
+
import * as unplugin4 from "unplugin";
|
|
3
|
+
|
|
4
|
+
//#region src/webpack.d.ts
|
|
5
|
+
|
|
6
|
+
declare const _default: (options?: OxContentOptions | undefined) => unplugin4.WebpackPluginInstance;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { type OxContentOptions, type ResolvedOptions, type TocEntry, type TransformResult, _default as default, unplugin };
|
package/dist/webpack.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { t as src_default } from "./src.js";
|
|
2
|
+
|
|
3
|
+
//#region src/webpack.ts
|
|
4
|
+
/**
|
|
5
|
+
* Webpack plugin export for @ox-content/unplugin
|
|
6
|
+
*/
|
|
7
|
+
var webpack_default = src_default.webpack;
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
10
|
+
export { webpack_default as default, src_default as unplugin };
|
package/package.json
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ox-content/unplugin",
|
|
3
|
+
"version": "0.3.0-alpha.11",
|
|
4
|
+
"description": "Universal plugin for Ox Content - Markdown processing for webpack, rollup, esbuild, vite, and more",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
},
|
|
13
|
+
"./vite": {
|
|
14
|
+
"import": "./dist/vite.js",
|
|
15
|
+
"types": "./dist/vite.d.ts"
|
|
16
|
+
},
|
|
17
|
+
"./webpack": {
|
|
18
|
+
"import": "./dist/webpack.js",
|
|
19
|
+
"types": "./dist/webpack.d.ts"
|
|
20
|
+
},
|
|
21
|
+
"./rollup": {
|
|
22
|
+
"import": "./dist/rollup.js",
|
|
23
|
+
"types": "./dist/rollup.d.ts"
|
|
24
|
+
},
|
|
25
|
+
"./esbuild": {
|
|
26
|
+
"import": "./dist/esbuild.js",
|
|
27
|
+
"types": "./dist/esbuild.d.ts"
|
|
28
|
+
},
|
|
29
|
+
"./rspack": {
|
|
30
|
+
"import": "./dist/rspack.js",
|
|
31
|
+
"types": "./dist/rspack.d.ts"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist"
|
|
36
|
+
],
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@rollup/pluginutils": "^5.1.4",
|
|
39
|
+
"gray-matter": "^4.0.3",
|
|
40
|
+
"markdown-it": "^14.1.0",
|
|
41
|
+
"markdown-it-anchor": "^9.2.0",
|
|
42
|
+
"rehype-stringify": "^10.0.1",
|
|
43
|
+
"remark-parse": "^11.0.0",
|
|
44
|
+
"remark-rehype": "^11.1.1",
|
|
45
|
+
"unified": "^11.0.5",
|
|
46
|
+
"unplugin": "^2.1.2",
|
|
47
|
+
"@ox-content/napi": "0.3.0-alpha.11"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@types/markdown-it": "^14.1.2",
|
|
51
|
+
"@types/node": "^22.0.0",
|
|
52
|
+
"tsdown": "^0.12.0",
|
|
53
|
+
"@typescript/native-preview": "^7.0.0-dev.20250601",
|
|
54
|
+
"typescript": "^5.7.0",
|
|
55
|
+
"vite": "^8.0.0-beta.0",
|
|
56
|
+
"webpack": "^5.97.1",
|
|
57
|
+
"rollup": "^4.29.1",
|
|
58
|
+
"esbuild": "^0.24.2"
|
|
59
|
+
},
|
|
60
|
+
"keywords": [
|
|
61
|
+
"unplugin",
|
|
62
|
+
"vite",
|
|
63
|
+
"webpack",
|
|
64
|
+
"rollup",
|
|
65
|
+
"esbuild",
|
|
66
|
+
"markdown",
|
|
67
|
+
"ox-content"
|
|
68
|
+
],
|
|
69
|
+
"license": "MIT",
|
|
70
|
+
"author": "ubugeeei",
|
|
71
|
+
"repository": {
|
|
72
|
+
"type": "git",
|
|
73
|
+
"url": "https://github.com/ubugeeei/ox-content.git",
|
|
74
|
+
"directory": "npm/unplugin-ox-content"
|
|
75
|
+
},
|
|
76
|
+
"publishConfig": {
|
|
77
|
+
"access": "public"
|
|
78
|
+
},
|
|
79
|
+
"scripts": {
|
|
80
|
+
"build": "tsdown",
|
|
81
|
+
"dev": "tsdown --watch",
|
|
82
|
+
"typecheck": "tsgo --noEmit"
|
|
83
|
+
}
|
|
84
|
+
}
|