@docubook/core 1.1.0 → 1.1.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/LICENSE +21 -0
- package/README.md +132 -28
- package/dist/extract.js +1 -1
- package/dist/extract.js.map +1 -1
- package/package.json +5 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Wildan Nursahidan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -32,32 +32,118 @@ Bun (independent runtime/package manager):
|
|
|
32
32
|
bun add @docubook/core
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
##
|
|
35
|
+
## Usage
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
### Quick Start (Recommended)
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
```ts
|
|
40
|
+
import { cache } from "react";
|
|
41
|
+
import { createMdxContentService } from "@docubook/core";
|
|
40
42
|
|
|
41
|
-
|
|
43
|
+
type Frontmatter = {
|
|
44
|
+
title: string;
|
|
45
|
+
description: string;
|
|
46
|
+
image: string;
|
|
47
|
+
date: string;
|
|
48
|
+
};
|
|
42
49
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
- remark-gfm
|
|
49
|
-
- unist-util-visit
|
|
50
|
+
type TocItem = {
|
|
51
|
+
level: number;
|
|
52
|
+
text: string;
|
|
53
|
+
href: string;
|
|
54
|
+
};
|
|
50
55
|
|
|
51
|
-
|
|
56
|
+
const components = {
|
|
57
|
+
// your MDX components
|
|
58
|
+
};
|
|
52
59
|
|
|
53
|
-
|
|
60
|
+
const docsService = createMdxContentService<Frontmatter, TocItem>({
|
|
61
|
+
parseOptions: { components },
|
|
62
|
+
cacheFn: cache,
|
|
63
|
+
});
|
|
54
64
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
65
|
+
const doc = await docsService.getCompiledForSlug("getting-started/introduction");
|
|
66
|
+
const frontmatter = await docsService.getFrontmatterForSlug("getting-started/introduction");
|
|
67
|
+
const tocs = await docsService.getTocsForSlug("getting-started/introduction");
|
|
68
|
+
```
|
|
59
69
|
|
|
60
|
-
|
|
70
|
+
### Importable APIs and What They Do
|
|
71
|
+
|
|
72
|
+
#### Runtime APIs
|
|
73
|
+
|
|
74
|
+
- `parseMdx`: Compile raw MDX string with optional custom parse options. Returns `MdxCompileResult<Frontmatter>`.
|
|
75
|
+
- `createMdxContentService`: Create slug-based docs service (`getParsedForSlug`, `getCompiledForSlug`, `getFrontmatterForSlug`, `getTocsForSlug`). Returns a service object.
|
|
76
|
+
- `readMdxFileBySlug`: Read `slug.mdx` or `slug/index.mdx` from docs directory. Returns `ReadMdxFileResult`.
|
|
77
|
+
- `parseMdxFile`: Convert raw file result into `frontmatter`, `tocs`, `content`, `filePath`. Returns `ParsedMdxFile<Frontmatter, TocItem>`.
|
|
78
|
+
- `compileParsedMdxFile`: Compile parsed MDX while preserving metadata and TOCs. Returns `CompiledMdxFile<Frontmatter, TocItem>`.
|
|
79
|
+
- `extractFrontmatter`: Parse frontmatter only from raw markdown/MDX. Returns `Frontmatter`.
|
|
80
|
+
- `extractTocsFromRawMdx`: Extract headings for table of contents generation. Returns `TocItem[]`.
|
|
81
|
+
- `sluggify`: Convert heading text into URL-safe slug. Returns `string`.
|
|
82
|
+
- `createDefaultRehypePlugins`: Get default DocuBook rehype plugin stack. Returns `unknown[]`.
|
|
83
|
+
- `createDefaultRemarkPlugins`: Get default DocuBook remark plugin stack. Returns `unknown[]`.
|
|
84
|
+
- `preProcess`: Add pre-processing behavior for code blocks (advanced customization). Returns a transformer function.
|
|
85
|
+
- `postProcess`: Add post-processing behavior for code blocks (advanced customization). Returns a transformer function.
|
|
86
|
+
- `handleCodeTitles`: Move code title metadata to `<pre>` attributes (advanced customization). Returns a transformer function.
|
|
87
|
+
|
|
88
|
+
#### Type Exports
|
|
89
|
+
|
|
90
|
+
| Type | Purpose |
|
|
91
|
+
| -------------------------------- | --------------------------------------------- |
|
|
92
|
+
| `MdxCompileResult` | Result shape for compiled MDX content |
|
|
93
|
+
| `TocItem` | Heading item structure used by TOC extraction |
|
|
94
|
+
| `ParseMdxOptions` | Options for `parseMdx` compile behavior |
|
|
95
|
+
| `ReadMdxFileResult` | Return type for `readMdxFileBySlug` |
|
|
96
|
+
| `ParsedMdxFile` | Parsed file structure before compile |
|
|
97
|
+
| `CompiledMdxFile` | Compiled file structure with metadata and TOC |
|
|
98
|
+
| `CreateMdxContentServiceOptions` | Options for creating the content service |
|
|
99
|
+
|
|
100
|
+
### Quick Import Recipes
|
|
101
|
+
|
|
102
|
+
#### 1. Compile raw MDX only
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
import { parseMdx } from "@docubook/core";
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Use this when your source is already in memory and you only need compiled content.
|
|
109
|
+
|
|
110
|
+
#### 2. Read frontmatter only
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
import { extractFrontmatter } from "@docubook/core";
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Use this for metadata pages where full MDX compilation is unnecessary.
|
|
117
|
+
|
|
118
|
+
#### 3. Build TOC from raw content
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
import { extractTocsFromRawMdx } from "@docubook/core";
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Use this when you need heading navigation from markdown/MDX text.
|
|
125
|
+
|
|
126
|
+
#### 4. Slug-based docs service (recommended for app integration)
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
import { createMdxContentService } from "@docubook/core";
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Use this as the default app-level integration for frontmatter, TOC, and compiled docs in one service.
|
|
133
|
+
|
|
134
|
+
#### 5. Low-level file pipeline (advanced)
|
|
135
|
+
|
|
136
|
+
```ts
|
|
137
|
+
import {
|
|
138
|
+
readMdxFileBySlug,
|
|
139
|
+
parseMdxFile,
|
|
140
|
+
compileParsedMdxFile,
|
|
141
|
+
} from "@docubook/core";
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Use this when you need full control over each pipeline step.
|
|
145
|
+
|
|
146
|
+
### Basic Compile Helpers
|
|
61
147
|
|
|
62
148
|
```ts
|
|
63
149
|
import {
|
|
@@ -109,20 +195,38 @@ const docsService = createMdxContentService<Frontmatter>({
|
|
|
109
195
|
const doc = await docsService.getCompiledForSlug("getting-started/introduction");
|
|
110
196
|
```
|
|
111
197
|
|
|
112
|
-
##
|
|
198
|
+
## Dependency Management Policy
|
|
113
199
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
-
|
|
121
|
-
-
|
|
200
|
+
Dependencies required for markdown processing are managed in this package and updated by the DocuBook author.
|
|
201
|
+
|
|
202
|
+
This means app-level users should focus on content and integration. Plugin upgrades, compatibility checks, and pipeline maintenance are handled centrally by DocuBook.
|
|
203
|
+
|
|
204
|
+
### Managed Markdown Dependencies
|
|
205
|
+
|
|
206
|
+
- gray-matter
|
|
207
|
+
- rehype-autolink-headings
|
|
208
|
+
- rehype-code-titles
|
|
209
|
+
- rehype-prism-plus
|
|
210
|
+
- rehype-slug
|
|
211
|
+
- remark-gfm
|
|
212
|
+
- unist-util-visit
|
|
213
|
+
|
|
214
|
+
The `remark` and `rehype` plugin stack is intentionally owned by this package to avoid dependency drift across apps.
|
|
215
|
+
|
|
216
|
+
## Why This Matters
|
|
217
|
+
|
|
218
|
+
- Consistent behavior across all DocuBook-based projects
|
|
219
|
+
- Easier maintenance and safer upgrades
|
|
220
|
+
- Less dependency duplication in app-level package.json files
|
|
221
|
+
- Faster onboarding for users who only need to write docs
|
|
122
222
|
|
|
123
223
|
## Notes
|
|
124
224
|
|
|
125
|
-
|
|
225
|
+
`@docubook/core` already includes and manages the MDX runtime/compile dependencies (including `next-mdx-remote`) as part of the package contract.
|
|
226
|
+
|
|
227
|
+
In most integrations, users only need to install `@docubook/core` and use the core APIs.
|
|
228
|
+
|
|
229
|
+
Only add `next-mdx-remote` directly in your app if your app explicitly imports it in app-level code.
|
|
126
230
|
|
|
127
231
|
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.
|
|
128
232
|
|
package/dist/extract.js
CHANGED
|
@@ -5,7 +5,7 @@ export function sluggify(text) {
|
|
|
5
5
|
}
|
|
6
6
|
export function extractTocsFromRawMdx(rawMdx) {
|
|
7
7
|
// Match code blocks, markdown headings, and <Release version="x.y.z" />.
|
|
8
|
-
const combinedRegex = /(```[\s\S]*?```)|^(#{2,4})\s(.+)$|<Release
|
|
8
|
+
const combinedRegex = /(```[\s\S]*?```)|^(#{2,4})\s(.+)$|<Release\s+version="([^"]+)"/gm;
|
|
9
9
|
const extractedHeadings = [];
|
|
10
10
|
let match;
|
|
11
11
|
while ((match = combinedRegex.exec(rawMdx)) !== null) {
|
package/dist/extract.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract.js","sourceRoot":"","sources":["../src/extract.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AAGjC,MAAM,UAAU,QAAQ,CAAC,IAAY;IACjC,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACrD,OAAO,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;AAC3C,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,MAAc;IAChD,yEAAyE;IACzE,MAAM,aAAa,GAAG,
|
|
1
|
+
{"version":3,"file":"extract.js","sourceRoot":"","sources":["../src/extract.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AAGjC,MAAM,UAAU,QAAQ,CAAC,IAAY;IACjC,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACrD,OAAO,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;AAC3C,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,MAAc;IAChD,yEAAyE;IACzE,MAAM,aAAa,GAAG,kEAAkE,CAAC;IACzF,MAAM,iBAAiB,GAAc,EAAE,CAAC;IAExC,IAAI,KAA6B,CAAC;IAClC,OAAO,CAAC,KAAK,GAAG,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;QACnD,IAAI,KAAK,CAAC,CAAC,CAAC;YAAE,SAAS;QAEvB,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;YACX,MAAM,YAAY,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;YACrC,MAAM,WAAW,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;YACpC,iBAAiB,CAAC,IAAI,CAAC;gBACnB,KAAK,EAAE,YAAY;gBACnB,IAAI,EAAE,WAAW;gBACjB,IAAI,EAAE,IAAI,QAAQ,CAAC,WAAW,CAAC,EAAE;aACpC,CAAC,CAAC;YACH,SAAS;QACb,CAAC;QAED,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;YACX,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;YACzB,iBAAiB,CAAC,IAAI,CAAC;gBACnB,KAAK,EAAE,CAAC;gBACR,IAAI,EAAE,IAAI,OAAO,EAAE;gBACnB,IAAI,EAAE,IAAI,OAAO,EAAE;aACtB,CAAC,CAAC;QACP,CAAC;IACL,CAAC;IAED,OAAO,iBAAiB,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAc,OAAe;IAC3D,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,IAAmB,CAAC;AAC/C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docubook/core",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Shared MDX compile pipeline and markdown utilities for DocuBook",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -30,7 +30,10 @@
|
|
|
30
30
|
"homepage": "https://docubook.pro/",
|
|
31
31
|
"repository": {
|
|
32
32
|
"type": "git",
|
|
33
|
-
"url": "git+https://github.com/DocuBook/docubook"
|
|
33
|
+
"url": "git+https://github.com/DocuBook/docubook.git"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
34
37
|
},
|
|
35
38
|
"author": "wildan.nrs",
|
|
36
39
|
"author-url": "https://wildan.dev",
|