@ai-react-markdown/core 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +107 -104
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +158 -4
- package/dist/index.d.ts +158 -4
- package/dist/index.js +107 -104
- package/dist/index.js.map +1 -1
- package/package.json +34 -6
package/dist/index.d.cts
CHANGED
|
@@ -2,64 +2,218 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
|
2
2
|
import { ComponentType, PropsWithChildren } from 'react';
|
|
3
3
|
import { Components } from 'react-markdown';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Core type definitions, enums, and default configuration for ai-react-markdown.
|
|
7
|
+
*
|
|
8
|
+
* This module defines the public API surface for configuring the renderer,
|
|
9
|
+
* including extra markdown syntax extensions, display optimization abilities,
|
|
10
|
+
* typography theming, and the shared render state shape.
|
|
11
|
+
*
|
|
12
|
+
* @module defs
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Extra markdown syntax extensions beyond standard GFM.
|
|
17
|
+
* Enable or disable these via {@link AIMarkdownRenderConfig.extraSyntaxSupported}.
|
|
18
|
+
*/
|
|
5
19
|
declare enum AIMarkdownRenderExtraSyntax {
|
|
6
|
-
|
|
7
|
-
|
|
20
|
+
/** `==Highlight==` syntax support. */
|
|
21
|
+
HIGHLIGHT = "HIGHLIGHT",
|
|
22
|
+
/** Definition list syntax. @see https://michelf.ca/projects/php-markdown/extra/#def-list */
|
|
23
|
+
DEFINITION_LIST = "DEFINITION_LIST",
|
|
24
|
+
/** Superscript (`^text^`) and subscript (`~text~`) syntax. */
|
|
8
25
|
SUBSCRIPT = "SUBSCRIPT"
|
|
9
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Display optimization abilities applied during markdown processing.
|
|
29
|
+
* Enable or disable these via {@link AIMarkdownRenderConfig.displayOptimizeAbilities}.
|
|
30
|
+
*/
|
|
10
31
|
declare enum AIMarkdownRenderDisplayOptimizeAbility {
|
|
11
|
-
|
|
12
|
-
|
|
32
|
+
/** Strip HTML comments from the content. */
|
|
33
|
+
REMOVE_COMMENTS = "REMOVE_COMMENTS",
|
|
34
|
+
/** Typographic enhancements via SmartyPants (curly quotes, em-dashes, etc.). @see https://www.npmjs.com/package/smartypants */
|
|
35
|
+
SMARTYPANTS = "SMARTYPANTS",
|
|
36
|
+
/** Automatically insert spaces between CJK and half-width characters. */
|
|
13
37
|
PANGU = "PANGU"
|
|
14
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Configuration object controlling which markdown extensions and
|
|
41
|
+
* display optimizations are active during rendering.
|
|
42
|
+
*/
|
|
15
43
|
interface AIMarkdownRenderConfig {
|
|
44
|
+
/** Extra syntax extensions to enable. */
|
|
16
45
|
extraSyntaxSupported: AIMarkdownRenderExtraSyntax[];
|
|
46
|
+
/** Display optimization abilities to enable. */
|
|
17
47
|
displayOptimizeAbilities: AIMarkdownRenderDisplayOptimizeAbility[];
|
|
18
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Arbitrary metadata that consumers can pass through the render context.
|
|
51
|
+
* Custom renderers can access this via {@link AIMarkdownRenderState.metadata}.
|
|
52
|
+
*/
|
|
19
53
|
interface AIMarkdownMetadata extends Record<string, any> {
|
|
20
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Typography variant identifier. Built-in variant is `'default'`;
|
|
57
|
+
* consumers may define additional variants via custom typography components.
|
|
58
|
+
*/
|
|
21
59
|
type AIMarkdownVariant = 'default' | (string & {});
|
|
60
|
+
/**
|
|
61
|
+
* Color scheme identifier. Built-in schemes are `'light'` and `'dark'`;
|
|
62
|
+
* consumers may define additional schemes via custom typography CSS.
|
|
63
|
+
*/
|
|
22
64
|
type AIMarkdownColorScheme = 'light' | 'dark' | (string & {});
|
|
65
|
+
/** Props accepted by a typography wrapper component. */
|
|
23
66
|
interface AIMarkdownTypographyProps extends PropsWithChildren {
|
|
67
|
+
/** Resolved CSS font-size value (e.g. `'14px'`, `'0.875rem'`). */
|
|
24
68
|
fontSize: string;
|
|
69
|
+
/** Active typography variant. */
|
|
25
70
|
variant?: AIMarkdownVariant;
|
|
71
|
+
/** Active color scheme. */
|
|
26
72
|
colorScheme?: AIMarkdownColorScheme;
|
|
27
73
|
}
|
|
74
|
+
/** React component type for the typography wrapper. */
|
|
28
75
|
type AIMarkdownTypographyComponent = ComponentType<AIMarkdownTypographyProps>;
|
|
76
|
+
/** Props accepted by an optional extra style wrapper component. */
|
|
29
77
|
interface AIMarkdownExtraStyleProps extends PropsWithChildren {
|
|
30
78
|
}
|
|
79
|
+
/** React component type for an optional extra style wrapper. */
|
|
31
80
|
type AIMarkdownExtraStyleComponent = ComponentType<AIMarkdownExtraStyleProps>;
|
|
81
|
+
/**
|
|
82
|
+
* Immutable render state exposed to all descendant components via React context.
|
|
83
|
+
* Access this with the {@link useAIMarkdownRenderState} hook.
|
|
84
|
+
*
|
|
85
|
+
* @typeParam TConfig - Render configuration type (defaults to {@link AIMarkdownRenderConfig}).
|
|
86
|
+
* @typeParam TMetadata - Metadata type (defaults to {@link AIMarkdownMetadata}).
|
|
87
|
+
*/
|
|
32
88
|
interface AIMarkdownRenderState<TConfig extends AIMarkdownRenderConfig = AIMarkdownRenderConfig, TMetadata extends AIMarkdownMetadata = AIMarkdownMetadata> {
|
|
89
|
+
/** Whether the content is currently being streamed (e.g. from an LLM). */
|
|
33
90
|
streaming: boolean;
|
|
91
|
+
/** Resolved CSS font-size value. */
|
|
34
92
|
fontSize: string;
|
|
93
|
+
/** Active render configuration. */
|
|
35
94
|
config: TConfig;
|
|
95
|
+
/** Optional consumer-provided metadata. */
|
|
36
96
|
metadata?: TMetadata;
|
|
37
97
|
}
|
|
38
98
|
|
|
99
|
+
/**
|
|
100
|
+
* Shared TypeScript utility types.
|
|
101
|
+
*
|
|
102
|
+
* @module ts-util
|
|
103
|
+
*/
|
|
104
|
+
/**
|
|
105
|
+
* Recursively makes all properties of `T` optional.
|
|
106
|
+
* Unlike the built-in `Partial<T>`, this traverses nested objects.
|
|
107
|
+
*
|
|
108
|
+
* @typeParam T - The type to make deeply partial.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* type Config = { a: { b: number } };
|
|
113
|
+
* type PartialConfig = DeepPartial<Config>;
|
|
114
|
+
* // { a?: { b?: number } }
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
39
117
|
type DeepPartial<T> = {
|
|
40
118
|
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
41
119
|
};
|
|
42
120
|
|
|
121
|
+
/**
|
|
122
|
+
* Access the current {@link AIMarkdownRenderState} from within the `<AIMarkdown>` tree.
|
|
123
|
+
*
|
|
124
|
+
* Must be called inside a component rendered as a descendant of `<AIMarkdown>`.
|
|
125
|
+
* Throws if called outside the provider boundary.
|
|
126
|
+
*
|
|
127
|
+
* @typeParam TConfig - Expected configuration shape (defaults to {@link AIMarkdownRenderConfig}).
|
|
128
|
+
* @typeParam TMetadata - Expected metadata shape (defaults to {@link AIMarkdownMetadata}).
|
|
129
|
+
* @returns The current render state.
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```tsx
|
|
133
|
+
* function CustomCodeBlock({ children }: PropsWithChildren) {
|
|
134
|
+
* const { streaming, config } = useAIMarkdownRenderState();
|
|
135
|
+
* // ...
|
|
136
|
+
* }
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
43
139
|
declare function useAIMarkdownRenderState<TConfig extends AIMarkdownRenderConfig = AIMarkdownRenderConfig, TMetadata extends AIMarkdownMetadata = AIMarkdownMetadata>(): AIMarkdownRenderState<TConfig, TMetadata>;
|
|
140
|
+
/** Props for {@link AIMarkdownRenderStateProvider}. */
|
|
44
141
|
interface AIMarkdownRenderStateProviderProps<TConfig extends AIMarkdownRenderConfig = AIMarkdownRenderConfig, TMetadata extends AIMarkdownMetadata = AIMarkdownMetadata> extends PropsWithChildren {
|
|
45
142
|
streaming: boolean;
|
|
46
143
|
fontSize: string;
|
|
144
|
+
/** Partial config that will be deep-merged with {@link defaultAIMarkdownRenderConfig}. */
|
|
47
145
|
config?: DeepPartial<TConfig>;
|
|
48
146
|
metadata?: TMetadata;
|
|
49
147
|
}
|
|
50
148
|
|
|
149
|
+
/**
|
|
150
|
+
* Type definitions for the content preprocessor pipeline.
|
|
151
|
+
*
|
|
152
|
+
* @module preprocessors/defs
|
|
153
|
+
*/
|
|
154
|
+
/**
|
|
155
|
+
* A synchronous function that transforms raw markdown content before it is
|
|
156
|
+
* passed to the remark/rehype rendering pipeline.
|
|
157
|
+
*
|
|
158
|
+
* Preprocessors run in sequence -- each receives the output of the previous one.
|
|
159
|
+
*
|
|
160
|
+
* @param content - The raw (or partially processed) markdown string.
|
|
161
|
+
* @returns The transformed markdown string.
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```ts
|
|
165
|
+
* const stripFrontmatter: AIMDContentPreprocessor = (content) =>
|
|
166
|
+
* content.replace(/^---[\s\S]*?---\n/, '');
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
51
169
|
type AIMDContentPreprocessor = (content: string) => string;
|
|
52
170
|
|
|
171
|
+
/**
|
|
172
|
+
* Props for the `<AIMarkdown>` component.
|
|
173
|
+
*
|
|
174
|
+
* @typeParam TConfig - Custom render configuration type (extends {@link AIMarkdownRenderConfig}).
|
|
175
|
+
* @typeParam TRenderData - Custom metadata type (extends {@link AIMarkdownMetadata}).
|
|
176
|
+
*/
|
|
53
177
|
interface AIMarkdownProps<TConfig extends AIMarkdownRenderConfig = AIMarkdownRenderConfig, TRenderData extends AIMarkdownMetadata = AIMarkdownMetadata> extends Omit<AIMarkdownRenderStateProviderProps<TConfig, TRenderData>, 'fontSize'> {
|
|
178
|
+
/**
|
|
179
|
+
* Base font size for the rendered output.
|
|
180
|
+
* Accepts a CSS length string (e.g. `'14px'`, `'0.875rem'`) or a number
|
|
181
|
+
* which is treated as pixels. Defaults to `'0.875rem'`.
|
|
182
|
+
*/
|
|
54
183
|
fontSize?: number | string;
|
|
184
|
+
/** Raw markdown content to render. */
|
|
55
185
|
content: string;
|
|
186
|
+
/**
|
|
187
|
+
* Additional preprocessors to run on the raw markdown before rendering.
|
|
188
|
+
* These run *after* the built-in LaTeX preprocessor.
|
|
189
|
+
*/
|
|
56
190
|
contentPreprocessors?: AIMDContentPreprocessor[];
|
|
191
|
+
/**
|
|
192
|
+
* Custom `react-markdown` component overrides.
|
|
193
|
+
* Use this to replace the default renderers for specific HTML elements
|
|
194
|
+
* (e.g. code blocks, links, images).
|
|
195
|
+
*/
|
|
57
196
|
customComponents?: Components;
|
|
197
|
+
/**
|
|
198
|
+
* Typography wrapper component. Receives `fontSize`, `variant`, and `colorScheme`.
|
|
199
|
+
* Defaults to the built-in {@link DefaultTypography}.
|
|
200
|
+
*/
|
|
58
201
|
typography?: AIMarkdownTypographyComponent;
|
|
202
|
+
/**
|
|
203
|
+
* Optional extra style wrapper component rendered between the typography
|
|
204
|
+
* wrapper and the markdown content. Useful for injecting additional
|
|
205
|
+
* CSS scope or theme providers.
|
|
206
|
+
*/
|
|
59
207
|
extraStyle?: AIMarkdownExtraStyleComponent;
|
|
208
|
+
/** Typography variant name. Defaults to `'default'`. */
|
|
60
209
|
variant?: AIMarkdownVariant;
|
|
210
|
+
/** Color scheme name. Defaults to `'light'`. */
|
|
61
211
|
colorScheme?: AIMarkdownColorScheme;
|
|
62
212
|
}
|
|
213
|
+
/**
|
|
214
|
+
* Root component that preprocesses markdown content and renders it through
|
|
215
|
+
* a configurable remark/rehype pipeline wrapped in typography and style layers.
|
|
216
|
+
*/
|
|
63
217
|
declare const AIMarkdownComponent: <TConfig extends AIMarkdownRenderConfig = AIMarkdownRenderConfig, TRenderData extends AIMarkdownMetadata = AIMarkdownMetadata>({ streaming, content, fontSize, contentPreprocessors, customComponents, config, metadata, typography: Typography, extraStyle: ExtraStyle, variant, colorScheme, }: AIMarkdownProps<TConfig, TRenderData>) => react_jsx_runtime.JSX.Element;
|
|
64
218
|
declare const _default: typeof AIMarkdownComponent;
|
|
65
219
|
|
package/dist/index.d.ts
CHANGED
|
@@ -2,64 +2,218 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
|
2
2
|
import { ComponentType, PropsWithChildren } from 'react';
|
|
3
3
|
import { Components } from 'react-markdown';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Core type definitions, enums, and default configuration for ai-react-markdown.
|
|
7
|
+
*
|
|
8
|
+
* This module defines the public API surface for configuring the renderer,
|
|
9
|
+
* including extra markdown syntax extensions, display optimization abilities,
|
|
10
|
+
* typography theming, and the shared render state shape.
|
|
11
|
+
*
|
|
12
|
+
* @module defs
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Extra markdown syntax extensions beyond standard GFM.
|
|
17
|
+
* Enable or disable these via {@link AIMarkdownRenderConfig.extraSyntaxSupported}.
|
|
18
|
+
*/
|
|
5
19
|
declare enum AIMarkdownRenderExtraSyntax {
|
|
6
|
-
|
|
7
|
-
|
|
20
|
+
/** `==Highlight==` syntax support. */
|
|
21
|
+
HIGHLIGHT = "HIGHLIGHT",
|
|
22
|
+
/** Definition list syntax. @see https://michelf.ca/projects/php-markdown/extra/#def-list */
|
|
23
|
+
DEFINITION_LIST = "DEFINITION_LIST",
|
|
24
|
+
/** Superscript (`^text^`) and subscript (`~text~`) syntax. */
|
|
8
25
|
SUBSCRIPT = "SUBSCRIPT"
|
|
9
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Display optimization abilities applied during markdown processing.
|
|
29
|
+
* Enable or disable these via {@link AIMarkdownRenderConfig.displayOptimizeAbilities}.
|
|
30
|
+
*/
|
|
10
31
|
declare enum AIMarkdownRenderDisplayOptimizeAbility {
|
|
11
|
-
|
|
12
|
-
|
|
32
|
+
/** Strip HTML comments from the content. */
|
|
33
|
+
REMOVE_COMMENTS = "REMOVE_COMMENTS",
|
|
34
|
+
/** Typographic enhancements via SmartyPants (curly quotes, em-dashes, etc.). @see https://www.npmjs.com/package/smartypants */
|
|
35
|
+
SMARTYPANTS = "SMARTYPANTS",
|
|
36
|
+
/** Automatically insert spaces between CJK and half-width characters. */
|
|
13
37
|
PANGU = "PANGU"
|
|
14
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Configuration object controlling which markdown extensions and
|
|
41
|
+
* display optimizations are active during rendering.
|
|
42
|
+
*/
|
|
15
43
|
interface AIMarkdownRenderConfig {
|
|
44
|
+
/** Extra syntax extensions to enable. */
|
|
16
45
|
extraSyntaxSupported: AIMarkdownRenderExtraSyntax[];
|
|
46
|
+
/** Display optimization abilities to enable. */
|
|
17
47
|
displayOptimizeAbilities: AIMarkdownRenderDisplayOptimizeAbility[];
|
|
18
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Arbitrary metadata that consumers can pass through the render context.
|
|
51
|
+
* Custom renderers can access this via {@link AIMarkdownRenderState.metadata}.
|
|
52
|
+
*/
|
|
19
53
|
interface AIMarkdownMetadata extends Record<string, any> {
|
|
20
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Typography variant identifier. Built-in variant is `'default'`;
|
|
57
|
+
* consumers may define additional variants via custom typography components.
|
|
58
|
+
*/
|
|
21
59
|
type AIMarkdownVariant = 'default' | (string & {});
|
|
60
|
+
/**
|
|
61
|
+
* Color scheme identifier. Built-in schemes are `'light'` and `'dark'`;
|
|
62
|
+
* consumers may define additional schemes via custom typography CSS.
|
|
63
|
+
*/
|
|
22
64
|
type AIMarkdownColorScheme = 'light' | 'dark' | (string & {});
|
|
65
|
+
/** Props accepted by a typography wrapper component. */
|
|
23
66
|
interface AIMarkdownTypographyProps extends PropsWithChildren {
|
|
67
|
+
/** Resolved CSS font-size value (e.g. `'14px'`, `'0.875rem'`). */
|
|
24
68
|
fontSize: string;
|
|
69
|
+
/** Active typography variant. */
|
|
25
70
|
variant?: AIMarkdownVariant;
|
|
71
|
+
/** Active color scheme. */
|
|
26
72
|
colorScheme?: AIMarkdownColorScheme;
|
|
27
73
|
}
|
|
74
|
+
/** React component type for the typography wrapper. */
|
|
28
75
|
type AIMarkdownTypographyComponent = ComponentType<AIMarkdownTypographyProps>;
|
|
76
|
+
/** Props accepted by an optional extra style wrapper component. */
|
|
29
77
|
interface AIMarkdownExtraStyleProps extends PropsWithChildren {
|
|
30
78
|
}
|
|
79
|
+
/** React component type for an optional extra style wrapper. */
|
|
31
80
|
type AIMarkdownExtraStyleComponent = ComponentType<AIMarkdownExtraStyleProps>;
|
|
81
|
+
/**
|
|
82
|
+
* Immutable render state exposed to all descendant components via React context.
|
|
83
|
+
* Access this with the {@link useAIMarkdownRenderState} hook.
|
|
84
|
+
*
|
|
85
|
+
* @typeParam TConfig - Render configuration type (defaults to {@link AIMarkdownRenderConfig}).
|
|
86
|
+
* @typeParam TMetadata - Metadata type (defaults to {@link AIMarkdownMetadata}).
|
|
87
|
+
*/
|
|
32
88
|
interface AIMarkdownRenderState<TConfig extends AIMarkdownRenderConfig = AIMarkdownRenderConfig, TMetadata extends AIMarkdownMetadata = AIMarkdownMetadata> {
|
|
89
|
+
/** Whether the content is currently being streamed (e.g. from an LLM). */
|
|
33
90
|
streaming: boolean;
|
|
91
|
+
/** Resolved CSS font-size value. */
|
|
34
92
|
fontSize: string;
|
|
93
|
+
/** Active render configuration. */
|
|
35
94
|
config: TConfig;
|
|
95
|
+
/** Optional consumer-provided metadata. */
|
|
36
96
|
metadata?: TMetadata;
|
|
37
97
|
}
|
|
38
98
|
|
|
99
|
+
/**
|
|
100
|
+
* Shared TypeScript utility types.
|
|
101
|
+
*
|
|
102
|
+
* @module ts-util
|
|
103
|
+
*/
|
|
104
|
+
/**
|
|
105
|
+
* Recursively makes all properties of `T` optional.
|
|
106
|
+
* Unlike the built-in `Partial<T>`, this traverses nested objects.
|
|
107
|
+
*
|
|
108
|
+
* @typeParam T - The type to make deeply partial.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* type Config = { a: { b: number } };
|
|
113
|
+
* type PartialConfig = DeepPartial<Config>;
|
|
114
|
+
* // { a?: { b?: number } }
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
39
117
|
type DeepPartial<T> = {
|
|
40
118
|
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
41
119
|
};
|
|
42
120
|
|
|
121
|
+
/**
|
|
122
|
+
* Access the current {@link AIMarkdownRenderState} from within the `<AIMarkdown>` tree.
|
|
123
|
+
*
|
|
124
|
+
* Must be called inside a component rendered as a descendant of `<AIMarkdown>`.
|
|
125
|
+
* Throws if called outside the provider boundary.
|
|
126
|
+
*
|
|
127
|
+
* @typeParam TConfig - Expected configuration shape (defaults to {@link AIMarkdownRenderConfig}).
|
|
128
|
+
* @typeParam TMetadata - Expected metadata shape (defaults to {@link AIMarkdownMetadata}).
|
|
129
|
+
* @returns The current render state.
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```tsx
|
|
133
|
+
* function CustomCodeBlock({ children }: PropsWithChildren) {
|
|
134
|
+
* const { streaming, config } = useAIMarkdownRenderState();
|
|
135
|
+
* // ...
|
|
136
|
+
* }
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
43
139
|
declare function useAIMarkdownRenderState<TConfig extends AIMarkdownRenderConfig = AIMarkdownRenderConfig, TMetadata extends AIMarkdownMetadata = AIMarkdownMetadata>(): AIMarkdownRenderState<TConfig, TMetadata>;
|
|
140
|
+
/** Props for {@link AIMarkdownRenderStateProvider}. */
|
|
44
141
|
interface AIMarkdownRenderStateProviderProps<TConfig extends AIMarkdownRenderConfig = AIMarkdownRenderConfig, TMetadata extends AIMarkdownMetadata = AIMarkdownMetadata> extends PropsWithChildren {
|
|
45
142
|
streaming: boolean;
|
|
46
143
|
fontSize: string;
|
|
144
|
+
/** Partial config that will be deep-merged with {@link defaultAIMarkdownRenderConfig}. */
|
|
47
145
|
config?: DeepPartial<TConfig>;
|
|
48
146
|
metadata?: TMetadata;
|
|
49
147
|
}
|
|
50
148
|
|
|
149
|
+
/**
|
|
150
|
+
* Type definitions for the content preprocessor pipeline.
|
|
151
|
+
*
|
|
152
|
+
* @module preprocessors/defs
|
|
153
|
+
*/
|
|
154
|
+
/**
|
|
155
|
+
* A synchronous function that transforms raw markdown content before it is
|
|
156
|
+
* passed to the remark/rehype rendering pipeline.
|
|
157
|
+
*
|
|
158
|
+
* Preprocessors run in sequence -- each receives the output of the previous one.
|
|
159
|
+
*
|
|
160
|
+
* @param content - The raw (or partially processed) markdown string.
|
|
161
|
+
* @returns The transformed markdown string.
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```ts
|
|
165
|
+
* const stripFrontmatter: AIMDContentPreprocessor = (content) =>
|
|
166
|
+
* content.replace(/^---[\s\S]*?---\n/, '');
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
51
169
|
type AIMDContentPreprocessor = (content: string) => string;
|
|
52
170
|
|
|
171
|
+
/**
|
|
172
|
+
* Props for the `<AIMarkdown>` component.
|
|
173
|
+
*
|
|
174
|
+
* @typeParam TConfig - Custom render configuration type (extends {@link AIMarkdownRenderConfig}).
|
|
175
|
+
* @typeParam TRenderData - Custom metadata type (extends {@link AIMarkdownMetadata}).
|
|
176
|
+
*/
|
|
53
177
|
interface AIMarkdownProps<TConfig extends AIMarkdownRenderConfig = AIMarkdownRenderConfig, TRenderData extends AIMarkdownMetadata = AIMarkdownMetadata> extends Omit<AIMarkdownRenderStateProviderProps<TConfig, TRenderData>, 'fontSize'> {
|
|
178
|
+
/**
|
|
179
|
+
* Base font size for the rendered output.
|
|
180
|
+
* Accepts a CSS length string (e.g. `'14px'`, `'0.875rem'`) or a number
|
|
181
|
+
* which is treated as pixels. Defaults to `'0.875rem'`.
|
|
182
|
+
*/
|
|
54
183
|
fontSize?: number | string;
|
|
184
|
+
/** Raw markdown content to render. */
|
|
55
185
|
content: string;
|
|
186
|
+
/**
|
|
187
|
+
* Additional preprocessors to run on the raw markdown before rendering.
|
|
188
|
+
* These run *after* the built-in LaTeX preprocessor.
|
|
189
|
+
*/
|
|
56
190
|
contentPreprocessors?: AIMDContentPreprocessor[];
|
|
191
|
+
/**
|
|
192
|
+
* Custom `react-markdown` component overrides.
|
|
193
|
+
* Use this to replace the default renderers for specific HTML elements
|
|
194
|
+
* (e.g. code blocks, links, images).
|
|
195
|
+
*/
|
|
57
196
|
customComponents?: Components;
|
|
197
|
+
/**
|
|
198
|
+
* Typography wrapper component. Receives `fontSize`, `variant`, and `colorScheme`.
|
|
199
|
+
* Defaults to the built-in {@link DefaultTypography}.
|
|
200
|
+
*/
|
|
58
201
|
typography?: AIMarkdownTypographyComponent;
|
|
202
|
+
/**
|
|
203
|
+
* Optional extra style wrapper component rendered between the typography
|
|
204
|
+
* wrapper and the markdown content. Useful for injecting additional
|
|
205
|
+
* CSS scope or theme providers.
|
|
206
|
+
*/
|
|
59
207
|
extraStyle?: AIMarkdownExtraStyleComponent;
|
|
208
|
+
/** Typography variant name. Defaults to `'default'`. */
|
|
60
209
|
variant?: AIMarkdownVariant;
|
|
210
|
+
/** Color scheme name. Defaults to `'light'`. */
|
|
61
211
|
colorScheme?: AIMarkdownColorScheme;
|
|
62
212
|
}
|
|
213
|
+
/**
|
|
214
|
+
* Root component that preprocesses markdown content and renders it through
|
|
215
|
+
* a configurable remark/rehype pipeline wrapped in typography and style layers.
|
|
216
|
+
*/
|
|
63
217
|
declare const AIMarkdownComponent: <TConfig extends AIMarkdownRenderConfig = AIMarkdownRenderConfig, TRenderData extends AIMarkdownMetadata = AIMarkdownMetadata>({ streaming, content, fontSize, contentPreprocessors, customComponents, config, metadata, typography: Typography, extraStyle: ExtraStyle, variant, colorScheme, }: AIMarkdownProps<TConfig, TRenderData>) => react_jsx_runtime.JSX.Element;
|
|
64
218
|
declare const _default: typeof AIMarkdownComponent;
|
|
65
219
|
|