@docubook/core 1.1.0 → 1.1.1

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.
Files changed (2) hide show
  1. package/README.md +132 -28
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -32,32 +32,118 @@ Bun (independent runtime/package manager):
32
32
  bun add @docubook/core
33
33
  ```
34
34
 
35
- ## Dependency Management Policy
35
+ ## Usage
36
36
 
37
- Dependencies required for markdown processing are managed in this package and updated by the DocuBook author.
37
+ ### Quick Start (Recommended)
38
38
 
39
- This means app-level users should focus on content and integration. Plugin upgrades, compatibility checks, and pipeline maintenance are handled centrally by DocuBook.
39
+ ```ts
40
+ import { cache } from "react";
41
+ import { createMdxContentService } from "@docubook/core";
40
42
 
41
- ### Managed Markdown Dependencies
43
+ type Frontmatter = {
44
+ title: string;
45
+ description: string;
46
+ image: string;
47
+ date: string;
48
+ };
42
49
 
43
- - gray-matter
44
- - rehype-autolink-headings
45
- - rehype-code-titles
46
- - rehype-prism-plus
47
- - rehype-slug
48
- - remark-gfm
49
- - unist-util-visit
50
+ type TocItem = {
51
+ level: number;
52
+ text: string;
53
+ href: string;
54
+ };
50
55
 
51
- The most important part is the `remark` and `rehype` plugin stack, which is intentionally owned by this package to avoid dependency drift across apps.
56
+ const components = {
57
+ // your MDX components
58
+ };
52
59
 
53
- ## Why This Matters
60
+ const docsService = createMdxContentService<Frontmatter, TocItem>({
61
+ parseOptions: { components },
62
+ cacheFn: cache,
63
+ });
54
64
 
55
- - Consistent behavior across all DocuBook-based projects
56
- - Easier maintenance and safer upgrades
57
- - Less dependency duplication in app-level package.json files
58
- - Faster onboarding for users who only need to write docs
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
- ## Usage
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
- ## API Overview
198
+ ## Dependency Management Policy
113
199
 
114
- - `parseMdx` - Compiles raw MDX with default or custom plugin options
115
- - `createMdxContentService` - Unified high-level API for read/parse/compile/getters
116
- - `readMdxFileBySlug` - Reads `slug.mdx` or `slug/index.mdx` from docs directory
117
- - `parseMdxFile` - Converts raw file result into `frontmatter` + `tocs` + `content`
118
- - `compileParsedMdxFile` - Compiles a parsed document while preserving metadata
119
- - `extractFrontmatter` - Parses frontmatter from raw markdown/MDX
120
- - `extractTocsFromRawMdx` - Extracts headings for TOC generation
121
- - `sluggify` - Converts heading text into URL-friendly slugs
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
- If your app uses `next-mdx-remote` directly for rendering in custom components, keep that direct dependency in the app.
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docubook/core",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Shared MDX compile pipeline and markdown utilities for DocuBook",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",