cms-renderer 0.6.5 → 0.6.7
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 +11 -11
- package/dist/lib/cms-api.d.ts +1 -0
- package/dist/lib/cms-api.js +11 -1
- package/dist/lib/cms-api.js.map +1 -1
- package/dist/lib/custom-schemas.js +17 -2
- package/dist/lib/custom-schemas.js.map +1 -1
- package/dist/lib/docs-markdown.d.ts +1 -0
- package/dist/lib/docs-markdown.js +103 -14
- package/dist/lib/docs-markdown.js.map +1 -1
- package/dist/lib/parametric-route.d.ts +41 -0
- package/dist/lib/parametric-route.js +686 -0
- package/dist/lib/parametric-route.js.map +1 -0
- package/dist/lib/proxy.js +8 -20
- package/dist/lib/proxy.js.map +1 -1
- package/dist/lib/renderer.d.ts +7 -23
- package/dist/lib/renderer.js +179 -85
- package/dist/lib/renderer.js.map +1 -1
- package/dist/lib/schema.d.ts +24 -7
- package/dist/lib/schema.js +62 -8
- package/dist/lib/schema.js.map +1 -1
- package/package.json +8 -1
|
@@ -146,10 +146,81 @@ async function initMarkdown() {
|
|
|
146
146
|
|
|
147
147
|
// lib/docs-markdown.tsx
|
|
148
148
|
import { Fragment as Fragment3 } from "react";
|
|
149
|
-
import {
|
|
149
|
+
import { bundledLanguages, createHighlighter } from "shiki";
|
|
150
150
|
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
151
151
|
var defaultClassName = "cms-docs-markdown";
|
|
152
152
|
var markdownInitPromise;
|
|
153
|
+
var PRELOADED_LANGS = [
|
|
154
|
+
// Web
|
|
155
|
+
"typescript",
|
|
156
|
+
"javascript",
|
|
157
|
+
"tsx",
|
|
158
|
+
"jsx",
|
|
159
|
+
"html",
|
|
160
|
+
"css",
|
|
161
|
+
"scss",
|
|
162
|
+
// Systems
|
|
163
|
+
"c",
|
|
164
|
+
"cpp",
|
|
165
|
+
"rust",
|
|
166
|
+
"go",
|
|
167
|
+
// Enterprise
|
|
168
|
+
"java",
|
|
169
|
+
"csharp",
|
|
170
|
+
"kotlin",
|
|
171
|
+
"swift",
|
|
172
|
+
// Scripting
|
|
173
|
+
"python",
|
|
174
|
+
"ruby",
|
|
175
|
+
"php",
|
|
176
|
+
"bash",
|
|
177
|
+
"shellscript",
|
|
178
|
+
"powershell",
|
|
179
|
+
// Data
|
|
180
|
+
"json",
|
|
181
|
+
"yaml",
|
|
182
|
+
"toml",
|
|
183
|
+
"xml",
|
|
184
|
+
"sql",
|
|
185
|
+
"graphql",
|
|
186
|
+
// Other
|
|
187
|
+
"markdown",
|
|
188
|
+
"dockerfile"
|
|
189
|
+
];
|
|
190
|
+
var highlighterPromise;
|
|
191
|
+
var loadedLanguages = new Set(PRELOADED_LANGS);
|
|
192
|
+
async function getHighlighter() {
|
|
193
|
+
highlighterPromise ??= createHighlighter({
|
|
194
|
+
themes: ["github-dark"],
|
|
195
|
+
langs: PRELOADED_LANGS
|
|
196
|
+
});
|
|
197
|
+
return highlighterPromise;
|
|
198
|
+
}
|
|
199
|
+
async function ensureLanguageLoaded(highlighter, lang) {
|
|
200
|
+
if (loadedLanguages.has(lang)) {
|
|
201
|
+
return lang;
|
|
202
|
+
}
|
|
203
|
+
if (lang in bundledLanguages) {
|
|
204
|
+
try {
|
|
205
|
+
await highlighter.loadLanguage(lang);
|
|
206
|
+
loadedLanguages.add(lang);
|
|
207
|
+
return lang;
|
|
208
|
+
} catch {
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
if (typeof window === "undefined") {
|
|
215
|
+
markdownInitPromise = initMarkdown();
|
|
216
|
+
highlighterPromise = createHighlighter({
|
|
217
|
+
themes: ["github-dark"],
|
|
218
|
+
langs: PRELOADED_LANGS
|
|
219
|
+
});
|
|
220
|
+
Promise.all([markdownInitPromise, highlighterPromise]).then(
|
|
221
|
+
() => console.log(`[docs-markdown] WASM and Shiki pre-warmed (${PRELOADED_LANGS.length} languages)`)
|
|
222
|
+
).catch((err) => console.error("[docs-markdown] Pre-warm failed:", err));
|
|
223
|
+
}
|
|
153
224
|
function markdownStartsWithHeading(markdown) {
|
|
154
225
|
return /^\s*#\s+/.test(markdown);
|
|
155
226
|
}
|
|
@@ -170,24 +241,33 @@ function buildComponentProps(type, props) {
|
|
|
170
241
|
}
|
|
171
242
|
function normalizeLanguage(lang) {
|
|
172
243
|
if (typeof lang !== "string") {
|
|
173
|
-
return "
|
|
244
|
+
return "";
|
|
174
245
|
}
|
|
175
246
|
const normalized = lang.trim().toLowerCase();
|
|
176
|
-
return normalized
|
|
247
|
+
return normalized;
|
|
248
|
+
}
|
|
249
|
+
function decodeHtmlEntities(value) {
|
|
250
|
+
return value.replaceAll("<", "<").replaceAll(">", ">").replaceAll(""", '"').replaceAll("'", "'").replaceAll("&", "&");
|
|
177
251
|
}
|
|
178
252
|
async function renderHighlightedCode(code, lang) {
|
|
179
253
|
const language = normalizeLanguage(lang);
|
|
254
|
+
const displayLanguage = language || "text";
|
|
180
255
|
try {
|
|
181
|
-
const
|
|
182
|
-
|
|
256
|
+
const highlighter = await getHighlighter();
|
|
257
|
+
const resolvedLang = await ensureLanguageLoaded(highlighter, language);
|
|
258
|
+
if (!resolvedLang) {
|
|
259
|
+
return /* @__PURE__ */ jsx3("pre", { className: `language-${displayLanguage}`, children: /* @__PURE__ */ jsx3("code", { className: `language-${displayLanguage}`, children: code }) });
|
|
260
|
+
}
|
|
261
|
+
const result = highlighter.codeToTokens(code, {
|
|
262
|
+
lang: resolvedLang,
|
|
183
263
|
theme: "github-dark"
|
|
184
264
|
});
|
|
185
265
|
return /* @__PURE__ */ jsx3(
|
|
186
266
|
"pre",
|
|
187
267
|
{
|
|
188
|
-
className: `shiki language-${
|
|
268
|
+
className: `shiki language-${displayLanguage}`,
|
|
189
269
|
style: { backgroundColor: result.bg, color: result.fg },
|
|
190
|
-
children: /* @__PURE__ */ jsx3("code", { className: `shiki_code language-${
|
|
270
|
+
children: /* @__PURE__ */ jsx3("code", { className: `shiki_code language-${displayLanguage}`, "data-language": displayLanguage, children: (() => {
|
|
191
271
|
const lineOccurrences = /* @__PURE__ */ new Map();
|
|
192
272
|
return result.tokens.map((line, lineIndex) => {
|
|
193
273
|
const isLastLine = lineIndex === result.tokens.length - 1;
|
|
@@ -208,27 +288,33 @@ async function renderHighlightedCode(code, lang) {
|
|
|
208
288
|
}
|
|
209
289
|
);
|
|
210
290
|
} catch {
|
|
211
|
-
return /* @__PURE__ */ jsx3("pre", { className: `language-${
|
|
291
|
+
return /* @__PURE__ */ jsx3("pre", { className: `language-${displayLanguage}`, children: /* @__PURE__ */ jsx3("code", { className: `language-${displayLanguage}`, children: code }) });
|
|
212
292
|
}
|
|
213
293
|
}
|
|
214
|
-
async function renderNode(node, components, renderImage, key) {
|
|
294
|
+
async function renderNode(node, components, renderImage, imageIndexRef, key) {
|
|
215
295
|
if (isTextNode2(node)) {
|
|
216
|
-
return node;
|
|
296
|
+
return decodeHtmlEntities(node);
|
|
217
297
|
}
|
|
218
298
|
const { type, props, children } = node;
|
|
219
299
|
if (type === NodeType3.IMG && renderImage) {
|
|
300
|
+
const imageIndex = imageIndexRef.current;
|
|
301
|
+
imageIndexRef.current += 1;
|
|
220
302
|
return /* @__PURE__ */ jsx3(Fragment3, { children: renderImage({
|
|
221
303
|
src: typeof props?.src === "string" ? props.src : "",
|
|
222
304
|
alt: typeof props?.alt === "string" ? props.alt : "",
|
|
223
|
-
title: typeof props?.title === "string" ? props.title : void 0
|
|
305
|
+
title: typeof props?.title === "string" ? props.title : void 0,
|
|
306
|
+
loading: imageIndex === 0 ? "eager" : "lazy"
|
|
224
307
|
}) }, key);
|
|
225
308
|
}
|
|
226
309
|
if (type === NodeType3.CODE_BLOCK) {
|
|
227
|
-
const
|
|
310
|
+
const rawCode = children?.filter(isTextNode2).join("") ?? "";
|
|
311
|
+
const code = decodeHtmlEntities(rawCode);
|
|
228
312
|
return /* @__PURE__ */ jsx3(Fragment3, { children: await renderHighlightedCode(code, props?.lang) }, key);
|
|
229
313
|
}
|
|
230
314
|
const renderedChildren = children ? await Promise.all(
|
|
231
|
-
children.map(
|
|
315
|
+
children.map(
|
|
316
|
+
(child, index) => renderNode(child, components, renderImage, imageIndexRef, index)
|
|
317
|
+
)
|
|
232
318
|
) : void 0;
|
|
233
319
|
const Component = components[type];
|
|
234
320
|
if (Component) {
|
|
@@ -244,8 +330,11 @@ async function DocsMarkdown({
|
|
|
244
330
|
}) {
|
|
245
331
|
await initMarkdown2();
|
|
246
332
|
const ast = mdToJSON2(content);
|
|
333
|
+
const imageIndexRef = { current: 0 };
|
|
247
334
|
const rendered = await Promise.all(
|
|
248
|
-
ast.children.map(
|
|
335
|
+
ast.children.map(
|
|
336
|
+
(node, index) => renderNode(node, defaultComponents, renderImage, imageIndexRef, index)
|
|
337
|
+
)
|
|
249
338
|
);
|
|
250
339
|
const resolvedClassName = className === defaultClassName ? defaultClassName : `${defaultClassName} ${className}`.trim();
|
|
251
340
|
return /* @__PURE__ */ jsx3("div", { className: resolvedClassName, children: rendered });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../packages/markdown-wasm/src/index.ts","../../../../packages/markdown-wasm/src/components.tsx","../../../../packages/markdown-wasm/src/renderer.tsx","../../../../packages/markdown-wasm/src/types.ts","../../lib/docs-markdown.tsx"],"sourcesContent":["/**\n * @repo/markdown-wasm\n *\n * High-performance markdown rendering using md4w WASM engine\n * with React component mapping support.\n *\n * @example\n * ```tsx\n * import { MarkdownRenderer, createMarkdownRenderer, NodeType } from \"@repo/markdown-wasm\";\n *\n * // Basic usage\n * <MarkdownRenderer content=\"# Hello **world**\" />\n *\n * // With custom components\n * <MarkdownRenderer\n * content={markdown}\n * components={{\n * [NodeType.H1]: ({ children }) => <MyHeading>{children}</MyHeading>,\n * }}\n * />\n *\n * // Factory pattern for reusable renderer\n * const CustomRenderer = createMarkdownRenderer({\n * components: { ... },\n * className: \"prose\",\n * });\n * <CustomRenderer content={markdown} />\n * ```\n */\n\n// Re-export md4w utilities for advanced usage\nexport { init, mdToHtml, mdToJSON, mdToReadableHtml, ParseFlags as Md4wParseFlags } from 'md4w';\n\n// Component exports\nexport { defaultComponents, minimalComponents } from './components';\n// Main renderer exports\nexport {\n createMarkdownRenderer,\n initMarkdown,\n MarkdownRenderer,\n NodeType,\n renderMarkdown,\n} from './renderer';\n// Type exports\nexport type {\n ComponentMap,\n CreateRendererOptions,\n GenericNodeComponent,\n HeadingLevel,\n MarkdownRendererProps,\n MDNode,\n MDTree,\n NodeComponent,\n NodePropsFor,\n NodeRenderProps,\n Options,\n ParseFlags,\n} from './types';\n// Utility exports\nexport { getHeadingLevel, isElementNode, isTextNode } from './types';\n","/**\n * @repo/markdown-wasm - Default Component Mappings\n *\n * Provides semantic HTML components for all md4w node types.\n * Override any of these by passing custom components to MarkdownRenderer.\n */\n\nimport { NodeType } from 'md4w';\nimport type { ReactNode } from 'react';\n\nimport type { ComponentMap, HeadingLevel } from './types';\n\n/**\n * Default heading component.\n * Renders H1-H6 based on level prop.\n */\nfunction Heading({ level, children }: { level: HeadingLevel; children: ReactNode }) {\n const Tag = `h${level}` as const;\n return <Tag>{children}</Tag>;\n}\n\n/**\n * Default components for all md4w node types.\n * These render semantic HTML elements that can be styled with CSS.\n *\n * Props are accessed from a generic props object to satisfy GenericNodeComponent type.\n * Runtime guarantees from md4w ensure the props exist for each node type.\n */\nexport const defaultComponents: ComponentMap = {\n // Block elements\n [NodeType.QUOTE]: (props) => <blockquote>{props.children}</blockquote>,\n [NodeType.UL]: (props) => <ul>{props.children}</ul>,\n [NodeType.OL]: (props) => <ol start={props.start as number | undefined}>{props.children}</ol>,\n [NodeType.LI]: (props) => {\n const isTask = props.isTask as boolean | undefined;\n const done = props.done as boolean | undefined;\n if (isTask) {\n return (\n <li>\n <input type=\"checkbox\" checked={done} disabled readOnly />\n {props.children}\n </li>\n );\n }\n return <li>{props.children}</li>;\n },\n [NodeType.HR]: () => <hr />,\n [NodeType.CODE_BLOCK]: (props: { lang?: string; children: React.ReactNode }) => {\n const language = props.lang?.toLowerCase() || 'plaintext';\n const languageClass = language ? `language-${language}` : undefined;\n return (\n <pre className={languageClass}>\n <code className={languageClass} data-language={language}>\n {props.children}\n </code>\n </pre>\n );\n },\n [NodeType.HTML]: (props) => {\n const html = getHtmlString(props.children);\n if (html && isLineBreakHtml(html)) {\n return <br />;\n }\n // HTML blocks are rendered as-is inside a div\n // Note: This is raw HTML from markdown, use dangerouslySetInnerHTML if needed\n return <div data-markdown-html>{props.children}</div>;\n },\n [NodeType.P]: (props) => <p>{props.children}</p>,\n\n // Table elements\n [NodeType.TABLE]: (props) => <table>{props.children}</table>,\n [NodeType.THEAD]: (props) => <thead>{props.children}</thead>,\n [NodeType.TBODY]: (props) => <tbody>{props.children}</tbody>,\n [NodeType.TR]: (props) => <tr>{props.children}</tr>,\n [NodeType.TH]: (props) => {\n const align = props.align as 'left' | 'center' | 'right' | '' | undefined;\n return <th style={align ? { textAlign: align } : undefined}>{props.children}</th>;\n },\n [NodeType.TD]: (props) => {\n const align = props.align as 'left' | 'center' | 'right' | '' | undefined;\n return <td style={align ? { textAlign: align } : undefined}>{props.children}</td>;\n },\n\n // Headings (H1-H6 share the same component with level prop injected by renderer)\n [NodeType.H1]: (props) => (\n <Heading level={(props.level as HeadingLevel) ?? 1}>{props.children}</Heading>\n ),\n [NodeType.H2]: (props) => (\n <Heading level={(props.level as HeadingLevel) ?? 2}>{props.children}</Heading>\n ),\n [NodeType.H3]: (props) => (\n <Heading level={(props.level as HeadingLevel) ?? 3}>{props.children}</Heading>\n ),\n [NodeType.H4]: (props) => (\n <Heading level={(props.level as HeadingLevel) ?? 4}>{props.children}</Heading>\n ),\n [NodeType.H5]: (props) => (\n <Heading level={(props.level as HeadingLevel) ?? 5}>{props.children}</Heading>\n ),\n [NodeType.H6]: (props) => (\n <Heading level={(props.level as HeadingLevel) ?? 6}>{props.children}</Heading>\n ),\n\n // Inline elements\n [NodeType.EM]: (props) => <em>{props.children}</em>,\n [NodeType.STRONG]: (props) => <strong>{props.children}</strong>,\n [NodeType.A]: (props) => (\n <a href={props.href as string} title={props.title as string | undefined}>\n {props.children}\n </a>\n ),\n [NodeType.IMG]: (props) => (\n // biome-ignore lint/performance/noImgElement: Generic markdown package, not Next.js specific. Users can override with next/image.\n <img\n src={props.src as string}\n alt={props.alt as string}\n title={props.title as string | undefined}\n />\n ),\n [NodeType.CODE_SPAN]: (props) => <code>{props.children}</code>,\n [NodeType.DEL]: (props) => <del>{props.children}</del>,\n\n // Math (LaTeX)\n [NodeType.LATEXMATH]: (props) => <span data-math=\"inline\">{props.children}</span>,\n [NodeType.LATEXMATH_DISPLAY]: (props) => <div data-math=\"display\">{props.children}</div>,\n\n // Wiki links\n [NodeType.WIKILINK]: (props) => {\n const target = props.target as string;\n return (\n <a href={`/wiki/${encodeURIComponent(target)}`} data-wikilink={target}>\n {props.children}\n </a>\n );\n },\n\n // Underline (when UNDERLINE parse flag is enabled)\n [NodeType.U]: (props) => <u>{props.children}</u>,\n};\n\nfunction getHtmlString(children: ReactNode): string | null {\n if (typeof children === 'string') {\n return children;\n }\n if (Array.isArray(children) && children.length === 1 && typeof children[0] === 'string') {\n return children[0];\n }\n return null;\n}\n\nfunction isLineBreakHtml(html: string): boolean {\n const trimmed = html.trim().toLowerCase();\n return trimmed === '<br>' || trimmed === '<br/>' || trimmed === '<br />';\n}\n\n/**\n * Minimal component set - only essential elements.\n * Use this when you want to style everything yourself.\n */\nexport const minimalComponents: ComponentMap = {\n [NodeType.P]: (props) => <p>{props.children}</p>,\n [NodeType.H1]: (props) => (\n <Heading level={(props.level as HeadingLevel) ?? 1}>{props.children}</Heading>\n ),\n [NodeType.H2]: (props) => (\n <Heading level={(props.level as HeadingLevel) ?? 2}>{props.children}</Heading>\n ),\n [NodeType.H3]: (props) => (\n <Heading level={(props.level as HeadingLevel) ?? 3}>{props.children}</Heading>\n ),\n [NodeType.H4]: (props) => (\n <Heading level={(props.level as HeadingLevel) ?? 4}>{props.children}</Heading>\n ),\n [NodeType.H5]: (props) => (\n <Heading level={(props.level as HeadingLevel) ?? 5}>{props.children}</Heading>\n ),\n [NodeType.H6]: (props) => (\n <Heading level={(props.level as HeadingLevel) ?? 6}>{props.children}</Heading>\n ),\n [NodeType.STRONG]: (props) => <strong>{props.children}</strong>,\n [NodeType.EM]: (props) => <em>{props.children}</em>,\n [NodeType.A]: (props) => <a href={props.href as string}>{props.children}</a>,\n [NodeType.CODE_SPAN]: (props) => <code>{props.children}</code>,\n};\n","/**\n * @repo/markdown-wasm - AST to React Renderer\n *\n * Converts md4w JSON AST to React components.\n * Pattern B from research: Direct AST-to-React mapping for maximum performance.\n *\n * IMPORTANT: md4w is a WASM module that requires async initialization.\n * This module uses a singleton pattern with cached promise to ensure\n * init() is called exactly once before any parsing.\n *\n * NOTE: For Vercel/Next.js deployment, ensure `serverExternalPackages: ['md4w']`\n * is set in next.config.ts so md4w can properly resolve its WASM files.\n */\n\nimport { init, mdToJSON, NodeType } from 'md4w';\nimport { Fragment, type ReactNode } from 'react';\n\nimport { defaultComponents } from './components';\nimport type { ComponentMap, CreateRendererOptions, MarkdownRendererProps, MDNode } from './types';\nimport { getHeadingLevel, isTextNode } from './types';\n\n// -----------------------------------------------------------------------------\n// WASM Initialization (Singleton Pattern)\n// -----------------------------------------------------------------------------\n\n/**\n * Cached initialization promise.\n * Ensures init() is called exactly once, even with concurrent calls.\n */\nlet initPromise: Promise<void> | null = null;\n\n/**\n * Ensures md4w WASM is initialized before use.\n * Uses singleton pattern - multiple calls return the same promise.\n *\n * When md4w is listed in `serverExternalPackages`, it will be kept as an\n * external package and can properly resolve its WASM file using import.meta.url.\n *\n * @returns Promise that resolves when WASM is ready\n */\nasync function ensureInitialized(): Promise<void> {\n if (!initPromise) {\n // Use \"small\" variant (28KB gzipped) for faster loading\n initPromise = init('small');\n }\n return initPromise;\n}\n\n// -----------------------------------------------------------------------------\n// Internal Helpers\n// -----------------------------------------------------------------------------\n\n/**\n * Recursively renders an AST node to React elements.\n *\n * @param node - The AST node (MDNode or string)\n * @param components - Component map for rendering\n * @param key - React key for list rendering\n * @returns React element or text\n */\nfunction renderNode(\n node: string | MDNode,\n components: ComponentMap,\n key?: string | number\n): ReactNode {\n // Text nodes render as-is\n if (isTextNode(node)) {\n return node;\n }\n\n const { type, props, children } = node;\n\n // Recursively render children first\n const renderedChildren = children?.map((child, index) => renderNode(child, components, index));\n\n // Get component for this node type\n const Component = components[type as NodeType];\n\n if (Component) {\n // Build props based on node type\n const componentProps = buildComponentProps(type, props);\n\n return (\n <Fragment key={key}>{Component({ ...componentProps, children: renderedChildren })}</Fragment>\n );\n }\n\n // Unmapped node types: warn in development and render children only\n if (process.env.NODE_ENV === 'development') {\n console.warn(\n `[@repo/markdown-wasm] Unmapped node type: ${type} (${NodeType[type] ?? 'unknown'})`\n );\n }\n\n return <Fragment key={key}>{renderedChildren}</Fragment>;\n}\n\n/**\n * Builds component props from AST node props.\n * Handles special cases like heading levels.\n */\nfunction buildComponentProps(\n type: number,\n props?: Record<string, unknown>\n): Record<string, unknown> {\n const result = { ...props };\n\n // Add heading level for H1-H6 nodes\n const headingLevel = getHeadingLevel(type as NodeType);\n if (headingLevel !== undefined) {\n result.level = headingLevel;\n }\n\n return result;\n}\n\n// -----------------------------------------------------------------------------\n// Public API\n// -----------------------------------------------------------------------------\n\n/**\n * Renders markdown content to React elements.\n *\n * This is an async Server Component that initializes the WASM module\n * on first use, then parses and renders markdown content.\n *\n * @example\n * ```tsx\n * import { MarkdownRenderer } from \"@repo/markdown-wasm\";\n *\n * // In a Server Component (async)\n * async function MyComponent() {\n * return <MarkdownRenderer content=\"# Hello **world**\" />;\n * }\n *\n * // Or with await\n * export default async function Page() {\n * return (\n * <article>\n * {await MarkdownRenderer({ content: markdown })}\n * </article>\n * );\n * }\n * ```\n */\nexport async function MarkdownRenderer({\n content,\n components: componentOverrides,\n parseFlags,\n className,\n}: MarkdownRendererProps): Promise<ReactNode> {\n // Ensure WASM is initialized before parsing\n await ensureInitialized();\n\n // Parse markdown to AST\n const ast = mdToJSON(content, { parseFlags });\n\n // Merge default components with overrides\n const components: ComponentMap = {\n ...defaultComponents,\n ...componentOverrides,\n };\n\n // Render AST children\n const rendered = ast.children.map((node, index) => renderNode(node, components, index));\n\n // Wrap in container if className provided, otherwise return fragment\n if (className) {\n return <div className={className}>{rendered}</div>;\n }\n\n return <>{rendered}</>;\n}\n\n/**\n * Creates a pre-configured markdown renderer with default settings.\n *\n * Returns an async function suitable for Server Components.\n *\n * @example\n * ```tsx\n * import { createMarkdownRenderer } from \"@repo/markdown-wasm\";\n * import { MyHeading, MyText, MyLink } from \"./components\";\n *\n * const CustomRenderer = createMarkdownRenderer({\n * components: {\n * [NodeType.H1]: ({ level, children }) => <MyHeading level={level}>{children}</MyHeading>,\n * [NodeType.P]: ({ children }) => <MyText>{children}</MyText>,\n * [NodeType.A]: ({ href, children }) => <MyLink href={href}>{children}</MyLink>,\n * },\n * className: \"prose prose-lg\",\n * });\n *\n * async function Article({ markdown }: { markdown: string }) {\n * return <CustomRenderer content={markdown} />;\n * }\n * ```\n */\nexport function createMarkdownRenderer(options: CreateRendererOptions) {\n const {\n components: defaultOverrides,\n parseFlags: defaultParseFlags,\n className: defaultClassName,\n } = options;\n\n return async function ConfiguredMarkdownRenderer({\n content,\n components: instanceOverrides,\n parseFlags: instanceParseFlags,\n className: instanceClassName,\n }: MarkdownRendererProps): Promise<ReactNode> {\n return MarkdownRenderer({\n content,\n components: { ...defaultOverrides, ...instanceOverrides },\n parseFlags: instanceParseFlags ?? defaultParseFlags,\n className: instanceClassName ?? defaultClassName,\n });\n };\n}\n\n/**\n * Renders markdown to React elements without a wrapper component.\n * Useful for embedding markdown content inline.\n *\n * @example\n * ```tsx\n * import { renderMarkdown } from \"@repo/markdown-wasm\";\n *\n * // In an async Server Component\n * const elements = await renderMarkdown(\"**bold** and *italic*\");\n * ```\n */\nexport async function renderMarkdown(\n content: string,\n options?: Omit<MarkdownRendererProps, 'content'>\n): Promise<ReactNode> {\n return MarkdownRenderer({ content, ...options });\n}\n\n/**\n * Explicitly initialize the md4w WASM module.\n * Useful for pre-warming in middleware or layout components.\n *\n * @example\n * ```tsx\n * // In layout.tsx\n * import { initMarkdown } from \"@repo/markdown-wasm\";\n *\n * export default async function RootLayout({ children }) {\n * // Pre-warm WASM for faster first render\n * await initMarkdown();\n * return <html>{children}</html>;\n * }\n * ```\n */\nexport async function initMarkdown(): Promise<void> {\n await ensureInitialized();\n}\n\n// Re-export for convenience\nexport { NodeType } from 'md4w';\n","/**\n * @repo/markdown-wasm - Type definitions\n *\n * Re-exports md4w types with additional utility types for React rendering.\n */\n\nimport type { MDNode, MDTree, NodeType, Options, ParseFlags } from 'md4w';\nimport type { ReactNode } from 'react';\n\n// Re-export md4w types\nexport type { MDNode, MDTree, NodeType, Options, ParseFlags };\n\n/**\n * Props passed to a custom component for an AST node.\n * Each node type has different props available.\n */\nexport interface NodeRenderProps {\n /** The original AST node */\n node: MDNode;\n /** Rendered children (already converted to React elements) */\n children: ReactNode;\n}\n\n/**\n * A component that renders a specific node type.\n * Receives the node props and pre-rendered children.\n */\nexport type NodeComponent<TProps = Record<string, unknown>> = (\n props: TProps & { children: ReactNode }\n) => ReactNode;\n\n/**\n * Generic component function used internally.\n * Accepts any props and children.\n */\nexport type GenericNodeComponent = (\n props: Record<string, unknown> & { children: ReactNode }\n) => ReactNode;\n\n/**\n * Component overrides map keyed by NodeType.\n * Each entry maps a node type number to a component function.\n * Uses GenericNodeComponent internally for flexibility.\n */\nexport type ComponentMap = Partial<Record<NodeType, GenericNodeComponent>>;\n\n/**\n * Utility type to extract props for a specific node type.\n * This provides type-safe access to node-specific properties.\n */\nexport type NodePropsFor<T extends NodeType> = T extends NodeType.CODE_BLOCK\n ? { lang?: string }\n : T extends NodeType.OL\n ? { start?: number }\n : T extends NodeType.LI\n ? { isTask?: boolean; done?: boolean }\n : T extends NodeType.TH | NodeType.TD\n ? { align?: 'left' | 'center' | 'right' | '' }\n : T extends NodeType.A\n ? { href: string; title?: string }\n : T extends NodeType.IMG\n ? { src: string; alt: string; title?: string }\n : T extends NodeType.WIKILINK\n ? { target: string }\n : T extends\n | NodeType.H1\n | NodeType.H2\n | NodeType.H3\n | NodeType.H4\n | NodeType.H5\n | NodeType.H6\n ? { level: 1 | 2 | 3 | 4 | 5 | 6 }\n : Record<string, unknown>;\n\n/**\n * Props for the MarkdownRenderer component.\n */\nexport interface MarkdownRendererProps {\n /** Markdown content to render */\n content: string;\n /** Optional component overrides */\n components?: ComponentMap;\n /** Optional parse flags for md4w */\n parseFlags?: Options['parseFlags'];\n /** Optional className for the wrapper element */\n className?: string;\n}\n\n/**\n * Factory function options for creating a custom renderer.\n */\nexport interface CreateRendererOptions {\n /** Component overrides */\n components?: ComponentMap;\n /** Default parse flags */\n parseFlags?: Options['parseFlags'];\n /** Default wrapper className */\n className?: string;\n}\n\n/**\n * Heading level type (1-6).\n */\nexport type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;\n\n/**\n * Maps NodeType.H1-H6 to numeric heading level.\n */\nexport function getHeadingLevel(type: NodeType): HeadingLevel | undefined {\n const levelMap: Record<number, HeadingLevel> = {\n 21: 1,\n 22: 2,\n 23: 3,\n 24: 4,\n 25: 5,\n 26: 6,\n };\n return levelMap[type];\n}\n\n/**\n * Type guard to check if a node is a text node (string).\n */\nexport function isTextNode(node: string | MDNode): node is string {\n return typeof node === 'string';\n}\n\n/**\n * Type guard to check if a node is an element node (MDNode).\n */\nexport function isElementNode(node: string | MDNode): node is MDNode {\n return typeof node !== 'string' && typeof node === 'object' && 'type' in node;\n}\n","import {\n type ComponentMap,\n defaultComponents,\n getHeadingLevel,\n initMarkdown as initMarkdownWasm,\n type MDNode,\n mdToJSON,\n NodeType,\n} from '@repo/markdown-wasm';\nimport { Fragment, type ReactNode } from 'react';\nimport { type BuiltinLanguage, codeToTokens } from 'shiki';\n\nexport interface DocsMarkdownProps {\n content: string;\n className?: string;\n renderImage?: (props: { src: string; alt: string; title?: string }) => ReactNode;\n}\n\nconst defaultClassName = 'cms-docs-markdown';\nlet markdownInitPromise: Promise<void> | undefined;\n\nexport function markdownStartsWithHeading(markdown: string): boolean {\n return /^\\s*#\\s+/.test(markdown);\n}\n\nexport async function initMarkdown(): Promise<void> {\n markdownInitPromise ??= initMarkdownWasm();\n await markdownInitPromise;\n}\n\nfunction isTextNode(node: string | MDNode): node is string {\n return typeof node === 'string';\n}\n\nfunction buildComponentProps(\n type: number,\n props?: Record<string, unknown>\n): Record<string, unknown> {\n const result = { ...props };\n const headingLevel = getHeadingLevel(type as NodeType);\n\n if (headingLevel !== undefined) {\n result.level = headingLevel;\n }\n\n return result;\n}\n\nfunction normalizeLanguage(lang: unknown): string {\n if (typeof lang !== 'string') {\n return 'text';\n }\n\n const normalized = lang.trim().toLowerCase();\n return normalized || 'text';\n}\n\nasync function renderHighlightedCode(code: string, lang: unknown): Promise<ReactNode> {\n const language = normalizeLanguage(lang);\n\n try {\n const result = await codeToTokens(code, {\n lang: language as BuiltinLanguage,\n theme: 'github-dark',\n });\n\n return (\n <pre\n className={`shiki language-${language}`}\n style={{ backgroundColor: result.bg, color: result.fg }}\n >\n <code className={`shiki_code language-${language}`} data-language={language}>\n {(() => {\n const lineOccurrences = new Map<string, number>();\n\n return result.tokens.map((line, lineIndex) => {\n const isLastLine = lineIndex === result.tokens.length - 1;\n const lineSignature = line\n .map((token) => `${token.offset}:${token.color ?? ''}:${token.content}`)\n .join('|');\n const lineOccurrence = lineOccurrences.get(lineSignature) ?? 0;\n\n lineOccurrences.set(lineSignature, lineOccurrence + 1);\n\n let tokenCursor = 0;\n\n return (\n <Fragment key={`${lineSignature}#${lineOccurrence}`}>\n {line.map((token) => {\n const tokenKey = `${token.offset}:${token.color ?? ''}:${tokenCursor}:${token.content}`;\n tokenCursor += token.content.length;\n\n return (\n <span key={tokenKey} style={{ color: token.color }}>\n {token.content}\n </span>\n );\n })}\n {isLastLine ? null : '\\n'}\n </Fragment>\n );\n });\n })()}\n </code>\n </pre>\n );\n } catch {\n return (\n <pre className={`language-${language}`}>\n <code className={`language-${language}`}>{code}</code>\n </pre>\n );\n }\n}\n\nasync function renderNode(\n node: string | MDNode,\n components: ComponentMap,\n renderImage: DocsMarkdownProps['renderImage'],\n key?: string | number\n): Promise<ReactNode> {\n if (isTextNode(node)) {\n return node;\n }\n\n const { type, props, children } = node;\n\n if (type === NodeType.IMG && renderImage) {\n return (\n <Fragment key={key}>\n {renderImage({\n src: typeof props?.src === 'string' ? props.src : '',\n alt: typeof props?.alt === 'string' ? props.alt : '',\n title: typeof props?.title === 'string' ? props.title : undefined,\n })}\n </Fragment>\n );\n }\n\n if (type === NodeType.CODE_BLOCK) {\n const code = children?.filter(isTextNode).join('') ?? '';\n return <Fragment key={key}>{await renderHighlightedCode(code, props?.lang)}</Fragment>;\n }\n\n const renderedChildren = children\n ? await Promise.all(\n children.map((child, index) => renderNode(child, components, renderImage, index))\n )\n : undefined;\n\n const Component = components[type as NodeType];\n\n if (Component) {\n const componentProps = buildComponentProps(type, props);\n return (\n <Fragment key={key}>{Component({ ...componentProps, children: renderedChildren })}</Fragment>\n );\n }\n\n return <Fragment key={key}>{renderedChildren}</Fragment>;\n}\n\nexport async function DocsMarkdown({\n content,\n className = defaultClassName,\n renderImage,\n}: DocsMarkdownProps) {\n await initMarkdown();\n\n const ast = mdToJSON(content);\n const rendered = await Promise.all(\n ast.children.map((node, index) => renderNode(node, defaultComponents, renderImage, index))\n );\n\n const resolvedClassName =\n className === defaultClassName ? defaultClassName : `${defaultClassName} ${className}`.trim();\n\n return <div className={resolvedClassName}>{rendered}</div>;\n}\n"],"mappings":";AA+BA,SAAS,QAAAA,OAAM,UAAU,YAAAC,WAAU,kBAAgC,kBAAsB;;;ACxBzF,SAAS,gBAAgB;AAWhB,cAoBD,YApBC;AAFT,SAAS,QAAQ,EAAE,OAAO,SAAS,GAAiD;AAClF,QAAM,MAAM,IAAI,KAAK;AACrB,SAA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BACJ,cAAc,mBAAmB,mBAAmB,GAAG,gBAAgB,IAAI,SAAS,GAAG,KAAK;AAE9F,SAAO,gBAAAL,KAAC,SAAI,WAAW,mBAAoB,oBAAS;AACtD;","names":["init","mdToJSON","NodeType","NodeType","Fragment","jsx","Fragment","jsx","jsxs","initMarkdown","isTextNode","NodeType","mdToJSON"]}
|
|
1
|
+
{"version":3,"sources":["../../../../packages/markdown-wasm/src/index.ts","../../../../packages/markdown-wasm/src/components.tsx","../../../../packages/markdown-wasm/src/renderer.tsx","../../../../packages/markdown-wasm/src/types.ts","../../lib/docs-markdown.tsx"],"sourcesContent":["/**\n * @repo/markdown-wasm\n *\n * High-performance markdown rendering using md4w WASM engine\n * with React component mapping support.\n *\n * @example\n * ```tsx\n * import { MarkdownRenderer, createMarkdownRenderer, NodeType } from \"@repo/markdown-wasm\";\n *\n * // Basic usage\n * <MarkdownRenderer content=\"# Hello **world**\" />\n *\n * // With custom components\n * <MarkdownRenderer\n * content={markdown}\n * components={{\n * [NodeType.H1]: ({ children }) => <MyHeading>{children}</MyHeading>,\n * }}\n * />\n *\n * // Factory pattern for reusable renderer\n * const CustomRenderer = createMarkdownRenderer({\n * components: { ... },\n * className: \"prose\",\n * });\n * <CustomRenderer content={markdown} />\n * ```\n */\n\n// Re-export md4w utilities for advanced usage\nexport { init, mdToHtml, mdToJSON, mdToReadableHtml, ParseFlags as Md4wParseFlags } from 'md4w';\n\n// Component exports\nexport { defaultComponents, minimalComponents } from './components';\n// Main renderer exports\nexport {\n createMarkdownRenderer,\n initMarkdown,\n MarkdownRenderer,\n NodeType,\n renderMarkdown,\n} from './renderer';\n// Type exports\nexport type {\n ComponentMap,\n CreateRendererOptions,\n GenericNodeComponent,\n HeadingLevel,\n MarkdownRendererProps,\n MDNode,\n MDTree,\n NodeComponent,\n NodePropsFor,\n NodeRenderProps,\n Options,\n ParseFlags,\n} from './types';\n// Utility exports\nexport { getHeadingLevel, isElementNode, isTextNode } from './types';\n","/**\n * @repo/markdown-wasm - Default Component Mappings\n *\n * Provides semantic HTML components for all md4w node types.\n * Override any of these by passing custom components to MarkdownRenderer.\n */\n\nimport { NodeType } from 'md4w';\nimport type { ReactNode } from 'react';\n\nimport type { ComponentMap, HeadingLevel } from './types';\n\n/**\n * Default heading component.\n * Renders H1-H6 based on level prop.\n */\nfunction Heading({ level, children }: { level: HeadingLevel; children: ReactNode }) {\n const Tag = `h${level}` as const;\n return <Tag>{children}</Tag>;\n}\n\n/**\n * Default components for all md4w node types.\n * These render semantic HTML elements that can be styled with CSS.\n *\n * Props are accessed from a generic props object to satisfy GenericNodeComponent type.\n * Runtime guarantees from md4w ensure the props exist for each node type.\n */\nexport const defaultComponents: ComponentMap = {\n // Block elements\n [NodeType.QUOTE]: (props) => <blockquote>{props.children}</blockquote>,\n [NodeType.UL]: (props) => <ul>{props.children}</ul>,\n [NodeType.OL]: (props) => <ol start={props.start as number | undefined}>{props.children}</ol>,\n [NodeType.LI]: (props) => {\n const isTask = props.isTask as boolean | undefined;\n const done = props.done as boolean | undefined;\n if (isTask) {\n return (\n <li>\n <input type=\"checkbox\" checked={done} disabled readOnly />\n {props.children}\n </li>\n );\n }\n return <li>{props.children}</li>;\n },\n [NodeType.HR]: () => <hr />,\n [NodeType.CODE_BLOCK]: (props: { lang?: string; children: React.ReactNode }) => {\n const language = props.lang?.toLowerCase() || 'plaintext';\n const languageClass = language ? `language-${language}` : undefined;\n return (\n <pre className={languageClass}>\n <code className={languageClass} data-language={language}>\n {props.children}\n </code>\n </pre>\n );\n },\n [NodeType.HTML]: (props) => {\n const html = getHtmlString(props.children);\n if (html && isLineBreakHtml(html)) {\n return <br />;\n }\n // HTML blocks are rendered as-is inside a div\n // Note: This is raw HTML from markdown, use dangerouslySetInnerHTML if needed\n return <div data-markdown-html>{props.children}</div>;\n },\n [NodeType.P]: (props) => <p>{props.children}</p>,\n\n // Table elements\n [NodeType.TABLE]: (props) => <table>{props.children}</table>,\n [NodeType.THEAD]: (props) => <thead>{props.children}</thead>,\n [NodeType.TBODY]: (props) => <tbody>{props.children}</tbody>,\n [NodeType.TR]: (props) => <tr>{props.children}</tr>,\n [NodeType.TH]: (props) => {\n const align = props.align as 'left' | 'center' | 'right' | '' | undefined;\n return <th style={align ? { textAlign: align } : undefined}>{props.children}</th>;\n },\n [NodeType.TD]: (props) => {\n const align = props.align as 'left' | 'center' | 'right' | '' | undefined;\n return <td style={align ? { textAlign: align } : undefined}>{props.children}</td>;\n },\n\n // Headings (H1-H6 share the same component with level prop injected by renderer)\n [NodeType.H1]: (props) => (\n <Heading level={(props.level as HeadingLevel) ?? 1}>{props.children}</Heading>\n ),\n [NodeType.H2]: (props) => (\n <Heading level={(props.level as HeadingLevel) ?? 2}>{props.children}</Heading>\n ),\n [NodeType.H3]: (props) => (\n <Heading level={(props.level as HeadingLevel) ?? 3}>{props.children}</Heading>\n ),\n [NodeType.H4]: (props) => (\n <Heading level={(props.level as HeadingLevel) ?? 4}>{props.children}</Heading>\n ),\n [NodeType.H5]: (props) => (\n <Heading level={(props.level as HeadingLevel) ?? 5}>{props.children}</Heading>\n ),\n [NodeType.H6]: (props) => (\n <Heading level={(props.level as HeadingLevel) ?? 6}>{props.children}</Heading>\n ),\n\n // Inline elements\n [NodeType.EM]: (props) => <em>{props.children}</em>,\n [NodeType.STRONG]: (props) => <strong>{props.children}</strong>,\n [NodeType.A]: (props) => (\n <a href={props.href as string} title={props.title as string | undefined}>\n {props.children}\n </a>\n ),\n [NodeType.IMG]: (props) => (\n // biome-ignore lint/performance/noImgElement: Generic markdown package, not Next.js specific. Users can override with next/image.\n <img\n src={props.src as string}\n alt={props.alt as string}\n title={props.title as string | undefined}\n />\n ),\n [NodeType.CODE_SPAN]: (props) => <code>{props.children}</code>,\n [NodeType.DEL]: (props) => <del>{props.children}</del>,\n\n // Math (LaTeX)\n [NodeType.LATEXMATH]: (props) => <span data-math=\"inline\">{props.children}</span>,\n [NodeType.LATEXMATH_DISPLAY]: (props) => <div data-math=\"display\">{props.children}</div>,\n\n // Wiki links\n [NodeType.WIKILINK]: (props) => {\n const target = props.target as string;\n return (\n <a href={`/wiki/${encodeURIComponent(target)}`} data-wikilink={target}>\n {props.children}\n </a>\n );\n },\n\n // Underline (when UNDERLINE parse flag is enabled)\n [NodeType.U]: (props) => <u>{props.children}</u>,\n};\n\nfunction getHtmlString(children: ReactNode): string | null {\n if (typeof children === 'string') {\n return children;\n }\n if (Array.isArray(children) && children.length === 1 && typeof children[0] === 'string') {\n return children[0];\n }\n return null;\n}\n\nfunction isLineBreakHtml(html: string): boolean {\n const trimmed = html.trim().toLowerCase();\n return trimmed === '<br>' || trimmed === '<br/>' || trimmed === '<br />';\n}\n\n/**\n * Minimal component set - only essential elements.\n * Use this when you want to style everything yourself.\n */\nexport const minimalComponents: ComponentMap = {\n [NodeType.P]: (props) => <p>{props.children}</p>,\n [NodeType.H1]: (props) => (\n <Heading level={(props.level as HeadingLevel) ?? 1}>{props.children}</Heading>\n ),\n [NodeType.H2]: (props) => (\n <Heading level={(props.level as HeadingLevel) ?? 2}>{props.children}</Heading>\n ),\n [NodeType.H3]: (props) => (\n <Heading level={(props.level as HeadingLevel) ?? 3}>{props.children}</Heading>\n ),\n [NodeType.H4]: (props) => (\n <Heading level={(props.level as HeadingLevel) ?? 4}>{props.children}</Heading>\n ),\n [NodeType.H5]: (props) => (\n <Heading level={(props.level as HeadingLevel) ?? 5}>{props.children}</Heading>\n ),\n [NodeType.H6]: (props) => (\n <Heading level={(props.level as HeadingLevel) ?? 6}>{props.children}</Heading>\n ),\n [NodeType.STRONG]: (props) => <strong>{props.children}</strong>,\n [NodeType.EM]: (props) => <em>{props.children}</em>,\n [NodeType.A]: (props) => <a href={props.href as string}>{props.children}</a>,\n [NodeType.CODE_SPAN]: (props) => <code>{props.children}</code>,\n};\n","/**\n * @repo/markdown-wasm - AST to React Renderer\n *\n * Converts md4w JSON AST to React components.\n * Pattern B from research: Direct AST-to-React mapping for maximum performance.\n *\n * IMPORTANT: md4w is a WASM module that requires async initialization.\n * This module uses a singleton pattern with cached promise to ensure\n * init() is called exactly once before any parsing.\n *\n * NOTE: For Vercel/Next.js deployment, ensure `serverExternalPackages: ['md4w']`\n * is set in next.config.ts so md4w can properly resolve its WASM files.\n */\n\nimport { init, mdToJSON, NodeType } from 'md4w';\nimport { Fragment, type ReactNode } from 'react';\n\nimport { defaultComponents } from './components';\nimport type { ComponentMap, CreateRendererOptions, MarkdownRendererProps, MDNode } from './types';\nimport { getHeadingLevel, isTextNode } from './types';\n\n// -----------------------------------------------------------------------------\n// WASM Initialization (Singleton Pattern)\n// -----------------------------------------------------------------------------\n\n/**\n * Cached initialization promise.\n * Ensures init() is called exactly once, even with concurrent calls.\n */\nlet initPromise: Promise<void> | null = null;\n\n/**\n * Ensures md4w WASM is initialized before use.\n * Uses singleton pattern - multiple calls return the same promise.\n *\n * When md4w is listed in `serverExternalPackages`, it will be kept as an\n * external package and can properly resolve its WASM file using import.meta.url.\n *\n * @returns Promise that resolves when WASM is ready\n */\nasync function ensureInitialized(): Promise<void> {\n if (!initPromise) {\n // Use \"small\" variant (28KB gzipped) for faster loading\n initPromise = init('small');\n }\n return initPromise;\n}\n\n// -----------------------------------------------------------------------------\n// Internal Helpers\n// -----------------------------------------------------------------------------\n\n/**\n * Recursively renders an AST node to React elements.\n *\n * @param node - The AST node (MDNode or string)\n * @param components - Component map for rendering\n * @param key - React key for list rendering\n * @returns React element or text\n */\nfunction renderNode(\n node: string | MDNode,\n components: ComponentMap,\n key?: string | number\n): ReactNode {\n // Text nodes render as-is\n if (isTextNode(node)) {\n return node;\n }\n\n const { type, props, children } = node;\n\n // Recursively render children first\n const renderedChildren = children?.map((child, index) => renderNode(child, components, index));\n\n // Get component for this node type\n const Component = components[type as NodeType];\n\n if (Component) {\n // Build props based on node type\n const componentProps = buildComponentProps(type, props);\n\n return (\n <Fragment key={key}>{Component({ ...componentProps, children: renderedChildren })}</Fragment>\n );\n }\n\n // Unmapped node types: warn in development and render children only\n if (process.env.NODE_ENV === 'development') {\n console.warn(\n `[@repo/markdown-wasm] Unmapped node type: ${type} (${NodeType[type] ?? 'unknown'})`\n );\n }\n\n return <Fragment key={key}>{renderedChildren}</Fragment>;\n}\n\n/**\n * Builds component props from AST node props.\n * Handles special cases like heading levels.\n */\nfunction buildComponentProps(\n type: number,\n props?: Record<string, unknown>\n): Record<string, unknown> {\n const result = { ...props };\n\n // Add heading level for H1-H6 nodes\n const headingLevel = getHeadingLevel(type as NodeType);\n if (headingLevel !== undefined) {\n result.level = headingLevel;\n }\n\n return result;\n}\n\n// -----------------------------------------------------------------------------\n// Public API\n// -----------------------------------------------------------------------------\n\n/**\n * Renders markdown content to React elements.\n *\n * This is an async Server Component that initializes the WASM module\n * on first use, then parses and renders markdown content.\n *\n * @example\n * ```tsx\n * import { MarkdownRenderer } from \"@repo/markdown-wasm\";\n *\n * // In a Server Component (async)\n * async function MyComponent() {\n * return <MarkdownRenderer content=\"# Hello **world**\" />;\n * }\n *\n * // Or with await\n * export default async function Page() {\n * return (\n * <article>\n * {await MarkdownRenderer({ content: markdown })}\n * </article>\n * );\n * }\n * ```\n */\nexport async function MarkdownRenderer({\n content,\n components: componentOverrides,\n parseFlags,\n className,\n}: MarkdownRendererProps): Promise<ReactNode> {\n // Ensure WASM is initialized before parsing\n await ensureInitialized();\n\n // Parse markdown to AST\n const ast = mdToJSON(content, { parseFlags });\n\n // Merge default components with overrides\n const components: ComponentMap = {\n ...defaultComponents,\n ...componentOverrides,\n };\n\n // Render AST children\n const rendered = ast.children.map((node, index) => renderNode(node, components, index));\n\n // Wrap in container if className provided, otherwise return fragment\n if (className) {\n return <div className={className}>{rendered}</div>;\n }\n\n return <>{rendered}</>;\n}\n\n/**\n * Creates a pre-configured markdown renderer with default settings.\n *\n * Returns an async function suitable for Server Components.\n *\n * @example\n * ```tsx\n * import { createMarkdownRenderer } from \"@repo/markdown-wasm\";\n * import { MyHeading, MyText, MyLink } from \"./components\";\n *\n * const CustomRenderer = createMarkdownRenderer({\n * components: {\n * [NodeType.H1]: ({ level, children }) => <MyHeading level={level}>{children}</MyHeading>,\n * [NodeType.P]: ({ children }) => <MyText>{children}</MyText>,\n * [NodeType.A]: ({ href, children }) => <MyLink href={href}>{children}</MyLink>,\n * },\n * className: \"prose prose-lg\",\n * });\n *\n * async function Article({ markdown }: { markdown: string }) {\n * return <CustomRenderer content={markdown} />;\n * }\n * ```\n */\nexport function createMarkdownRenderer(options: CreateRendererOptions) {\n const {\n components: defaultOverrides,\n parseFlags: defaultParseFlags,\n className: defaultClassName,\n } = options;\n\n return async function ConfiguredMarkdownRenderer({\n content,\n components: instanceOverrides,\n parseFlags: instanceParseFlags,\n className: instanceClassName,\n }: MarkdownRendererProps): Promise<ReactNode> {\n return MarkdownRenderer({\n content,\n components: { ...defaultOverrides, ...instanceOverrides },\n parseFlags: instanceParseFlags ?? defaultParseFlags,\n className: instanceClassName ?? defaultClassName,\n });\n };\n}\n\n/**\n * Renders markdown to React elements without a wrapper component.\n * Useful for embedding markdown content inline.\n *\n * @example\n * ```tsx\n * import { renderMarkdown } from \"@repo/markdown-wasm\";\n *\n * // In an async Server Component\n * const elements = await renderMarkdown(\"**bold** and *italic*\");\n * ```\n */\nexport async function renderMarkdown(\n content: string,\n options?: Omit<MarkdownRendererProps, 'content'>\n): Promise<ReactNode> {\n return MarkdownRenderer({ content, ...options });\n}\n\n/**\n * Explicitly initialize the md4w WASM module.\n * Useful for pre-warming in middleware or layout components.\n *\n * @example\n * ```tsx\n * // In layout.tsx\n * import { initMarkdown } from \"@repo/markdown-wasm\";\n *\n * export default async function RootLayout({ children }) {\n * // Pre-warm WASM for faster first render\n * await initMarkdown();\n * return <html>{children}</html>;\n * }\n * ```\n */\nexport async function initMarkdown(): Promise<void> {\n await ensureInitialized();\n}\n\n// Re-export for convenience\nexport { NodeType } from 'md4w';\n","/**\n * @repo/markdown-wasm - Type definitions\n *\n * Re-exports md4w types with additional utility types for React rendering.\n */\n\nimport type { MDNode, MDTree, NodeType, Options, ParseFlags } from 'md4w';\nimport type { ReactNode } from 'react';\n\n// Re-export md4w types\nexport type { MDNode, MDTree, NodeType, Options, ParseFlags };\n\n/**\n * Props passed to a custom component for an AST node.\n * Each node type has different props available.\n */\nexport interface NodeRenderProps {\n /** The original AST node */\n node: MDNode;\n /** Rendered children (already converted to React elements) */\n children: ReactNode;\n}\n\n/**\n * A component that renders a specific node type.\n * Receives the node props and pre-rendered children.\n */\nexport type NodeComponent<TProps = Record<string, unknown>> = (\n props: TProps & { children: ReactNode }\n) => ReactNode;\n\n/**\n * Generic component function used internally.\n * Accepts any props and children.\n */\nexport type GenericNodeComponent = (\n props: Record<string, unknown> & { children: ReactNode }\n) => ReactNode;\n\n/**\n * Component overrides map keyed by NodeType.\n * Each entry maps a node type number to a component function.\n * Uses GenericNodeComponent internally for flexibility.\n */\nexport type ComponentMap = Partial<Record<NodeType, GenericNodeComponent>>;\n\n/**\n * Utility type to extract props for a specific node type.\n * This provides type-safe access to node-specific properties.\n */\nexport type NodePropsFor<T extends NodeType> = T extends NodeType.CODE_BLOCK\n ? { lang?: string }\n : T extends NodeType.OL\n ? { start?: number }\n : T extends NodeType.LI\n ? { isTask?: boolean; done?: boolean }\n : T extends NodeType.TH | NodeType.TD\n ? { align?: 'left' | 'center' | 'right' | '' }\n : T extends NodeType.A\n ? { href: string; title?: string }\n : T extends NodeType.IMG\n ? { src: string; alt: string; title?: string }\n : T extends NodeType.WIKILINK\n ? { target: string }\n : T extends\n | NodeType.H1\n | NodeType.H2\n | NodeType.H3\n | NodeType.H4\n | NodeType.H5\n | NodeType.H6\n ? { level: 1 | 2 | 3 | 4 | 5 | 6 }\n : Record<string, unknown>;\n\n/**\n * Props for the MarkdownRenderer component.\n */\nexport interface MarkdownRendererProps {\n /** Markdown content to render */\n content: string;\n /** Optional component overrides */\n components?: ComponentMap;\n /** Optional parse flags for md4w */\n parseFlags?: Options['parseFlags'];\n /** Optional className for the wrapper element */\n className?: string;\n}\n\n/**\n * Factory function options for creating a custom renderer.\n */\nexport interface CreateRendererOptions {\n /** Component overrides */\n components?: ComponentMap;\n /** Default parse flags */\n parseFlags?: Options['parseFlags'];\n /** Default wrapper className */\n className?: string;\n}\n\n/**\n * Heading level type (1-6).\n */\nexport type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;\n\n/**\n * Maps NodeType.H1-H6 to numeric heading level.\n */\nexport function getHeadingLevel(type: NodeType): HeadingLevel | undefined {\n const levelMap: Record<number, HeadingLevel> = {\n 21: 1,\n 22: 2,\n 23: 3,\n 24: 4,\n 25: 5,\n 26: 6,\n };\n return levelMap[type];\n}\n\n/**\n * Type guard to check if a node is a text node (string).\n */\nexport function isTextNode(node: string | MDNode): node is string {\n return typeof node === 'string';\n}\n\n/**\n * Type guard to check if a node is an element node (MDNode).\n */\nexport function isElementNode(node: string | MDNode): node is MDNode {\n return typeof node !== 'string' && typeof node === 'object' && 'type' in node;\n}\n","import {\n type ComponentMap,\n defaultComponents,\n getHeadingLevel,\n initMarkdown as initMarkdownWasm,\n type MDNode,\n mdToJSON,\n NodeType,\n} from '@repo/markdown-wasm';\nimport { Fragment, type ReactNode } from 'react';\nimport { type BundledLanguage, bundledLanguages, createHighlighter, type Highlighter } from 'shiki';\n\nexport interface DocsMarkdownProps {\n content: string;\n className?: string;\n renderImage?: (props: {\n src: string;\n alt: string;\n title?: string;\n loading?: 'eager' | 'lazy';\n }) => ReactNode;\n}\n\nconst defaultClassName = 'cms-docs-markdown';\nlet markdownInitPromise: Promise<void> | undefined;\n\n// Pre-load common languages for fast cold-start\n// Less common languages are lazy-loaded on demand\nconst PRELOADED_LANGS: BundledLanguage[] = [\n // Web\n 'typescript',\n 'javascript',\n 'tsx',\n 'jsx',\n 'html',\n 'css',\n 'scss',\n // Systems\n 'c',\n 'cpp',\n 'rust',\n 'go',\n // Enterprise\n 'java',\n 'csharp',\n 'kotlin',\n 'swift',\n // Scripting\n 'python',\n 'ruby',\n 'php',\n 'bash',\n 'shellscript',\n 'powershell',\n // Data\n 'json',\n 'yaml',\n 'toml',\n 'xml',\n 'sql',\n 'graphql',\n // Other\n 'markdown',\n 'dockerfile',\n];\n\n// Cache the highlighter instance to avoid re-loading languages/themes\nlet highlighterPromise: Promise<Highlighter> | undefined;\n\n// Track which languages have been loaded\nconst loadedLanguages = new Set<string>(PRELOADED_LANGS);\n\nasync function getHighlighter(): Promise<Highlighter> {\n highlighterPromise ??= createHighlighter({\n themes: ['github-dark'],\n langs: PRELOADED_LANGS,\n });\n return highlighterPromise;\n}\n\n/**\n * Ensures a language is loaded, lazy-loading if needed.\n * Returns the resolved language name, or null if not a valid language.\n */\nasync function ensureLanguageLoaded(\n highlighter: Highlighter,\n lang: string\n): Promise<BundledLanguage | null> {\n // Already loaded\n if (loadedLanguages.has(lang)) {\n return lang as BundledLanguage;\n }\n\n // Check if it's a valid bundled language\n if (lang in bundledLanguages) {\n try {\n await highlighter.loadLanguage(lang as BundledLanguage);\n loadedLanguages.add(lang);\n return lang as BundledLanguage;\n } catch {\n // Loading failed, will render as plain code\n return null;\n }\n }\n\n // Unknown language, will render as plain code\n return null;\n}\n\n// Pre-warm WASM and Shiki at module load to avoid cold start penalty\n// This runs once when the module is first imported (server startup)\nif (typeof window === 'undefined') {\n // Server-side only: trigger initialization immediately\n markdownInitPromise = initMarkdownWasm();\n highlighterPromise = createHighlighter({\n themes: ['github-dark'],\n langs: PRELOADED_LANGS,\n });\n // Log pre-warming for debugging\n Promise.all([markdownInitPromise, highlighterPromise])\n .then(() =>\n console.log(`[docs-markdown] WASM and Shiki pre-warmed (${PRELOADED_LANGS.length} languages)`)\n )\n .catch((err) => console.error('[docs-markdown] Pre-warm failed:', err));\n}\n\nexport function markdownStartsWithHeading(markdown: string): boolean {\n return /^\\s*#\\s+/.test(markdown);\n}\n\nexport async function initMarkdown(): Promise<void> {\n markdownInitPromise ??= initMarkdownWasm();\n await markdownInitPromise;\n}\n\nfunction isTextNode(node: string | MDNode): node is string {\n return typeof node === 'string';\n}\n\nfunction buildComponentProps(\n type: number,\n props?: Record<string, unknown>\n): Record<string, unknown> {\n const result = { ...props };\n const headingLevel = getHeadingLevel(type as NodeType);\n\n if (headingLevel !== undefined) {\n result.level = headingLevel;\n }\n\n return result;\n}\n\nfunction normalizeLanguage(lang: unknown): string {\n if (typeof lang !== 'string') {\n return '';\n }\n\n const normalized = lang.trim().toLowerCase();\n return normalized;\n}\n\nfunction decodeHtmlEntities(value: string): string {\n return value\n .replaceAll('<', '<')\n .replaceAll('>', '>')\n .replaceAll('"', '\"')\n .replaceAll(''', \"'\")\n .replaceAll('&', '&');\n}\n\nasync function renderHighlightedCode(code: string, lang: unknown): Promise<ReactNode> {\n const language = normalizeLanguage(lang);\n const displayLanguage = language || 'text';\n\n try {\n const highlighter = await getHighlighter();\n // Ensure language is loaded (lazy-load if needed)\n const resolvedLang = await ensureLanguageLoaded(highlighter, language);\n\n // If language not supported, render plain code\n if (!resolvedLang) {\n return (\n <pre className={`language-${displayLanguage}`}>\n <code className={`language-${displayLanguage}`}>{code}</code>\n </pre>\n );\n }\n\n const result = highlighter.codeToTokens(code, {\n lang: resolvedLang,\n theme: 'github-dark',\n });\n\n return (\n <pre\n className={`shiki language-${displayLanguage}`}\n style={{ backgroundColor: result.bg, color: result.fg }}\n >\n <code className={`shiki_code language-${displayLanguage}`} data-language={displayLanguage}>\n {(() => {\n const lineOccurrences = new Map<string, number>();\n\n return result.tokens.map((line, lineIndex) => {\n const isLastLine = lineIndex === result.tokens.length - 1;\n const lineSignature = line\n .map((token) => `${token.offset}:${token.color ?? ''}:${token.content}`)\n .join('|');\n const lineOccurrence = lineOccurrences.get(lineSignature) ?? 0;\n\n lineOccurrences.set(lineSignature, lineOccurrence + 1);\n\n let tokenCursor = 0;\n\n return (\n <Fragment key={`${lineSignature}#${lineOccurrence}`}>\n {line.map((token) => {\n const tokenKey = `${token.offset}:${token.color ?? ''}:${tokenCursor}:${token.content}`;\n tokenCursor += token.content.length;\n\n return (\n <span key={tokenKey} style={{ color: token.color }}>\n {token.content}\n </span>\n );\n })}\n {isLastLine ? null : '\\n'}\n </Fragment>\n );\n });\n })()}\n </code>\n </pre>\n );\n } catch {\n return (\n <pre className={`language-${displayLanguage}`}>\n <code className={`language-${displayLanguage}`}>{code}</code>\n </pre>\n );\n }\n}\n\nasync function renderNode(\n node: string | MDNode,\n components: ComponentMap,\n renderImage: DocsMarkdownProps['renderImage'],\n imageIndexRef: { current: number },\n key?: string | number\n): Promise<ReactNode> {\n if (isTextNode(node)) {\n return decodeHtmlEntities(node);\n }\n\n const { type, props, children } = node;\n\n if (type === NodeType.IMG && renderImage) {\n const imageIndex = imageIndexRef.current;\n imageIndexRef.current += 1;\n\n return (\n <Fragment key={key}>\n {renderImage({\n src: typeof props?.src === 'string' ? props.src : '',\n alt: typeof props?.alt === 'string' ? props.alt : '',\n title: typeof props?.title === 'string' ? props.title : undefined,\n loading: imageIndex === 0 ? 'eager' : 'lazy',\n })}\n </Fragment>\n );\n }\n\n if (type === NodeType.CODE_BLOCK) {\n const rawCode = children?.filter(isTextNode).join('') ?? '';\n const code = decodeHtmlEntities(rawCode);\n return <Fragment key={key}>{await renderHighlightedCode(code, props?.lang)}</Fragment>;\n }\n\n const renderedChildren = children\n ? await Promise.all(\n children.map((child, index) =>\n renderNode(child, components, renderImage, imageIndexRef, index)\n )\n )\n : undefined;\n\n const Component = components[type as NodeType];\n\n if (Component) {\n const componentProps = buildComponentProps(type, props);\n return (\n <Fragment key={key}>{Component({ ...componentProps, children: renderedChildren })}</Fragment>\n );\n }\n\n return <Fragment key={key}>{renderedChildren}</Fragment>;\n}\n\nexport async function DocsMarkdown({\n content,\n className = defaultClassName,\n renderImage,\n}: DocsMarkdownProps) {\n await initMarkdown();\n\n const ast = mdToJSON(content);\n const imageIndexRef = { current: 0 };\n const rendered = await Promise.all(\n ast.children.map((node, index) =>\n renderNode(node, defaultComponents, renderImage, imageIndexRef, index)\n )\n );\n\n const resolvedClassName =\n className === defaultClassName ? defaultClassName : `${defaultClassName} ${className}`.trim();\n\n return <div className={res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MAAM,OAAO,IAAI,KAAnD,GAAqD;AAAA,EAC7E;AAEA,QAAM,mBAAmB,WACrB,MAAM,QAAQ;AAAA,IACZ,SAAS;AAAA,MAAI,CAAC,OAAO,UACnB,WAAW,OAAO,YAAY,aAAa,eAAe,KAAK;AAAA,IACjE;AAAA,EACF,IACA;AAEJ,QAAM,YAAY,WAAW,IAAgB;AAE7C,MAAI,WAAW;AACb,UAAM,iBAAiB,oBAAoB,MAAM,KAAK;AACtD,WACE,gBAAAC,KAACD,WAAA,EAAoB,oBAAU,EAAE,GAAG,gBAAgB,UAAU,iBAAiB,CAAC,KAAjE,GAAmE;AAAA,EAEtF;AAEA,SAAO,gBAAAC,KAACD,WAAA,EAAoB,8BAAN,GAAuB;AAC/C;AAEA,eAAsB,aAAa;AAAA,EACjC;AAAA,EACA,YAAY;AAAA,EACZ;AACF,GAAsB;AACpB,QAAMG,cAAa;AAEnB,QAAM,MAAMG,UAAS,OAAO;AAC5B,QAAM,gBAAgB,EAAE,SAAS,EAAE;AACnC,QAAM,WAAW,MAAM,QAAQ;AAAA,IAC7B,IAAI,SAAS;AAAA,MAAI,CAAC,MAAM,UACtB,WAAW,MAAM,mBAAmB,aAAa,eAAe,KAAK;AAAA,IACvE;AAAA,EACF;AAEA,QAAM,oBACJ,cAAc,mBAAmB,mBAAmB,GAAG,gBAAgB,IAAI,SAAS,GAAG,KAAK;AAE9F,SAAO,gBAAAL,KAAC,SAAI,WAAW,mBAAoB,oBAAS;AACtD;","names":["init","mdToJSON","NodeType","NodeType","Fragment","jsx","Fragment","jsx","jsxs","initMarkdown","isTextNode","NodeType","mdToJSON"]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export { normalizePath } from '@repo/cms-schema/routing';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { CmsConfig } from './cms-api.js';
|
|
4
|
+
import { BlockComponentRegistry } from './types.js';
|
|
5
|
+
import '@repo/cms-schema/trpc';
|
|
6
|
+
import '@trpc/client';
|
|
7
|
+
import '@repo/cms-schema/blocks';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Framework-agnostic parametric route rendering for Profound CMS.
|
|
11
|
+
* Next.js and TanStack Start call `renderParametricRoute` and map `not_found`
|
|
12
|
+
* to their respective 404 mechanisms.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
type ParametricRouteProps = CmsConfig & {
|
|
16
|
+
params: Promise<{
|
|
17
|
+
slug: string[];
|
|
18
|
+
}>;
|
|
19
|
+
searchParams?: Promise<{
|
|
20
|
+
[key: string]: string | string[] | undefined;
|
|
21
|
+
}>;
|
|
22
|
+
registry?: Partial<BlockComponentRegistry>;
|
|
23
|
+
};
|
|
24
|
+
type ParametricRouteResult = {
|
|
25
|
+
status: 'ok';
|
|
26
|
+
node: ReactNode;
|
|
27
|
+
} | {
|
|
28
|
+
status: 'not_found';
|
|
29
|
+
} | {
|
|
30
|
+
status: 'error';
|
|
31
|
+
error: unknown;
|
|
32
|
+
};
|
|
33
|
+
/** @internal Exported for generateMetadata in renderer.tsx */
|
|
34
|
+
declare function getWebsiteId(providedWebsiteId?: string): string;
|
|
35
|
+
/**
|
|
36
|
+
* Renders CMS-backed blocks for a multi-segment path. Maps NOT_FOUND-style API
|
|
37
|
+
* outcomes to `{ status: 'not_found' }` instead of throwing.
|
|
38
|
+
*/
|
|
39
|
+
declare function renderParametricRoute({ params, searchParams, registry, apiKey, cmsUrl, websiteId: providedWebsiteId, }: ParametricRouteProps): Promise<ParametricRouteResult>;
|
|
40
|
+
|
|
41
|
+
export { type ParametricRouteProps, type ParametricRouteResult, getWebsiteId, renderParametricRoute };
|