@docubook/markdown 2.1.2 → 2.2.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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @docubook/markdown
2
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.
3
+ Portable MDX components and the component registry for [DocuBook](https://docubook.pro/). Components are authored as markdown directives, not JSX — the registry maps directive names to React components and is consumed by the Flame build (or any MDX renderer that accepts a components map).
4
4
 
5
5
  ## Installation
6
6
 
@@ -20,138 +20,83 @@ bun add @docubook/markdown
20
20
 
21
21
  ## Usage
22
22
 
23
- ### 1. Create a custom components registry
23
+ ### 1. Create the components map
24
24
 
25
- Create `lib/mdx/index.ts` to register your custom MDX components:
25
+ `createMdxComponents` returns the built-in component map; pass your own components to extend or override it:
26
26
 
27
27
  ```ts
28
- // lib/mdx/index.ts
29
- import type { MdxComponentMap } from "@docubook/markdown";
28
+ // lib/mdx-components.ts
29
+ import { createMdxComponents, type MdxComponentMap } from "@docubook/markdown";
30
30
 
31
- export const customMdxComponents: MdxComponentMap = {
32
- // add your custom components here
31
+ const customComponents: MdxComponentMap = {
32
+ // optional: add or override components here
33
33
  };
34
- ```
35
34
 
36
- ### 2. Create the MDX components map
35
+ export const mdxComponents = createMdxComponents(customComponents);
36
+ ```
37
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`:
38
+ ### 2. Pass the map when rendering MDX
39
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
- };
40
+ ```tsx
41
+ // e.g. with @docubook/core's MDXRemote
42
+ import { MDXRemote } from "@docubook/core";
43
+ import { mdxComponents } from "@/lib/mdx-components";
107
44
 
108
- export const mdxComponents = createMdxComponents({
109
- ...builtInOverrides,
110
- ...customMdxComponents,
111
- });
45
+ export function Doc({ serialized }) {
46
+ return <MDXRemote {...serialized} components={mdxComponents} />;
47
+ }
112
48
  ```
113
49
 
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
50
+ ### 3. Import the stylesheet
117
51
 
118
- Pass `mdxComponents` to `createMdxContentService` from `@docubook/core`:
52
+ Required — import it in your app's root layout or global CSS entry point:
119
53
 
120
54
  ```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
- });
55
+ import "@docubook/markdown/styles.css";
130
56
  ```
131
57
 
132
58
  ### Available import paths
133
59
 
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) |
60
+ | Path | Description |
61
+ | ---------------------------------- | ---------------------------------------------------- |
62
+ | `@docubook/markdown` | The registry (`createMdxComponents`, `MdxComponentMap`) |
63
+ | `@docubook/markdown/styles.css` | Stylesheet for the built-in components (required) |
141
64
 
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
- > ```
65
+ ## Built-in components
147
66
 
148
- ---
67
+ Built-ins are registered under these keys and authored as directives (the v2 authoring contract — no JSX tags):
68
+
69
+ | Registry key | Authored as |
70
+ | ------------------------------------- | --------------------------------------------------------------------------- |
71
+ | `Tab` / `Tabs` | `:::tab` / `::::tabs` |
72
+ | `Accordion` / `Accordions` | `:::accordion` / `::::accordions` |
73
+ | `Card` / `Cards` | `:::card` / `::::cards` |
74
+ | `Step` / `Steps` | `:::step` / `::::steps` |
75
+ | `Tree` | `::::tree` |
76
+ | `Youtube` | `::youtube{videoId="…"}` |
77
+ | `Tooltip` | `:tooltip[label]{tip="…"}` |
78
+ | `Mermaid` | fenced `mermaid` code block |
79
+ | `Tip` / `Info` / `Warning` / `Danger` / `Success` | `:::tip` / `:::info` / `:::warning` / `:::danger` / `:::success` |
80
+ | `pre` / `img` / `Image` / `a` / `Link` | markdown elements — rendered as `CodeBlock`, `ImageMdx`, `LinkMdx` |
81
+ | `table` / `thead` / `tbody` / `tfoot` / `tr` / `th` / `td` | markdown tables — rendered as the table components |
82
+
83
+ ### GFM alerts
84
+
85
+ GitHub alert blockquotes render through the same callout components, with the GitHub label as title:
86
+
87
+ | Markdown | Renders as |
88
+ | ----------------- | --------------------------------- |
89
+ | `> [!NOTE]` | `Info` |
90
+ | `> [!TIP]` | `Tip` |
91
+ | `> [!IMPORTANT]` | `GfmImportant` (GitHub purple) |
92
+ | `> [!WARNING]` | `Warning` |
93
+ | `> [!CAUTION]` | `Danger` |
149
94
 
150
- ## Custom Components
95
+ `GfmImportant` exists for GFM alerts only — deliberately not registered as `Important`, so `:::important` is not a directive.
151
96
 
152
- ### 1. Create your component
97
+ ## Custom components
153
98
 
154
- Add a new file under `lib/mdx/`:
99
+ Add a component and register it through the map:
155
100
 
156
101
  ```tsx
