@docubook/core 1.8.0 → 1.8.2
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/README.md +5 -5
- package/dist/chunk-HZJLRYAI.js +45 -0
- package/dist/chunk-HZJLRYAI.js.map +1 -0
- package/dist/index.d.ts +118 -11
- package/dist/index.js +514 -7
- package/dist/index.js.map +1 -1
- package/dist/utils.d.ts +12 -10
- package/dist/utils.js +16 -38
- package/dist/utils.js.map +1 -1
- package/package.json +8 -6
- package/dist/__tests__/compile.test.d.ts +0 -2
- package/dist/__tests__/compile.test.d.ts.map +0 -1
- package/dist/__tests__/compile.test.js +0 -122
- package/dist/__tests__/compile.test.js.map +0 -1
- package/dist/__tests__/content.test.d.ts +0 -2
- package/dist/__tests__/content.test.d.ts.map +0 -1
- package/dist/__tests__/content.test.js +0 -109
- package/dist/__tests__/content.test.js.map +0 -1
- package/dist/__tests__/extract.test.d.ts +0 -2
- package/dist/__tests__/extract.test.d.ts.map +0 -1
- package/dist/__tests__/extract.test.js +0 -95
- package/dist/__tests__/extract.test.js.map +0 -1
- package/dist/__tests__/plugins/handleCodeExpandable.test.d.ts +0 -2
- package/dist/__tests__/plugins/handleCodeExpandable.test.d.ts.map +0 -1
- package/dist/__tests__/plugins/handleCodeExpandable.test.js +0 -191
- package/dist/__tests__/plugins/handleCodeExpandable.test.js.map +0 -1
- package/dist/__tests__/plugins/handleCodeTitles.test.d.ts +0 -2
- package/dist/__tests__/plugins/handleCodeTitles.test.d.ts.map +0 -1
- package/dist/__tests__/plugins/handleCodeTitles.test.js +0 -99
- package/dist/__tests__/plugins/handleCodeTitles.test.js.map +0 -1
- package/dist/compile.d.ts +0 -28
- package/dist/compile.d.ts.map +0 -1
- package/dist/compile.js +0 -90
- package/dist/compile.js.map +0 -1
- package/dist/content.d.ts +0 -52
- package/dist/content.d.ts.map +0 -1
- package/dist/content.js +0 -102
- package/dist/content.js.map +0 -1
- package/dist/extract.d.ts +0 -13
- package/dist/extract.d.ts.map +0 -1
- package/dist/extract.js +0 -96
- package/dist/extract.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/plugins/handleCodeExpandable.d.ts +0 -4
- package/dist/plugins/handleCodeExpandable.d.ts.map +0 -1
- package/dist/plugins/handleCodeExpandable.js +0 -174
- package/dist/plugins/handleCodeExpandable.js.map +0 -1
- package/dist/plugins/handleCodeTitles.d.ts +0 -3
- package/dist/plugins/handleCodeTitles.d.ts.map +0 -1
- package/dist/plugins/handleCodeTitles.js +0 -38
- package/dist/plugins/handleCodeTitles.js.map +0 -1
- package/dist/plugins/rehypeMermaid.d.ts +0 -11
- package/dist/plugins/rehypeMermaid.d.ts.map +0 -1
- package/dist/plugins/rehypeMermaid.js +0 -34
- package/dist/plugins/rehypeMermaid.js.map +0 -1
- package/dist/types.d.ts +0 -12
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/dist/utils.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -90,8 +90,8 @@ const tocs = await docsService.getTocsForSlug("getting-started/introduction");
|
|
|
90
90
|
| `handleCodeExpandableRemark` | Remark plugin that detects `Expandable` meta on code blocks and injects expandable data attributes | transformer function |
|
|
91
91
|
| `handleCodeExpandable` | Rehype plugin that propagates expandable metadata from `<code>` to `<pre>` elements | transformer function |
|
|
92
92
|
| `rehypeMermaid` | Rehype plugin that transforms ` ```mermaid ` fenced code blocks into `<Mermaid chart="...">` elements | transformer function |
|
|
93
|
-
| `serialize` | Re-exported from
|
|
94
|
-
| `MDXRemote` | Re-exported from
|
|
93
|
+
| `serialize` | Re-exported from `@docubook/mdx-remote/serialize` for non-RSC MDX compilation workflows | `MDXRemoteSerializeResult` |
|
|
94
|
+
| `MDXRemote` | Re-exported from `@docubook/mdx-remote` for client-side MDX hydration | React component |
|
|
95
95
|
| `cn` | Merge class names using `clsx` + `tailwind-merge` | `string` |
|
|
96
96
|
| `parseDate` | Parse `dd-MM-yyyy` or ISO 8601 date strings into a Date object | `Date` |
|
|
97
97
|
| `stringToDate` | Convert a string or Date value to a Date object | `Date` |
|
|
@@ -408,7 +408,7 @@ This means app-level users should focus on content and integration. Plugin upgra
|
|
|
408
408
|
|
|
409
409
|
- clsx — class name composition for the `cn()` utility
|
|
410
410
|
- tailwind-merge — intelligent Tailwind class merging for the `cn()` utility
|
|
411
|
-
-
|
|
411
|
+
- @docubook/mdx-remote — MDX runtime/compile engine (`serialize`, `MDXRemote`)
|
|
412
412
|
|
|
413
413
|
The `remark` and `rehype` plugin stack is intentionally owned by this package to avoid dependency drift across apps.
|
|
414
414
|
|
|
@@ -421,11 +421,11 @@ The `remark` and `rehype` plugin stack is intentionally owned by this package to
|
|
|
421
421
|
|
|
422
422
|
## Notes
|
|
423
423
|
|
|
424
|
-
`@docubook/core` already includes and manages the MDX runtime/compile dependencies (including
|
|
424
|
+
`@docubook/core` already includes and manages the MDX runtime/compile dependencies (including `@docubook/mdx-remote`) as part of the package contract.
|
|
425
425
|
|
|
426
426
|
In most integrations, users only need to install `@docubook/core` and use the core APIs.
|
|
427
427
|
|
|
428
|
-
Only
|
|
428
|
+
Only import `@docubook/mdx-remote` directly in your app if your app explicitly needs it in app-level code.
|
|
429
429
|
|
|
430
430
|
For compile pipeline plugins (especially `remark` and `rehype` plugins), rely on this package and avoid re-declaring them at app level unless you have a specific override requirement.
|
|
431
431
|
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// src/utils.ts
|
|
2
|
+
import { clsx } from "clsx";
|
|
3
|
+
import { twMerge } from "tailwind-merge";
|
|
4
|
+
function cn(...inputs) {
|
|
5
|
+
return twMerge(clsx(inputs));
|
|
6
|
+
}
|
|
7
|
+
function parseDate(dateStr) {
|
|
8
|
+
if (/^\d{4}-/.test(dateStr)) return new Date(dateStr);
|
|
9
|
+
const [day, month, year] = dateStr.split("-").map(Number);
|
|
10
|
+
return new Date(year, month - 1, day);
|
|
11
|
+
}
|
|
12
|
+
function stringToDate(date) {
|
|
13
|
+
return date instanceof Date ? date : parseDate(date);
|
|
14
|
+
}
|
|
15
|
+
function formatDate(dateStrOrDate) {
|
|
16
|
+
const date = stringToDate(dateStrOrDate);
|
|
17
|
+
return date.toLocaleDateString("en-US", {
|
|
18
|
+
weekday: "long",
|
|
19
|
+
year: "numeric",
|
|
20
|
+
month: "long",
|
|
21
|
+
day: "numeric"
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
function formatDate2(dateStrOrDate) {
|
|
25
|
+
const date = stringToDate(dateStrOrDate);
|
|
26
|
+
return date.toLocaleDateString("en-US", {
|
|
27
|
+
month: "short",
|
|
28
|
+
day: "numeric",
|
|
29
|
+
year: "numeric"
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function toIsoDateOnly(dateStrOrDate) {
|
|
33
|
+
const date = stringToDate(dateStrOrDate);
|
|
34
|
+
return date.toISOString().slice(0, 10);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export {
|
|
38
|
+
cn,
|
|
39
|
+
parseDate,
|
|
40
|
+
stringToDate,
|
|
41
|
+
formatDate,
|
|
42
|
+
formatDate2,
|
|
43
|
+
toIsoDateOnly
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=chunk-HZJLRYAI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils.ts"],"sourcesContent":["import { type ClassValue, clsx } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\nimport type { Node } from \"unist\";\n\nexport interface ElementNode extends Node {\n type: string;\n tagName?: string;\n properties?: Record<string, unknown> & {\n className?: string[] | string;\n raw?: string;\n };\n data?: Record<string, unknown>;\n children?: Node[];\n raw?: string;\n language?: string;\n codeTitle?: string;\n}\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n\n/** Parse both `dd-MM-yyyy` and ISO 8601 date strings into a Date object. */\nexport function parseDate(dateStr: string): Date {\n if (/^\\d{4}-/.test(dateStr)) return new Date(dateStr);\n const [day, month, year] = dateStr.split(\"-\").map(Number);\n return new Date(year, month - 1, day);\n}\n\nexport function stringToDate(date: string | Date) {\n return date instanceof Date ? date : parseDate(date);\n}\n\n/** Format date to long format (e.g. \"Thursday, April 5, 2026\") */\nexport function formatDate(dateStrOrDate: string | Date): string {\n const date = stringToDate(dateStrOrDate);\n return date.toLocaleDateString(\"en-US\", {\n weekday: \"long\",\n year: \"numeric\",\n month: \"long\",\n day: \"numeric\",\n });\n}\n\n/** Format date to short format (e.g. \"Apr 5, 2026\") */\nexport function formatDate2(dateStrOrDate: string | Date): string {\n const date = stringToDate(dateStrOrDate);\n return date.toLocaleDateString(\"en-US\", {\n month: \"short\",\n day: \"numeric\",\n year: \"numeric\",\n });\n}\n\nexport function toIsoDateOnly(dateStrOrDate: string | Date): string {\n const date = stringToDate(dateStrOrDate);\n return date.toISOString().slice(0, 10);\n}\n"],"mappings":";AAAA,SAA0B,YAAY;AACtC,SAAS,eAAe;AAiBjB,SAAS,MAAM,QAAsB;AAC1C,SAAO,QAAQ,KAAK,MAAM,CAAC;AAC7B;AAGO,SAAS,UAAU,SAAuB;AAC/C,MAAI,UAAU,KAAK,OAAO,EAAG,QAAO,IAAI,KAAK,OAAO;AACpD,QAAM,CAAC,KAAK,OAAO,IAAI,IAAI,QAAQ,MAAM,GAAG,EAAE,IAAI,MAAM;AACxD,SAAO,IAAI,KAAK,MAAM,QAAQ,GAAG,GAAG;AACtC;AAEO,SAAS,aAAa,MAAqB;AAChD,SAAO,gBAAgB,OAAO,OAAO,UAAU,IAAI;AACrD;AAGO,SAAS,WAAW,eAAsC;AAC/D,QAAM,OAAO,aAAa,aAAa;AACvC,SAAO,KAAK,mBAAmB,SAAS;AAAA,IACtC,SAAS;AAAA,IACT,MAAM;AAAA,IACN,OAAO;AAAA,IACP,KAAK;AAAA,EACP,CAAC;AACH;AAGO,SAAS,YAAY,eAAsC;AAChE,QAAM,OAAO,aAAa,aAAa;AACvC,SAAO,KAAK,mBAAmB,SAAS;AAAA,IACtC,OAAO;AAAA,IACP,KAAK;AAAA,IACL,MAAM;AAAA,EACR,CAAC;AACH;AAEO,SAAS,cAAc,eAAsC;AAClE,QAAM,OAAO,aAAa,aAAa;AACvC,SAAO,KAAK,YAAY,EAAE,MAAM,GAAG,EAAE;AACvC;","names":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,118 @@
|
|
|
1
|
-
|
|
2
|
-
export { cn,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
export { cn, formatDate, formatDate2, parseDate, stringToDate, toIsoDateOnly } from './utils.js';
|
|
3
|
+
import { compileMDX } from '@docubook/mdx-remote/rsc';
|
|
4
|
+
import { Node } from 'unist';
|
|
5
|
+
import { Pluggable } from 'unified';
|
|
6
|
+
export { MDXRemote } from '@docubook/mdx-remote';
|
|
7
|
+
export { serialize } from '@docubook/mdx-remote/serialize';
|
|
8
|
+
import 'clsx';
|
|
9
|
+
|
|
10
|
+
type TocItem = {
|
|
11
|
+
level: number;
|
|
12
|
+
text: string;
|
|
13
|
+
href: string;
|
|
14
|
+
};
|
|
15
|
+
type MdxCompileResult<Frontmatter> = {
|
|
16
|
+
content: ReactNode;
|
|
17
|
+
frontmatter: Frontmatter;
|
|
18
|
+
scope?: Record<string, unknown>;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
type CompileMdxInput = Parameters<typeof compileMDX<Record<string, unknown>>>[0];
|
|
22
|
+
type CompileMdxOptions = NonNullable<CompileMdxInput["options"]>;
|
|
23
|
+
type CompilerMdxOptions = NonNullable<CompileMdxOptions["mdxOptions"]>;
|
|
24
|
+
type ParseMdxOptions = {
|
|
25
|
+
components?: CompileMdxInput["components"];
|
|
26
|
+
rehypePlugins?: CompilerMdxOptions["rehypePlugins"];
|
|
27
|
+
remarkPlugins?: CompilerMdxOptions["remarkPlugins"];
|
|
28
|
+
/**
|
|
29
|
+
* Whether to parse frontmatter during MDX compilation.
|
|
30
|
+
* Set to `false` when frontmatter is already extracted separately
|
|
31
|
+
* (e.g. via gray-matter) to avoid redundant parsing.
|
|
32
|
+
* Defaults to `true`.
|
|
33
|
+
*/
|
|
34
|
+
parseFrontmatter?: boolean;
|
|
35
|
+
};
|
|
36
|
+
declare const preProcess: () => (tree: Node) => Node;
|
|
37
|
+
declare const postProcess: () => (tree: Node) => Node;
|
|
38
|
+
declare function createDefaultRehypePlugins(): Pluggable[];
|
|
39
|
+
declare function createDefaultRemarkPlugins(): Pluggable[];
|
|
40
|
+
declare function parseMdx<Frontmatter>(rawMdx: string, options?: ParseMdxOptions): Promise<MdxCompileResult<Frontmatter>>;
|
|
41
|
+
|
|
42
|
+
declare const handleCodeTitles: () => (tree: Node) => void;
|
|
43
|
+
|
|
44
|
+
declare const handleCodeExpandableRemark: () => (tree: Node) => void;
|
|
45
|
+
declare const handleCodeExpandable: () => (tree: Node) => void;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Rehype plugin that transforms `<pre><code class="language-mermaid">` fenced
|
|
49
|
+
* blocks into `<Mermaid chart="...">` elements.
|
|
50
|
+
*
|
|
51
|
+
* This allows Mermaid diagram definitions to be authored via standard fenced
|
|
52
|
+
* code blocks (````mermaid) which avoids JSX parsing collisions with
|
|
53
|
+
* Mermaid's `{...}` (decision nodes) and `[...]` (label nodes) syntax.
|
|
54
|
+
*/
|
|
55
|
+
declare const rehypeMermaid: () => (tree: Node) => void;
|
|
56
|
+
|
|
57
|
+
declare function sluggify(text: string): string;
|
|
58
|
+
declare function extractTocsFromRawMdx(rawMdx: string): TocItem[];
|
|
59
|
+
declare function extractFrontmatter<Frontmatter>(content: string): Frontmatter;
|
|
60
|
+
/**
|
|
61
|
+
* Extract frontmatter and return both the parsed data and the content
|
|
62
|
+
* with the frontmatter block stripped. Avoids a second parse by compileMDX.
|
|
63
|
+
*/
|
|
64
|
+
declare function extractFrontmatterWithContent<Frontmatter>(content: string): {
|
|
65
|
+
frontmatter: Frontmatter;
|
|
66
|
+
strippedContent: string;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
type CacheFn = <T extends (...args: any[]) => any>(fn: T) => T;
|
|
70
|
+
type ReadMdxFileResult = {
|
|
71
|
+
content: string;
|
|
72
|
+
/** Relative path used for UI links (e.g. "docs/getting-started/index.mdx"). */
|
|
73
|
+
filePath: string;
|
|
74
|
+
/** Absolute path on disk — available when file was read by readMdxFileBySlug. */
|
|
75
|
+
absoluteFilePath?: string;
|
|
76
|
+
};
|
|
77
|
+
type ParsedMdxFile<Frontmatter, T extends TocItem = TocItem> = {
|
|
78
|
+
/** Raw content with frontmatter block stripped — ready to pass to compileMDX. */
|
|
79
|
+
content: string;
|
|
80
|
+
filePath: string;
|
|
81
|
+
frontmatter: Frontmatter;
|
|
82
|
+
tocs: T[];
|
|
83
|
+
};
|
|
84
|
+
type CompiledMdxFile<Frontmatter, T extends TocItem = TocItem> = MdxCompileResult<Frontmatter> & {
|
|
85
|
+
filePath: string;
|
|
86
|
+
tocs: T[];
|
|
87
|
+
};
|
|
88
|
+
type ReadMdxBySlugOptions = {
|
|
89
|
+
rootDir?: string;
|
|
90
|
+
docsDir?: string;
|
|
91
|
+
};
|
|
92
|
+
declare function readMdxFileBySlug(slug: string, options?: ReadMdxBySlugOptions): Promise<ReadMdxFileResult>;
|
|
93
|
+
type ParseMdxFileOptions<T extends TocItem> = {
|
|
94
|
+
tocsExtractor?: (rawMdx: string) => T[];
|
|
95
|
+
};
|
|
96
|
+
declare function parseMdxFile<Frontmatter, T extends TocItem = TocItem>(raw: ReadMdxFileResult, options?: ParseMdxFileOptions<T>): ParsedMdxFile<Frontmatter, T>;
|
|
97
|
+
declare function compileParsedMdxFile<Frontmatter, T extends TocItem = TocItem>(parsed: ParsedMdxFile<Frontmatter, T>, options?: ParseMdxOptions): Promise<CompiledMdxFile<Frontmatter, T>>;
|
|
98
|
+
type CreateMdxContentServiceOptions<Frontmatter, T extends TocItem = TocItem> = {
|
|
99
|
+
parseOptions?: ParseMdxOptions;
|
|
100
|
+
readOptions?: ReadMdxBySlugOptions;
|
|
101
|
+
tocsExtractor?: (rawMdx: string) => T[];
|
|
102
|
+
cacheFn?: CacheFn;
|
|
103
|
+
/**
|
|
104
|
+
* Optional hook to enrich or transform frontmatter after parsing.
|
|
105
|
+
* Called with the parsed frontmatter and the absolute file path.
|
|
106
|
+
* Runs at build time during static generation — ideal for injecting
|
|
107
|
+
* fallback values (e.g. git last-modified date when `date` is absent).
|
|
108
|
+
*/
|
|
109
|
+
frontmatterEnricher?: (frontmatter: Frontmatter, absoluteFilePath: string) => Frontmatter | Promise<Frontmatter>;
|
|
110
|
+
};
|
|
111
|
+
declare function createMdxContentService<Frontmatter, T extends TocItem = TocItem>(options?: CreateMdxContentServiceOptions<Frontmatter, T>): {
|
|
112
|
+
getParsedForSlug: (slug: string) => Promise<ParsedMdxFile<Frontmatter, T>>;
|
|
113
|
+
getCompiledForSlug: (slug: string) => Promise<CompiledMdxFile<Frontmatter, T>>;
|
|
114
|
+
getFrontmatterForSlug: (slug: string) => Promise<Frontmatter>;
|
|
115
|
+
getTocsForSlug: (slug: string) => Promise<T[]>;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export { type CompiledMdxFile, type CreateMdxContentServiceOptions, type MdxCompileResult, type ParseMdxOptions, type ParsedMdxFile, type ReadMdxFileResult, type TocItem, compileParsedMdxFile, createDefaultRehypePlugins, createDefaultRemarkPlugins, createMdxContentService, extractFrontmatter, extractFrontmatterWithContent, extractTocsFromRawMdx, handleCodeExpandable, handleCodeExpandableRemark, handleCodeTitles, parseMdx, parseMdxFile, postProcess, preProcess, readMdxFileBySlug, rehypeMermaid, sluggify };
|