@docfuse/markdown 0.1.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.
Files changed (121) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +50 -0
  3. package/README.zh-CN.md +50 -0
  4. package/dist/Markdown-D33gcJbF.js +2116 -0
  5. package/dist/base.css +2 -0
  6. package/dist/client/chunks/client-DIoaSmq2.js +334 -0
  7. package/dist/client/chunks/gallery-BPqV7HsS.js +40 -0
  8. package/dist/client/chunks/image-BGExZy1g.js +36 -0
  9. package/dist/client/chunks/provider-DL6V8F7z.js +841 -0
  10. package/dist/client/chunks/react-runtime-ByABE9MG.js +10571 -0
  11. package/dist/client/chunks/serialized-BvfsNeRQ.js +3464 -0
  12. package/dist/client/chunks/table-DBiKAEbC.js +30 -0
  13. package/dist/client/index.js +4 -0
  14. package/dist/client/nativeBehaviors.d.ts +4 -0
  15. package/dist/client.d.ts +15 -0
  16. package/dist/compiler/analyze.d.ts +27 -0
  17. package/dist/compiler/assets.d.ts +29 -0
  18. package/dist/compiler/ast.d.ts +68 -0
  19. package/dist/compiler/createPipeline.d.ts +18 -0
  20. package/dist/compiler/defaultLabels.d.ts +28 -0
  21. package/dist/compiler/directiveValidation.d.ts +17 -0
  22. package/dist/compiler/highlighter.d.ts +3 -0
  23. package/dist/compiler/mdxModules.d.ts +19 -0
  24. package/dist/compiler/mdxPlugins.d.ts +16 -0
  25. package/dist/compiler/normalizeOptions.d.ts +16 -0
  26. package/dist/compiler/pluginPlan.d.ts +18 -0
  27. package/dist/compiler/plugins/code.d.ts +16 -0
  28. package/dist/compiler/plugins/directives.d.ts +24 -0
  29. package/dist/compiler/plugins/documentBlocks.d.ts +5 -0
  30. package/dist/compiler/plugins/tables.d.ts +5 -0
  31. package/dist/compiler/plugins.d.ts +24 -0
  32. package/dist/compiler/prepareMarkdown.d.ts +11 -0
  33. package/dist/compiler/sanitizeBoundary.d.ts +18 -0
  34. package/dist/compiler/stableJson.d.ts +2 -0
  35. package/dist/compiler/syntaxFeatures.d.ts +10 -0
  36. package/dist/compiler/types.d.ts +177 -0
  37. package/dist/components/blocks/MarkdownCodeBlock.d.ts +10 -0
  38. package/dist/components/blocks/MarkdownCopySnippet.d.ts +10 -0
  39. package/dist/components/blocks/MarkdownHeading.d.ts +13 -0
  40. package/dist/components/blocks/MarkdownImage.d.ts +16 -0
  41. package/dist/components/blocks/MarkdownTable.d.ts +12 -0
  42. package/dist/components/blocks/MarkdownTerminal.d.ts +9 -0
  43. package/dist/components/composite/MarkdownComposite.d.ts +37 -0
  44. package/dist/components/composite/MarkdownFileTree.d.ts +5 -0
  45. package/dist/components/composite/MarkdownTabs.d.ts +6 -0
  46. package/dist/components/gallery/ImageGallery.d.ts +25 -0
  47. package/dist/components/shared/MarkdownActions.d.ts +18 -0
  48. package/dist/components/shared/MarkdownDialog.d.ts +11 -0
  49. package/dist/components/shared/MarkdownFileIcon.d.ts +4 -0
  50. package/dist/components/shared/MarkdownIcon.d.ts +8 -0
  51. package/dist/components/shared/interactionConstants.d.ts +1 -0
  52. package/dist/components/shared/reactText.d.ts +14 -0
  53. package/dist/directiveValidation-BdIao7Yn.js +741 -0
  54. package/dist/file-icons/LICENSE +21 -0
  55. package/dist/file-icons/astro.svg +1 -0
  56. package/dist/file-icons/bun.svg +1 -0
  57. package/dist/file-icons/bun_light.svg +1 -0
  58. package/dist/file-icons/config.svg +1 -0
  59. package/dist/file-icons/console.svg +1 -0
  60. package/dist/file-icons/css.svg +1 -0
  61. package/dist/file-icons/database.svg +1 -0
  62. package/dist/file-icons/deno.svg +1 -0
  63. package/dist/file-icons/deno_light.svg +1 -0
  64. package/dist/file-icons/diff.svg +1 -0
  65. package/dist/file-icons/docker.svg +1 -0
  66. package/dist/file-icons/document.svg +1 -0
  67. package/dist/file-icons/download.svg +1 -0
  68. package/dist/file-icons/environment.svg +1 -0
  69. package/dist/file-icons/excel.svg +1 -0
  70. package/dist/file-icons/git.svg +1 -0
  71. package/dist/file-icons/github-actions.svg +1 -0
  72. package/dist/file-icons/go.svg +1 -0
  73. package/dist/file-icons/javascript.svg +1 -0
  74. package/dist/file-icons/json.svg +1 -0
  75. package/dist/file-icons/markdown.svg +1 -0
  76. package/dist/file-icons/nodejs.svg +1 -0
  77. package/dist/file-icons/npm.svg +1 -0
  78. package/dist/file-icons/pdf.svg +1 -0
  79. package/dist/file-icons/pnpm.svg +1 -0
  80. package/dist/file-icons/pnpm_light.svg +1 -0
  81. package/dist/file-icons/powerpoint.svg +1 -0
  82. package/dist/file-icons/python.svg +1 -0
  83. package/dist/file-icons/react.svg +1 -0
  84. package/dist/file-icons/rust.svg +1 -0
  85. package/dist/file-icons/sass.svg +1 -0
  86. package/dist/file-icons/settings.svg +1 -0
  87. package/dist/file-icons/svelte.svg +1 -0
  88. package/dist/file-icons/typescript.svg +1 -0
  89. package/dist/file-icons/vue.svg +1 -0
  90. package/dist/file-icons/word.svg +1 -0
  91. package/dist/file-icons/yaml.svg +1 -0
  92. package/dist/file-icons/yarn.svg +1 -0
  93. package/dist/index.d.ts +7 -0
  94. package/dist/index.js +6 -0
  95. package/dist/islands/gallery.d.ts +2 -0
  96. package/dist/islands/image.d.ts +2 -0
  97. package/dist/islands/options.d.ts +8 -0
  98. package/dist/islands/provider.d.ts +4 -0
  99. package/dist/islands/serialized.d.ts +4 -0
  100. package/dist/islands/table.d.ts +2 -0
  101. package/dist/islands.d.ts +13 -0
  102. package/dist/plugins-DQ-VUuCT.js +288 -0
  103. package/dist/prepareMarkdown-CHqN2JF5.js +852 -0
  104. package/dist/protocol/serializedNode.d.ts +3 -0
  105. package/dist/react/Markdown.d.ts +54 -0
  106. package/dist/react/componentMap.d.ts +172 -0
  107. package/dist/react/semanticOverrideProps.d.ts +4 -0
  108. package/dist/react/slots.d.ts +39 -0
  109. package/dist/react/urlTransform.d.ts +12 -0
  110. package/dist/server/analyze.d.ts +6 -0
  111. package/dist/server/analyze.js +132 -0
  112. package/dist/server/cache.d.ts +16 -0
  113. package/dist/server/createMarkdownRenderer.d.ts +39 -0
  114. package/dist/server.d.ts +5 -0
  115. package/dist/server.js +137 -0
  116. package/dist/shared/copyText.d.ts +2 -0
  117. package/dist/shared/fileKinds.d.ts +6 -0
  118. package/dist/theme.css +183 -0
  119. package/dist/theme.d.ts +167 -0
  120. package/dist/theme.js +228 -0
  121. package/package.json +110 -0
