@docubook/markdown 2.0.0-alpha.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.
- package/LICENSE +21 -0
- package/README.md +260 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +2319 -0
- package/dist/index.js.map +1 -0
- package/package.json +67 -0
- package/styles.css +35 -0
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
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
# @docubook/markdown
|
|
2
|
+
|
|
3
|
+
Portable MDX components and framework adapters for [DocuBook](https://docubook.pro/). Provides a collection of ready-to-use React components designed for MDX-based documentation sites, with built-in support for Next.js adapters.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# npm
|
|
9
|
+
npm install @docubook/markdown
|
|
10
|
+
|
|
11
|
+
# pnpm
|
|
12
|
+
pnpm add @docubook/markdown
|
|
13
|
+
|
|
14
|
+
# yarn
|
|
15
|
+
yarn add @docubook/markdown
|
|
16
|
+
|
|
17
|
+
# bun
|
|
18
|
+
bun add @docubook/markdown
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
### 1. Create a custom components registry
|
|
24
|
+
|
|
25
|
+
Create `lib/mdx/index.ts` to register your custom MDX components:
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
// lib/mdx/index.ts
|
|
29
|
+
import type { MdxComponentMap } from "@docubook/markdown";
|
|
30
|
+
|
|
31
|
+
export const customMdxComponents: MdxComponentMap = {
|
|
32
|
+
// add your custom components here
|
|
33
|
+
};
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### 2. Create the MDX components map
|
|
37
|
+
|
|
38
|
+
Create `lib/mdx-components.ts` to define the full component map. Import built-in components individually and merge them with your custom ones via `createMdxComponents`:
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
// lib/mdx-components.ts
|
|
42
|
+
import {
|
|
43
|
+
createMdxComponents,
|
|
44
|
+
type MdxComponentMap,
|
|
45
|
+
AccordionsMdx,
|
|
46
|
+
AccordionMdx,
|
|
47
|
+
CardsMdx,
|
|
48
|
+
ChangesMdx,
|
|
49
|
+
CodeBlock,
|
|
50
|
+
FileMdx,
|
|
51
|
+
FilesMdx,
|
|
52
|
+
FolderMdx,
|
|
53
|
+
KbdMdx,
|
|
54
|
+
NoteMdx,
|
|
55
|
+
ReleaseMdx,
|
|
56
|
+
StepsMdx,
|
|
57
|
+
StepMdx,
|
|
58
|
+
TabMdx,
|
|
59
|
+
TabsMdx,
|
|
60
|
+
TableBodyMdx,
|
|
61
|
+
TableCellMdx,
|
|
62
|
+
TableFooterMdx,
|
|
63
|
+
TableHeadMdx,
|
|
64
|
+
TableHeaderMdx,
|
|
65
|
+
TableMdx,
|
|
66
|
+
TableRowMdx,
|
|
67
|
+
MermaidMdx,
|
|
68
|
+
TooltipMdx,
|
|
69
|
+
YoutubeMdx,
|
|
70
|
+
} from "@docubook/markdown";
|
|
71
|
+
// Note: the Next.js adapter (`@docubook/markdown/next`) has been removed.
|
|
72
|
+
// Use the base components from `@docubook/markdown` instead.
|
|
73
|
+
import { customMdxComponents } from "@/lib/mdx";
|
|
74
|
+
|
|
75
|
+
const builtInOverrides: MdxComponentMap = {
|
|
76
|
+
Tabs: TabsMdx,
|
|
77
|
+
Tab: TabMdx,
|
|
78
|
+
table: TableMdx,
|
|
79
|
+
thead: TableHeaderMdx,
|
|
80
|
+
tbody: TableBodyMdx,
|
|
81
|
+
tfoot: TableFooterMdx,
|
|
82
|
+
tr: TableRowMdx,
|
|
83
|
+
th: TableHeadMdx,
|
|
84
|
+
td: TableCellMdx,
|
|
85
|
+
pre: CodeBlock,
|
|
86
|
+
Button: ButtonMdx,
|
|
87
|
+
Note: NoteMdx,
|
|
88
|
+
Step: StepMdx,
|
|
89
|
+
Steps: StepsMdx,
|
|
90
|
+
Accordion: AccordionMdx,
|
|
91
|
+
Accordions: AccordionsMdx,
|
|
92
|
+
Card: CardMdx,
|
|
93
|
+
Cards: CardsMdx,
|
|
94
|
+
Kbd: KbdMdx,
|
|
95
|
+
Release: ReleaseMdx,
|
|
96
|
+
Changes: ChangesMdx,
|
|
97
|
+
File: FileMdx,
|
|
98
|
+
Files: FilesMdx,
|
|
99
|
+
Folder: FolderMdx,
|
|
100
|
+
Youtube: YoutubeMdx,
|
|
101
|
+
Tooltip: TooltipMdx,
|
|
102
|
+
Mermaid: MermaidMdx,
|
|
103
|
+
img: ImageMdx,
|
|
104
|
+
a: LinkMdx,
|
|
105
|
+
Link: LinkMdx,
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export const mdxComponents = createMdxComponents({
|
|
109
|
+
...builtInOverrides,
|
|
110
|
+
...customMdxComponents,
|
|
111
|
+
});
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
> The Next.js adapter (`@docubook/markdown/next`) has been removed. Use the base components from `@docubook/markdown`.
|
|
115
|
+
|
|
116
|
+
### 3. Use the components map when rendering MDX
|
|
117
|
+
|
|
118
|
+
Pass `mdxComponents` to `createMdxContentService` from `@docubook/core`:
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
// lib/markdown.ts
|
|
122
|
+
import { createMdxContentService } from "@docubook/core";
|
|
123
|
+
import { cache } from "react";
|
|
124
|
+
import { mdxComponents as components } from "@/lib/mdx-components";
|
|
125
|
+
|
|
126
|
+
const docsService = createMdxContentService({
|
|
127
|
+
parseOptions: { components },
|
|
128
|
+
cacheFn: cache,
|
|
129
|
+
});
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Available import paths
|
|
133
|
+
|
|
134
|
+
| Path | Description |
|
|
135
|
+
| ------------------------------ | -------------------------------------------------------------- |
|
|
136
|
+
| `@docubook/markdown` | All server-safe components + `createMdxComponents` registry |
|
|
137
|
+
| `@docubook/markdown/client` | Client-only components (accordion, tabs, tooltip, mermaid, etc.) |
|
|
138
|
+
| `@docubook/markdown/server` | Server-side components |
|
|
139
|
+
| ~~`@docubook/markdown/next`~~ | Removed — Next.js adapter was deleted. Use base components. |
|
|
140
|
+
| `@docubook/markdown/styles.css` | Stylesheet for MDX components (required) |
|
|
141
|
+
|
|
142
|
+
> **Important:** You must import the stylesheet in your app's root layout or global CSS entry point:
|
|
143
|
+
>
|
|
144
|
+
> ```ts
|
|
145
|
+
> import "@docubook/markdown/styles.css";
|
|
146
|
+
> ```
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## Custom Components
|
|
151
|
+
|
|
152
|
+
### 1. Create your component
|
|
153
|
+
|
|
154
|
+
Add a new file under `lib/mdx/`:
|
|
155
|
+
|
|
156
|
+
```tsx
|
|
157
|
+
// lib/mdx/Callout.tsx
|
|
158
|
+
export default function Callout({ children }: { children: React.ReactNode }) {
|
|
159
|
+
return (
|
|
160
|
+
<div className="border-l-4 border-blue-500 pl-4 py-2 bg-blue-50">
|
|
161
|
+
{children}
|
|
162
|
+
</div>
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### 2. Register your component
|
|
168
|
+
|
|
169
|
+
Import and add it to `customMdxComponents` in `lib/mdx/index.ts`:
|
|
170
|
+
|
|
171
|
+
```ts
|
|
172
|
+
// lib/mdx/index.ts
|
|
173
|
+
import type { MdxComponentMap } from "@docubook/markdown";
|
|
174
|
+
import Callout from "@/lib/mdx/Callout";
|
|
175
|
+
|
|
176
|
+
export const customMdxComponents: MdxComponentMap = {
|
|
177
|
+
Callout,
|
|
178
|
+
};
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
`customMdxComponents` is already spread into `createMdxComponents` in `lib/mdx-components.ts`, so no further changes are needed. You can now use `<Callout>` in any `.mdx` file:
|
|
182
|
+
|
|
183
|
+
```mdx
|
|
184
|
+
<Callout>
|
|
185
|
+
This is a custom callout component.
|
|
186
|
+
</Callout>
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
## Customization
|
|
192
|
+
|
|
193
|
+
All components expose stable CSS class names you can target for style overrides. Import `@docubook/markdown/styles.css` for base styles, then override as needed.
|
|
194
|
+
|
|
195
|
+
### CSS Classes
|
|
196
|
+
|
|
197
|
+
| Class | Component | Description |
|
|
198
|
+
| -------------------------------- | ------------ | ------------------------------------------------- |
|
|
199
|
+
| `.mdx-expandable-code` | `CodeBlock` | The `<pre>` element inside expandable code blocks |
|
|
200
|
+
| `.mdx-expandable-code-container` | `CodeBlock` | Scroll container wrapping the `<pre>` |
|
|
201
|
+
| `.code-block-container` | `CodeBlock` | Outer wrapper of the entire code block |
|
|
202
|
+
| `.code-block-header` | `CodeBlock` | Header bar (filename, language label) |
|
|
203
|
+
| `.code-block-actions` | `CodeBlock` | Action buttons area (copy button) |
|
|
204
|
+
| `.code-block-body` | `CodeBlock` | Body area containing the code |
|
|
205
|
+
| `.code-block-expandable-footer` | `CodeBlock` | Footer with expand/collapse toggle |
|
|
206
|
+
| `.code-block-expandable-toggle` | `CodeBlock` | The expand/collapse button |
|
|
207
|
+
| `.docubook-card-group` | `Cards` | Grid container for card layouts |
|
|
208
|
+
| `[data-card-hover]` | `Card` | Card with link — target for hover styles |
|
|
209
|
+
| `[data-card-icon]` | `Card` | Icon element inside a card |
|
|
210
|
+
| `.mdx-accordion` | `Accordion` | Single accordion wrapper |
|
|
211
|
+
| `.mdx-accordion-group` | `Accordions` | Group wrapper for multiple accordions |
|
|
212
|
+
| `.mdx-accordion-group-item` | `Accordion` | Accordion when inside a group |
|
|
213
|
+
| `.mdx-accordion-header` | `Accordion` | Clickable header/trigger |
|
|
214
|
+
| `.mdx-accordion-chevron` | `Accordion` | Chevron icon in header |
|
|
215
|
+
| `.mdx-accordion-content` | `Accordion` | Collapsible content area |
|
|
216
|
+
|
|
217
|
+
### CSS Custom Properties
|
|
218
|
+
|
|
219
|
+
| Variable | Component | Description |
|
|
220
|
+
| -------------------------------- | --------- | -------------------------------------------------------- |
|
|
221
|
+
| `--docubook-card-group-template` | `Cards` | Grid column template (set automatically via `cols` prop) |
|
|
222
|
+
|
|
223
|
+
---
|
|
224
|
+
|
|
225
|
+
## API Migration Policy
|
|
226
|
+
|
|
227
|
+
The current rename rollout uses a migration phase, not an immediate hard-breaking change:
|
|
228
|
+
|
|
229
|
+
- New tags are the primary API (`Accordions`, `Cards`, `Steps`, `Step`).
|
|
230
|
+
- Legacy tags are still supported as deprecated aliases for backward compatibility `only v2`(`AccordionGroup`, `CardGroup`, `Stepper`, `StepperItem`).
|
|
231
|
+
- A true breaking change happens when deprecated aliases are removed in a future major release. `v3 remove legacy API`
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
## Available Components
|
|
236
|
+
|
|
237
|
+
Components included out of the box:
|
|
238
|
+
|
|
239
|
+
- `Accordion` / `Accordions`
|
|
240
|
+
- `Button`
|
|
241
|
+
- `Card` / `Cards`
|
|
242
|
+
- Code Block (`pre`)
|
|
243
|
+
- `Files` / `Folder` / `File`
|
|
244
|
+
- `Image` / `img`
|
|
245
|
+
- `Kbd`
|
|
246
|
+
- `Link` / `a`
|
|
247
|
+
- `Note`
|
|
248
|
+
- `Release` / `Changes`
|
|
249
|
+
- `Steps` / `Step`
|
|
250
|
+
- `Tabs` / `Tab`
|
|
251
|
+
- `Tooltip`
|
|
252
|
+
- `Mermaid` — renders Mermaid.js diagrams (flowchart, sequence, class, state, gantt, pie, ER) from ` ```mermaid ` fenced code blocks, with GFM-style pan/zoom/fullscreen controls (button and keyboard driven)
|
|
253
|
+
- `Youtube`
|
|
254
|
+
- Table (`table`, `thead`, `tbody`, `tfoot`, `tr`, `th`, `td`)
|
|
255
|
+
|
|
256
|
+
---
|
|
257
|
+
|
|
258
|
+
## License
|
|
259
|
+
|
|
260
|
+
MIT — see [LICENSE](https://github.com/DocuBook/docubook/blob/main/packages/markdown/LICENSE) for details.
|
package/dist/index.d.ts
ADDED