157
102
  // lib/mdx/Callout.tsx
@@ -164,28 +109,20 @@ export default function Callout({ children }: { children: React.ReactNode }) {
164
109
  }
165
110
  ```
166
111
 
167
- ### 2. Register your component
168
-
169
- Import and add it to `customMdxComponents` in `lib/mdx/index.ts`:
170
-
171
112
  ```ts
172
- // lib/mdx/index.ts
173
- import type { MdxComponentMap } from "@docubook/markdown";
113
+ // lib/mdx-components.ts
114
+ import { createMdxComponents, type MdxComponentMap } from "@docubook/markdown";
174
115
  import Callout from "@/lib/mdx/Callout";
175
116
 
176
- export const customMdxComponents: MdxComponentMap = {
117
+ const customComponents: MdxComponentMap = {
177
118
  Callout,
178
119
  };
179
- ```
180
120
 
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>
121
+ export const mdxComponents = createMdxComponents(customComponents);
187
122
  ```
188
123
 
124
+ The component is now available in `.mdx` files, and custom entries override built-ins on key conflicts.
125
+
189
126
  ---
190
127
 
191
128
  ## Customization
@@ -222,39 +159,6 @@ All components expose stable CSS class names you can target for style overrides.
222
159
 
223
160
  ---
224
161
 
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
162
  ## License
259
163
 
260
164
  MIT — see [LICENSE](https://github.com/DocuBook/docubook/blob/main/packages/markdown/LICENSE) for details.
@@ -1,7 +1,7 @@
1
1
  import type { CSSProperties, HTMLAttributes, ReactNode } from "react";
2
- export type CalloutType = "tip" | "info" | "danger" | "warning" | "success";
2
+ export type CalloutType = "tip" | "info" | "danger" | "warning" | "success" | "important";
3
3
  type CalloutProps = HTMLAttributes<HTMLElement> & {
4
- /** Internal — set by the registry variant (Tip/Info/Danger/Warning/Success). */
4
+ /** Internal — set by the registry variant (Tip/Info/Danger/Warning/Success/GfmImportant). */
5
5
  type: CalloutType;
6
6
  /** Optional; falls back to the callout label (Tip, Info, …). */
7
7
  title?: string;
package/dist/index.js CHANGED
@@ -40041,11 +40041,11 @@ var $M = {
40041
40041
  defaultIcon: "TriangleAlert"
40042
40042
  },
40043
40043
  success: {
40044
- border: "hsl(137 50% 35%)",
40045
- bg: "hsl(137 50% 35% / 0.16)",
40044
+ border: "hsl(160 84% 30%)",
40045
+ bg: "hsl(160 84% 30% / 0.16)",
40046
40046
  text: "hsl(var(--foreground, 220 30% 15%))",
40047
- header: "hsl(137 50% 35%)",
40048
- content: "hsl(137 50% 35% / 0.75)",
40047
+ header: "hsl(160 84% 30%)",
40048
+ content: "hsl(160 84% 30% / 0.75)",
40049
40049
  defaultIcon: "CircleCheck"
40050
40050
  },
40051
40051
  info: {
@@ -40063,13 +40063,22 @@ var $M = {
40063
40063
  header: "hsl(137 50% 35%)",
40064
40064
  content: "hsl(137 50% 35% / 0.75)",
40065
40065
  defaultIcon: "Lightbulb"
40066
+ },
40067
+ important: {
40068
+ border: "hsl(261 69% 59%)",
40069
+ bg: "hsl(261 69% 59% / 0.16)",
40070
+ text: "hsl(var(--foreground, 220 30% 15%))",
40071
+ header: "hsl(261 69% 59%)",
40072
+ content: "hsl(261 69% 59% / 0.75)",
40073
+ defaultIcon: "MessageSquareWarning"
40066
40074
  }
40067
40075
  }, eN = {
40068
40076
  tip: "Tip",
40069
40077
  info: "Info",
40070
40078
  danger: "Danger",
40071
40079
  warning: "Warning",
40072
- success: "Success"
40080
+ success: "Success",
40081
+ important: "Important"
40073
40082
  };
40074
40083
  function tN({ type: e, title: t, children: n, style: r, className: i, ...a }) {
40075
40084
  let o = $M[e];
@@ -41767,6 +41776,7 @@ function cP(e = {}) {
41767
41776
  Danger: sP("danger"),
41768
41777
  Warning: sP("warning"),
41769
41778
  Success: sP("success"),
41779
+ GfmImportant: sP("important"),
41770
41780
  Steps: EN,
41771
41781
  Step: DN,
41772
41782
  Accordion: rN,