@@ -0,0 +1,3 @@
1
+ import type { Nodes } from 'hast';
2
+ export declare function serializeMarkdownNode(node: unknown): string | undefined;
3
+ export declare function deserializeMarkdownNode(value?: string): Nodes | undefined;
@@ -0,0 +1,54 @@
1
+ import { type ElementType, type HTMLAttributes, type ReactNode } from 'react';
2
+ import { type MarkdownClassNames, type MarkdownComponents } from './componentMap';
3
+ import type { PreparedMarkdown, RenderMarkdownOptions } from '../compiler/types';
4
+ import { type MarkdownSlots } from './slots';
5
+ import { type MarkdownUrlTransform } from './urlTransform';
6
+ export interface MarkdownRootProps extends Omit<HTMLAttributes<HTMLElement>, 'children' | 'dangerouslySetInnerHTML'> {
7
+ /** Render element. Defaults to `div`. */
8
+ as?: ElementType;
9
+ /** Stable root marker used by Docfuse Islands and host automation. */
10
+ 'data-df-root'?: string;
11
+ classNames?: MarkdownClassNames;
12
+ /** Local visual slots used by the React component map. */
13
+ slots?: MarkdownSlots;
14
+ /** Transform authored URL properties without scanning rendered HTML. */
15
+ urlTransform?: MarkdownUrlTransform;
16
+ }
17
+ export interface MarkdownProps extends MarkdownRootProps {
18
+ /** Markdown source. The compiler is intentionally hidden from callers. */
19
+ source: string;
20
+ /** Compiler options; visual tokens and interaction labels remain configurable. */
21
+ options?: RenderMarkdownOptions;
22
+ /** Optional callback invoked when browser-side preparation fails. */
23
+ onError?: (error: unknown) => void;
24
+ /** Optional callback invoked after prepared output has committed to the DOM. */
25
+ onReady?: () => void;
26
+ /** Optional content shown while preparing or after preparation fails. */
27
+ fallback?: ReactNode;
28
+ /** Keep the last prepared document visible while a newer source is compiling. */
29
+ retainPrevious?: boolean;
30
+ /** Intrinsic element overrides for structured Markdown output. */
31
+ components?: MarkdownComponents;
32
+ }
33
+ interface MarkdownDocumentProps extends MarkdownRootProps {
34
+ /** Prepared HAST document produced by the package's internal compiler. */
35
+ document: PreparedMarkdown['document'];
36
+ /** Optional intrinsic tag replacements for host-level customization. */
37
+ components?: MarkdownComponents;
38
+ }
39
+ interface MarkdownRootContentProps extends MarkdownRootProps {
40
+ children: ReactNode;
41
+ }
42
+ /** Shared root contract for Markdown and MDX React output. */
43
+ export declare function MarkdownRoot({ as: Tag, className, classNames, slots, urlTransform, children, 'data-df-root': rootMarker, ...props }: MarkdownRootContentProps): import("react").FunctionComponentElement<{
44
+ transform?: MarkdownUrlTransform;
45
+ children: ReactNode;
46
+ }>;
47
+ /** Render a prepared HAST tree as React elements. */
48
+ export declare function MarkdownDocument({ document, classNames, components, slots, urlTransform, ...props }: MarkdownDocumentProps): import("react").JSX.Element;
49
+ /**
50
+ * Render Markdown directly from source. Preparation remains an internal
51
+ * implementation detail of the package's React entry point.
52
+ */
53
+ export declare function Markdown({ source, options, onError, onReady, fallback, retainPrevious, ...props }: MarkdownProps): string | number | bigint | boolean | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | import("react").JSX.Element | null;
54
+ export {};
@@ -0,0 +1,172 @@
1
+ import { type ComponentType, type ElementType, type JSX, type ReactNode } from 'react';
2
+ import type { MarkdownCodeBlockProps } from '../components/blocks/MarkdownCodeBlock';
3
+ import type { MarkdownCopySnippetProps } from '../components/blocks/MarkdownCopySnippet';
4
+ import type { MarkdownImageProps } from '../components/blocks/MarkdownImage';
5
+ import type { MarkdownTableProps } from '../components/blocks/MarkdownTable';
6
+ import type { MarkdownTerminalProps } from '../components/blocks/MarkdownTerminal';
7
+ import type { MarkdownCompositeProps, MarkdownDetailsProps } from '../components/composite/MarkdownComposite';
8
+ import type { MarkdownFileTreeProps } from '../components/composite/MarkdownFileTree';
9
+ import type { MarkdownTabsProps } from '../components/composite/MarkdownTabs';
10
+ import type { ImageGalleryProps } from '../components/gallery/ImageGallery';
11
+ import { type MarkdownSlots } from './slots';
12
+ import { type MarkdownUrlTransform } from './urlTransform';
13
+ export type MarkdownComponentMap = Record<string, ElementType>;
14
+ /**
15
+ * Host overrides for intrinsic tags and named Markdown composites.
16
+ * Composite names are semantic so callers do not depend on wrapper classes.
17
+ */
18
+ export interface MarkdownNamedComponentProps {
19
+ Callout: MarkdownCompositeProps;
20
+ Tabs: MarkdownTabsProps;
21
+ CodeGroup: MarkdownTabsProps;
22
+ Steps: MarkdownCompositeProps;
23
+ CodeBlock: MarkdownCodeBlockProps;
24
+ CopySnippet: MarkdownCopySnippetProps;
25
+ Table: MarkdownTableProps;
26
+ Image: MarkdownImageProps;
27
+ Terminal: MarkdownTerminalProps;
28
+ Details: MarkdownDetailsProps;
29
+ FileTree: MarkdownFileTreeProps;
30
+ Gallery: ImageGalleryProps;
31
+ CardGrid: MarkdownCompositeProps;
32
+ Api: MarkdownCompositeProps;
33
+ Aside: MarkdownCompositeProps;
34
+ Badge: MarkdownCompositeProps;
35
+ }
36
+ export type MarkdownIntrinsicComponents = {
37
+ [Tag in keyof JSX.IntrinsicElements]?: ComponentType<JSX.IntrinsicElements[Tag]>;
38
+ };
39
+ export type MarkdownComponents = MarkdownIntrinsicComponents & {
40
+ [Name in keyof MarkdownNamedComponentProps]?: ComponentType<MarkdownNamedComponentProps[Name]>;
41
+ };
42
+ /** Additional classes for stable Markdown element/component slots. */
43
+ export interface MarkdownClassNames {
44
+ root?: string;
45
+ heading?: string;
46
+ paragraph?: string;
47
+ link?: string;
48
+ list?: string;
49
+ listItem?: string;
50
+ blockquote?: string;
51
+ horizontalRule?: string;
52
+ strong?: string;
53
+ emphasis?: string;
54
+ strikethrough?: string;
55
+ highlight?: string;
56
+ keyboard?: string;
57
+ superscript?: string;
58
+ subscript?: string;
59
+ inlineCode?: string;
60
+ code?: string;
61
+ codeBlock?: string;
62
+ copySnippet?: string;
63
+ table?: string;
64
+ tableHead?: string;
65
+ tableBody?: string;
66
+ tableRow?: string;
67
+ tableHeader?: string;
68
+ tableCell?: string;
69
+ taskCheckbox?: string;
70
+ callout?: string;
71
+ tabs?: string;
72
+ steps?: string;
73
+ image?: string;
74
+ video?: string;
75
+ audio?: string;
76
+ embed?: string;
77
+ definitionList?: string;
78
+ definitionTerm?: string;
79
+ definitionDescription?: string;
80
+ summary?: string;
81
+ footnotes?: string;
82
+ terminal?: string;
83
+ details?: string;
84
+ fileTree?: string;
85
+ gallery?: string;
86
+ cardGrid?: string;
87
+ api?: string;
88
+ aside?: string;
89
+ badge?: string;
90
+ }
91
+ export interface MarkdownElementProps {
92
+ children?: ReactNode;
93
+ node?: unknown;
94
+ [key: string]: unknown;
95
+ }
96
+ declare const componentDescriptors: {
97
+ readonly callout: {
98
+ readonly className: "callout";
99
+ readonly override: "Callout";
100
+ };
101
+ readonly tabs: {
102
+ readonly className: "tabs";
103
+ readonly override: "Tabs";
104
+ };
105
+ readonly 'code-group': {
106
+ readonly className: "tabs";
107
+ readonly override: "CodeGroup";
108
+ };
109
+ readonly steps: {
110
+ readonly className: "steps";
111
+ readonly override: "Steps";
112
+ };
113
+ readonly 'code-block': {
114
+ readonly className: "codeBlock";
115
+ readonly override: "CodeBlock";
116
+ };
117
+ readonly 'copy-snippet': {
118
+ readonly className: "copySnippet";
119
+ readonly override: "CopySnippet";
120
+ };
121
+ readonly table: {
122
+ readonly className: "table";
123
+ readonly override: "Table";
124
+ };
125
+ readonly image: {
126
+ readonly className: "image";
127
+ readonly override: "Image";
128
+ };
129
+ readonly terminal: {
130
+ readonly className: "terminal";
131
+ readonly override: "Terminal";
132
+ };
133
+ readonly details: {
134
+ readonly className: "details";
135
+ readonly override: "Details";
136
+ };
137
+ readonly 'file-tree': {
138
+ readonly className: "fileTree";
139
+ readonly override: "FileTree";
140
+ };
141
+ readonly gallery: {
142
+ readonly className: "gallery";
143
+ readonly override: "Gallery";
144
+ };
145
+ readonly 'card-grid': {
146
+ readonly className: "cardGrid";
147
+ readonly override: "CardGrid";
148
+ };
149
+ readonly api: {
150
+ readonly className: "api";
151
+ readonly override: "Api";
152
+ };
153
+ readonly aside: {
154
+ readonly className: "aside";
155
+ readonly override: "Aside";
156
+ };
157
+ readonly badge: {
158
+ readonly className: "badge";
159
+ readonly override: "Badge";
160
+ };
161
+ };
162
+ export type MarkdownComponentName = keyof typeof componentDescriptors;
163
+ /**
164
+ * Shared structural map for Markdown HAST and MDX SSR.
165
+ *
166
+ * The map adds stable semantic hooks. Visual styling stays in tokens/CSS;
167
+ * interactive state lives in React components and static React Islands.
168
+ */
169
+ export declare function createMarkdownComponentMap(classNames?: MarkdownClassNames, slots?: MarkdownSlots, components?: MarkdownComponents, urlTransform?: MarkdownUrlTransform): MarkdownComponentMap;
170
+ /** Add trusted MDX component names without letting lowercase tags bypass Markdown semantics. */
171
+ export declare function createMarkdownMdxComponentMap(classNames?: MarkdownClassNames, slots?: MarkdownSlots, components?: MarkdownComponents & Record<string, ElementType>, urlTransform?: MarkdownUrlTransform): MarkdownComponentMap;
172
+ export {};
@@ -0,0 +1,4 @@
1
+ import { type ReactNode } from 'react';
2
+ import type { MarkdownComponentName, MarkdownElementProps } from './componentMap';
3
+ /** Normalize compiler data attributes into the public props promised to named replacements. */
4
+ export declare function semanticOverrideProps(component: MarkdownComponentName, props: MarkdownElementProps, children: ReactNode): MarkdownElementProps;
@@ -0,0 +1,39 @@
1
+ import { type ComponentType, type ReactNode } from 'react';
2
+ export type MarkdownIconName = 'copy' | 'download' | 'code' | 'maximize' | 'minus' | 'plus' | 'reset' | 'sort' | 'table' | 'folder' | 'file' | 'workflow' | 'link' | 'close' | 'previous' | 'next';
3
+ export interface MarkdownIconSlotProps {
4
+ name: MarkdownIconName;
5
+ size?: number;
6
+ className?: string;
7
+ 'aria-hidden'?: boolean | 'true' | 'false';
8
+ }
9
+ export interface MarkdownCaptionSlotProps {
10
+ children?: ReactNode;
11
+ className?: string;
12
+ 'data-df-slot'?: string;
13
+ }
14
+ export interface MarkdownSlots {
15
+ CopyIcon?: ComponentType<MarkdownIconSlotProps>;
16
+ DownloadIcon?: ComponentType<MarkdownIconSlotProps>;
17
+ MaximizeIcon?: ComponentType<MarkdownIconSlotProps>;
18
+ CodeIcon?: ComponentType<MarkdownIconSlotProps>;
19
+ MinusIcon?: ComponentType<MarkdownIconSlotProps>;
20
+ PlusIcon?: ComponentType<MarkdownIconSlotProps>;
21
+ ResetIcon?: ComponentType<MarkdownIconSlotProps>;
22
+ SortIcon?: ComponentType<MarkdownIconSlotProps>;
23
+ TableIcon?: ComponentType<MarkdownIconSlotProps>;
24
+ FolderIcon?: ComponentType<MarkdownIconSlotProps>;
25
+ FileIcon?: ComponentType<MarkdownIconSlotProps>;
26
+ WorkflowIcon?: ComponentType<MarkdownIconSlotProps>;
27
+ LinkIcon?: ComponentType<MarkdownIconSlotProps>;
28
+ CloseIcon?: ComponentType<MarkdownIconSlotProps>;
29
+ PreviousIcon?: ComponentType<MarkdownIconSlotProps>;
30
+ NextIcon?: ComponentType<MarkdownIconSlotProps>;
31
+ ImageCaption?: ComponentType<MarkdownCaptionSlotProps>;
32
+ }
33
+ export declare function MarkdownSlotsProvider({ slots, children }: {
34
+ slots?: MarkdownSlots;
35
+ children: ReactNode;
36
+ }): import("react").FunctionComponentElement<import("react").ProviderProps<MarkdownSlots>>;
37
+ export declare function useMarkdownSlots(): MarkdownSlots;
38
+ export declare function getMarkdownIconSlot(slots: MarkdownSlots | undefined, name: MarkdownIconName): ((props: Omit<MarkdownIconSlotProps, "name">) => import("react").ReactElement<MarkdownIconSlotProps, string | import("react").JSXElementConstructor<any>>) | undefined;
39
+ export declare function getMarkdownCaptionSlot(slots: MarkdownSlots | undefined): ComponentType<MarkdownCaptionSlotProps> | undefined;
@@ -0,0 +1,12 @@
1
+ import { type ReactNode } from 'react';
2
+ export type MarkdownUrlProperty = 'href' | 'src' | 'poster' | 'srcSet';
3
+ export type MarkdownUrlTransform = (value: string, property: MarkdownUrlProperty) => string;
4
+ /** Keep relative URLs and a small set of non-executable absolute protocols. */
5
+ export declare function sanitizeMarkdownUrl(value: string): string | undefined;
6
+ export declare function MarkdownUrlTransformProvider({ transform, children }: {
7
+ transform?: MarkdownUrlTransform;
8
+ children: ReactNode;
9
+ }): import("react").FunctionComponentElement<import("react").ProviderProps<MarkdownUrlTransform | undefined>>;
10
+ export declare function useMarkdownUrlTransform(): MarkdownUrlTransform | undefined;
11
+ export declare function transformMarkdownSrcSet(value: string, transform?: MarkdownUrlTransform): string;
12
+ export declare function transformMarkdownUrlProps(props: Record<string, unknown>, transform?: MarkdownUrlTransform): Record<string, unknown>;
@@ -0,0 +1,6 @@
1
+ /** Build-tool analysis entry point, isolated from the SSR renderer graph. */
2
+ export { detectMarkdownAssets } from '../compiler/assets';
3
+ export { analyzeMarkdown } from '../compiler/analyze';
4
+ export { analyzeMdxModuleBoundary } from '../compiler/mdxModules';
5
+ export type { AnalyzeMarkdownOptions, MarkdownAnalysis, MarkdownCodeExample, MarkdownHeading } from '../compiler/analyze';
6
+ export type { MdxImportBinding, MdxImportDeclaration, MdxModuleBoundary } from '../compiler/mdxModules';
@@ -0,0 +1,132 @@
1
+ import { n as k, c as w } from "../directiveValidation-BdIao7Yn.js";
2
+ import { d as K } from "../directiveValidation-BdIao7Yn.js";
3
+ import x from "github-slugger";
4
+ import { remarkDefinitionList as b } from "remark-definition-list";
5
+ import D from "remark-directive";
6
+ import M from "remark-gfm";
7
+ import S from "remark-parse";
8
+ import { unified as E } from "unified";
9
+ import { visit as y } from "unist-util-visit";
10
+ import { a as I, n as v, m as C } from "../plugins-DQ-VUuCT.js";
11
+ import { createProcessor as A } from "@mdx-js/mdx";
12
+ function L(t) {
13
+ return "children" in t && Array.isArray(t.children);
14
+ }
15
+ function f(t) {
16
+ return t.type === "text" || t.type === "inlineCode" ? String(t.value ?? "") : t.type === "image" ? String(t.alt ?? "") : t.type === "code" || t.type === "html" || t.type === "definition" ? "" : L(t) ? t.children.map(f).join(" ") : "";
17
+ }
18
+ function q(t, e = {}) {
19
+ const s = E().use(S).use(b).use(M).use(D).parse(k(t)), c = new x(), m = [], o = [], r = [], l = [];
20
+ let g = 0;
21
+ const u = /* @__PURE__ */ new Map();
22
+ y(s, "definition", (n) => {
23
+ n.url && u.set(n.identifier.toLowerCase(), n.url);
24
+ }), y(s, (n) => {
25
+ if (n.type === "heading") {
26
+ const i = n, a = f(i).replace(/\s+/g, " ").trim();
27
+ m.push({ level: i.depth, text: a, slug: c.slug(a) });
28
+ }
29
+ if (n.type === "code") {
30
+ const i = n;
31
+ i.lang || (g += 1), o.push({
32
+ language: i.lang || "text",
33
+ ...i.meta ? { meta: i.meta } : {},
34
+ code: i.value
35
+ });
36
+ }
37
+ if (n.type === "link") {
38
+ const i = n;
39
+ i.url && r.push(i.url);
40
+ }
41
+ if (n.type === "image") {
42
+ const i = n;
43
+ i.url && l.push(i.url);
44
+ }
45
+ if (n.type === "linkReference") {
46
+ const i = n, a = u.get(i.identifier.toLowerCase());
47
+ a && r.push(a);
48
+ }
49
+ if (n.type === "imageReference") {
50
+ const i = n, a = u.get(i.identifier.toLowerCase());
51
+ a && l.push(a);
52
+ }
53
+ });
54
+ const h = I(v(e.plugins), {
55
+ source: t,
56
+ mode: "markdown"
57
+ });
58
+ return {
59
+ text: f(s).replace(/\s+/g, " ").trim(),
60
+ headings: m,
61
+ codeExamples: o,
62
+ links: r,
63
+ images: l,
64
+ missingCodeBlockLanguages: g,
65
+ directiveIssues: w(s, C(h)).map(
66
+ ({ message: n, line: i, column: a }) => ({
67
+ message: n,
68
+ line: i,
69
+ column: a
70
+ })
71
+ )
72
+ };
73
+ }
74
+ function P(t) {
75
+ return t.specifiers.map((e) => e.type === "ImportDefaultSpecifier" ? { imported: "default", local: e.local.name } : e.type === "ImportNamespaceSpecifier" ? { imported: "*", local: e.local.name, namespace: !0 } : {
76
+ imported: e.type === "ImportSpecifier" ? "name" in e.imported ? e.imported.name : String(e.imported.value ?? "") : "",
77
+ local: e.local.name
78
+ });
79
+ }
80
+ function j(t) {
81
+ return !!(t && typeof t == "object" && typeof t.type == "string");
82
+ }
83
+ function R(t) {
84
+ const e = t;
85
+ return typeof e.start == "number" && typeof e.end == "number";
86
+ }
87
+ function d(t, e) {
88
+ if (!t || typeof t != "object") return;
89
+ if (Array.isArray(t)) {
90
+ for (const s of t) d(s, e);
91
+ return;
92
+ }
93
+ const p = t;
94
+ j(t) && e(t);
95
+ for (const [s, c] of Object.entries(p))
96
+ s === "loc" || s === "position" || d(c, e);
97
+ }
98
+ function F(t) {
99
+ const e = A().parse(t), p = [], s = [], c = [];
100
+ d(e, (o) => {
101
+ if (o.type === "ImportExpression") {
102
+ const r = o.source.type === "Literal" && typeof o.source.value == "string" ? o.source.value : void 0;
103
+ s.push({
104
+ kind: "dynamic-import",
105
+ specifier: r
106
+ });
107
+ }
108
+ });
109
+ for (const o of e.children ?? [])
110
+ if (o.type === "mdxjsEsm")
111
+ for (const r of o.data?.estree?.body ?? [])
112
+ if (r.type === "ImportDeclaration") {
113
+ if (p.push({
114
+ specifier: String(r.source.value),
115
+ bindings: P(r)
116
+ }), !R(r))
117
+ throw new Error("Unable to locate an MDX import declaration in the source document");
118
+ c.push({ start: r.start, end: r.end });
119
+ } else (r.type === "ExportNamedDeclaration" || r.type === "ExportAllDeclaration") && r.source && s.push({
120
+ kind: "export-from",
121
+ specifier: String(r.source.value)
122
+ });
123
+ const m = [
124
+ ...new Map(c.map((o) => [`${o.start}:${o.end}`, o])).values()
125
+ ].sort((o, r) => r.start - o.start).reduce((o, r) => `${o.slice(0, r.start)}${o.slice(r.end)}`, t).replace(/^\s*\n/, "");
126
+ return { imports: p, sourceWithoutImports: m, unsupportedReferences: s };
127
+ }
128
+ export {
129
+ q as analyzeMarkdown,
130
+ F as analyzeMdxModuleBoundary,
131
+ K as detectMarkdownAssets
132
+ };
@@ -0,0 +1,16 @@
1
+ import type { PreparedMarkdown, RenderMarkdownOptions } from '../compiler/types';
2
+ export interface MarkdownServerContextOptions {
3
+ /** Maximum number of prepared entries retained by this context. */
4
+ maxEntries?: number;
5
+ }
6
+ interface MarkdownServerContext {
7
+ prepare(source: string, options?: RenderMarkdownOptions): Promise<PreparedMarkdown>;
8
+ clear(): void;
9
+ }
10
+ /**
11
+ * Renderer-scoped Markdown cache. It deduplicates concurrent preparation and
12
+ * stays bounded; hosts clear it when a full build invalidates the content
13
+ * graph, while safe single-page dev rebuilds can retain hot entries.
14
+ */
15
+ export declare function createMarkdownServerContext({ maxEntries, warningState }?: MarkdownServerContextOptions): MarkdownServerContext;
16
+ export {};
@@ -0,0 +1,39 @@
1
+ import { type ElementType, type ReactNode } from 'react';
2
+ import { type MarkdownClassNames, type MarkdownComponents } from '../react/componentMap';
3
+ import type { MarkdownAssets } from '../compiler/assets';
4
+ import { type MarkdownServerContextOptions } from './cache';
5
+ import type { RenderMarkdownOptions } from '../compiler/types';
6
+ import { type MarkdownSlots } from '../react/slots';
7
+ import type { MarkdownUrlTransform } from '../react/urlTransform';
8
+ export interface MarkdownRenderOptions {
9
+ markdown?: RenderMarkdownOptions;
10
+ classNames?: MarkdownClassNames;
11
+ components?: MarkdownComponents;
12
+ slots?: MarkdownSlots;
13
+ className?: string;
14
+ as?: ElementType;
15
+ urlTransform?: MarkdownUrlTransform;
16
+ }
17
+ export interface MdxRenderOptions extends Omit<MarkdownRenderOptions, 'components'> {
18
+ /** Host and author components made available to trusted MDX. */
19
+ components?: MarkdownComponents & Record<string, ElementType>;
20
+ /** Base URL used by the MDX runtime for generated module metadata. */
21
+ baseUrl?: URL;
22
+ }
23
+ export interface RenderedMarkdown {
24
+ content: ReactNode;
25
+ assets: MarkdownAssets;
26
+ }
27
+ export interface MarkdownRenderer {
28
+ render(source: string, options?: MarkdownRenderOptions): Promise<RenderedMarkdown>;
29
+ renderMdx(source: string, options?: MdxRenderOptions): Promise<RenderedMarkdown>;
30
+ clear(): void;
31
+ }
32
+ /**
33
+ * Build/SSR renderer for Markdown and trusted MDX.
34
+ *
35
+ * The interface returns React content plus resource facts. HAST, Unified
36
+ * processors, plugin ordering and compiler caches remain private so hosts do
37
+ * not have to assemble the rendering pipeline themselves.
38
+ */
39
+ export declare function createMarkdownRenderer(contextOptions?: MarkdownServerContextOptions): MarkdownRenderer;
@@ -0,0 +1,5 @@
1
+ /** Build/SSR-only entry point with compiler details hidden behind renderers. */
2
+ export { createMarkdownRenderer } from './server/createMarkdownRenderer';
3
+ export { defineMarkdownPlugin } from './compiler/plugins';
4
+ export type { MarkdownAssets, MarkdownLabels, MarkdownPlugin, MarkdownPluginBrowserCompiler, MarkdownPluginCacheValue, MarkdownPluginClientAsset, MarkdownPluginClientResource, MarkdownPluginClientResourceDirectory, MarkdownPluginStyleAsset, MarkdownUnknownLanguagePolicy, RenderMarkdownOptions } from './compiler/prepareMarkdown';
5
+ export type { MarkdownRenderer, MarkdownRenderOptions, MdxRenderOptions, RenderedMarkdown } from './server/createMarkdownRenderer';
package/dist/server.js ADDED
@@ -0,0 +1,137 @@
1
+ import * as p from "react/jsx-runtime";
2
+ import { jsx as c } from "react/jsx-runtime";
3
+ import { evaluate as w } from "@mdx-js/mdx";
4
+ import { c as f, a as h, b as k } from "./Markdown-D33gcJbF.js";
5
+ import { a as M, n as P } from "./directiveValidation-BdIao7Yn.js";
6
+ import { n as x, d as v, c as y, a as N, p as L } from "./prepareMarkdown-CHqN2JF5.js";
7
+ import { a as b, b as S, s as C, c as T } from "./plugins-DQ-VUuCT.js";
8
+ import { d as G } from "./plugins-DQ-VUuCT.js";
9
+ import { createHash as z } from "node:crypto";
10
+ async function O(a = {}, r, t = { warnedLanguages: /* @__PURE__ */ new Set() }) {
11
+ const s = x(a), e = M(), n = r ?? "", o = b(s.plugins, { source: n, mode: "mdx" }), l = S(o), d = { ...s, plugins: o }, u = v(n, l);
12
+ o.forEach((g) => e.markPluginAssets(g));
13
+ const m = u.highlightedCode ? await y(
14
+ u.codeLanguages,
15
+ d,
16
+ t.warnedLanguages,
17
+ l
18
+ ) : void 0, i = N("mdx", e, d, u, m);
19
+ return {
20
+ remarkPlugins: i.remarkPlugins,
21
+ rehypePlugins: i.rehypePlugins,
22
+ remarkRehypeOptions: { handlers: i.handlers },
23
+ getAssets: () => e.snapshot()
24
+ };
25
+ }
26
+ function R(a, r) {
27
+ const { plugins: t, ...s } = r ?? {}, e = C({ ...s, plugins: T(t) });
28
+ if (e !== void 0)
29
+ return z("sha256").update(a).update("\0").update(e).digest("hex");
30
+ }
31
+ function A(a, r, t, s) {
32
+ for (a.delete(r), a.set(r, t); a.size > s; ) {
33
+ const e = a.keys().next().value;
34
+ if (e === void 0) break;
35
+ a.delete(e);
36
+ }
37
+ return t;
38
+ }
39
+ function H(a, r, t, s) {
40
+ if (!r) return t();
41
+ const e = a.get(r);
42
+ if (e)
43
+ return a.delete(r), a.set(r, e), e;
44
+ const n = t().catch((o) => {
45
+ throw a.get(r) === n && a.delete(r), o;
46
+ });
47
+ return A(a, r, n, s);
48
+ }
49
+ function F({
50
+ maxEntries: a = 64,
51
+ warningState: r = /* @__PURE__ */ new Set()
52
+ } = {}) {
53
+ const t = Number.isFinite(a) && a > 0 ? Math.floor(a) : 64, s = /* @__PURE__ */ new Map();
54
+ return {
55
+ prepare(e, n) {
56
+ return H(
57
+ s,
58
+ R(e, n),
59
+ () => L(e, n, { warnedLanguages: r }),
60
+ t
61
+ );
62
+ },
63
+ clear() {
64
+ s.clear(), r.clear();
65
+ }
66
+ };
67
+ }
68
+ function q(a = {}) {
69
+ const r = /* @__PURE__ */ new Set(), t = F({ ...a, warningState: r });
70
+ return {
71
+ async render(s, e = {}) {
72
+ const n = await t.prepare(s, e.markdown);
73
+ return {
74
+ content: /* @__PURE__ */ c(
75
+ k,
76
+ {
77
+ document: n.document,
78
+ classNames: e.classNames,
79
+ components: e.components,
80
+ slots: e.slots,
81
+ className: e.className,
82
+ as: e.as,
83
+ "data-df-runtime": "static",
84
+ urlTransform: e.urlTransform
85
+ }
86
+ ),
87
+ assets: n.assets
88
+ };
89
+ },
90
+ async renderMdx(s, e = {}) {
91
+ if (e.markdown?.html && e.markdown.html !== "trusted")
92
+ throw new Error("MDX executes trusted JSX and does not support sanitize or strip HTML policies");
93
+ const n = await O(e.markdown, s, {
94
+ warnedLanguages: r
95
+ }), l = (await w(
96
+ {
97
+ value: P(s),
98
+ data: { docfuseLocale: e.markdown?.locale?.trim() || void 0 }
99
+ },
100
+ {
101
+ ...p,
102
+ remarkPlugins: n.remarkPlugins,
103
+ rehypePlugins: n.rehypePlugins,
104
+ remarkRehypeOptions: n.remarkRehypeOptions,
105
+ baseUrl: e.baseUrl ?? import.meta.url
106
+ }
107
+ )).default, d = f(
108
+ e.classNames,
109
+ e.slots,
110
+ e.components,
111
+ e.urlTransform
112
+ );
113
+ return {
114
+ content: /* @__PURE__ */ c(
115
+ h,
116
+ {
117
+ "data-df-runtime": "static",
118
+ as: e.as,
119
+ className: e.className,
120
+ classNames: e.classNames,
121
+ slots: e.slots,
122
+ urlTransform: e.urlTransform,
123
+ children: /* @__PURE__ */ c(l, { components: d })
124
+ }
125
+ ),
126
+ assets: n.getAssets()
127
+ };
128
+ },
129
+ clear() {
130
+ t.clear();
131
+ }
132
+ };
133
+ }
134
+ export {
135
+ q as createMarkdownRenderer,
136
+ G as defineMarkdownPlugin
137
+ };
@@ -0,0 +1,2 @@
1
+ /** Copy text in both secure and legacy browser contexts. */
2
+ export declare function copyMarkdownText(value: string): Promise<boolean>;
@@ -0,0 +1,6 @@
1
+ export type MarkdownFileKind = 'package' | 'config' | 'typescript' | 'javascript' | 'markdown' | 'style' | 'data' | 'database' | 'shell' | 'container' | 'diff' | 'component' | 'source' | 'environment' | 'file';
2
+ export type MarkdownFileIconName = 'astro' | 'bun' | 'console' | 'css' | 'database' | 'deno' | 'diff' | 'docker' | 'docfuse' | 'document' | 'environment' | 'git' | 'github-actions' | 'go' | 'javascript' | 'json' | 'markdown' | 'nodejs' | 'npm' | 'pnpm' | 'python' | 'react' | 'rust' | 'sass' | 'config' | 'settings' | 'svelte' | 'typescript' | 'vue' | 'yaml' | 'yarn';
3
+ /** Filename associations take precedence over extension and language fallbacks. */
4
+ export declare function markdownFileKind(filename: string, language?: string): MarkdownFileKind;
5
+ /** Material Icon Theme-style filename associations, with filenames taking priority. */
6
+ export declare function markdownFileIconName(filename: string, language?: string): MarkdownFileIconName;