pd-markdown 2.0.0 → 2.0.2

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 (60) hide show
  1. package/README.md +52 -170
  2. package/package.json +12 -1
  3. package/packages/parser/dist/index.d.ts +121 -4
  4. package/packages/utils/dist/index.d.ts +144 -7
  5. package/packages/web/dist/index.d.ts +265 -8
  6. package/packages/parser/dist/index.d.ts.map +0 -1
  7. package/packages/parser/dist/plugins/index.d.ts +0 -4
  8. package/packages/parser/dist/plugins/index.d.ts.map +0 -1
  9. package/packages/parser/dist/plugins/transform/heading.d.ts +0 -6
  10. package/packages/parser/dist/plugins/transform/heading.d.ts.map +0 -1
  11. package/packages/parser/dist/plugins/transform/list.d.ts +0 -14
  12. package/packages/parser/dist/plugins/transform/list.d.ts.map +0 -1
  13. package/packages/parser/dist/plugins/transform/table.d.ts +0 -27
  14. package/packages/parser/dist/plugins/transform/table.d.ts.map +0 -1
  15. package/packages/parser/dist/processor.d.ts +0 -22
  16. package/packages/parser/dist/processor.d.ts.map +0 -1
  17. package/packages/parser/dist/types/index.d.ts +0 -55
  18. package/packages/parser/dist/types/index.d.ts.map +0 -1
  19. package/packages/utils/dist/ast/query.d.ts +0 -36
  20. package/packages/utils/dist/ast/query.d.ts.map +0 -1
  21. package/packages/utils/dist/ast/traverse.d.ts +0 -22
  22. package/packages/utils/dist/ast/traverse.d.ts.map +0 -1
  23. package/packages/utils/dist/index.d.ts.map +0 -1
  24. package/packages/utils/dist/string/sanitize.d.ts +0 -22
  25. package/packages/utils/dist/string/sanitize.d.ts.map +0 -1
  26. package/packages/utils/dist/string/slugify.d.ts +0 -16
  27. package/packages/utils/dist/string/slugify.d.ts.map +0 -1
  28. package/packages/utils/dist/types/index.d.ts +0 -49
  29. package/packages/utils/dist/types/index.d.ts.map +0 -1
  30. package/packages/web/dist/components/MarkdownRenderer.d.ts +0 -27
  31. package/packages/web/dist/components/MarkdownRenderer.d.ts.map +0 -1
  32. package/packages/web/dist/components/NodeRenderer.d.ts +0 -10
  33. package/packages/web/dist/components/NodeRenderer.d.ts.map +0 -1
  34. package/packages/web/dist/components/StreamMarkdownRenderer.d.ts +0 -58
  35. package/packages/web/dist/components/StreamMarkdownRenderer.d.ts.map +0 -1
  36. package/packages/web/dist/components/context.d.ts +0 -17
  37. package/packages/web/dist/components/context.d.ts.map +0 -1
  38. package/packages/web/dist/components/defaults/Blockquote.d.ts +0 -8
  39. package/packages/web/dist/components/defaults/Blockquote.d.ts.map +0 -1
  40. package/packages/web/dist/components/defaults/Code.d.ts +0 -13
  41. package/packages/web/dist/components/defaults/Code.d.ts.map +0 -1
  42. package/packages/web/dist/components/defaults/Heading.d.ts +0 -8
  43. package/packages/web/dist/components/defaults/Heading.d.ts.map +0 -1
  44. package/packages/web/dist/components/defaults/Image.d.ts +0 -7
  45. package/packages/web/dist/components/defaults/Image.d.ts.map +0 -1
  46. package/packages/web/dist/components/defaults/Link.d.ts +0 -8
  47. package/packages/web/dist/components/defaults/Link.d.ts.map +0 -1
  48. package/packages/web/dist/components/defaults/List.d.ts +0 -13
  49. package/packages/web/dist/components/defaults/List.d.ts.map +0 -1
  50. package/packages/web/dist/components/defaults/Paragraph.d.ts +0 -8
  51. package/packages/web/dist/components/defaults/Paragraph.d.ts.map +0 -1
  52. package/packages/web/dist/components/defaults/Table.d.ts +0 -19
  53. package/packages/web/dist/components/defaults/Table.d.ts.map +0 -1
  54. package/packages/web/dist/components/defaults/index.d.ts +0 -42
  55. package/packages/web/dist/components/defaults/index.d.ts.map +0 -1
  56. package/packages/web/dist/hooks/useMarkdown.d.ts +0 -11
  57. package/packages/web/dist/hooks/useMarkdown.d.ts.map +0 -1
  58. package/packages/web/dist/hooks/useStreamMarkdown.d.ts +0 -59
  59. package/packages/web/dist/hooks/useStreamMarkdown.d.ts.map +0 -1
  60. package/packages/web/dist/index.d.ts.map +0 -1
@@ -1,8 +1,265 @@
1
- export { MarkdownRenderer, type MarkdownRendererProps } from './components/MarkdownRenderer';
2
- export { NodeRenderer, type NodeRendererProps } from './components/NodeRenderer';
3
- export { StreamMarkdownRenderer, type StreamMarkdownRendererProps } from './components/StreamMarkdownRenderer';
4
- export { MarkdownContext, useMarkdownContext, type MarkdownContextValue } from './components/context';
5
- export { Heading, Paragraph, List, ListItem, Table, TableRow, TableCell, Code, InlineCodeComponent, Link, Image, Blockquote, defaultComponents, type ComponentMap, type HeadingProps, type ParagraphProps, type ListProps, type ListItemProps, type TableProps, type TableRowProps, type TableCellProps, type CodeProps, type InlineCodeProps, type LinkProps, type ImageProps, type BlockquoteProps, } from './components/defaults';
6
- export { useMarkdown } from './hooks/useMarkdown';
7
- export { useStreamMarkdown, type StreamState, type UseStreamMarkdownOptions, type UseStreamMarkdownReturn, } from './hooks/useStreamMarkdown';
8
- //# sourceMappingURL=index.d.ts.map
1
+ import * as React from 'react';
2
+ import { ReactNode, FC, CSSProperties } from 'react';
3
+ import { Heading as Heading$1, Paragraph as Paragraph$1, List as List$1, ListItem as ListItem$1, Table as Table$1, TableRow as TableRow$1, TableCell as TableCell$1, Code as Code$1, InlineCode, Link as Link$1, Image as Image$1, Blockquote as Blockquote$1, Root, Content } from 'mdast';
4
+ import { ParserOptions } from 'pd-markdown-parser';
5
+
6
+ interface HeadingProps {
7
+ node: Heading$1;
8
+ children: ReactNode;
9
+ }
10
+ declare const Heading: FC<HeadingProps>;
11
+
12
+ interface ParagraphProps {
13
+ node: Paragraph$1;
14
+ children: ReactNode;
15
+ }
16
+ declare const Paragraph: FC<ParagraphProps>;
17
+
18
+ interface ListProps {
19
+ node: List$1;
20
+ children: ReactNode;
21
+ }
22
+ declare const List: FC<ListProps>;
23
+ interface ListItemProps {
24
+ node: ListItem$1;
25
+ children: ReactNode;
26
+ }
27
+ declare const ListItem: FC<ListItemProps>;
28
+
29
+ interface TableProps {
30
+ node: Table$1;
31
+ children: ReactNode;
32
+ }
33
+ declare const Table: FC<TableProps>;
34
+ interface TableRowProps {
35
+ node: TableRow$1;
36
+ children: ReactNode;
37
+ isHeader?: boolean;
38
+ }
39
+ declare const TableRow: FC<TableRowProps>;
40
+ interface TableCellProps {
41
+ node: TableCell$1;
42
+ children: ReactNode;
43
+ }
44
+ declare const TableCell: FC<TableCellProps>;
45
+
46
+ interface CodeProps {
47
+ node: Code$1;
48
+ children?: ReactNode;
49
+ }
50
+ declare const Code: FC<CodeProps>;
51
+ interface InlineCodeProps {
52
+ node: InlineCode;
53
+ children?: ReactNode;
54
+ }
55
+ declare const InlineCodeComponent: FC<InlineCodeProps>;
56
+
57
+ interface LinkProps {
58
+ node: Link$1;
59
+ children: ReactNode;
60
+ }
61
+ declare const Link: FC<LinkProps>;
62
+
63
+ interface ImageProps {
64
+ node: Image$1;
65
+ }
66
+ declare const Image: FC<ImageProps>;
67
+
68
+ interface BlockquoteProps {
69
+ node: Blockquote$1;
70
+ children: ReactNode;
71
+ }
72
+ declare const Blockquote: FC<BlockquoteProps>;
73
+
74
+ /**
75
+ * Map of node types to their corresponding React components
76
+ */
77
+ interface ComponentMap {
78
+ heading: React.FC<HeadingProps>;
79
+ paragraph: React.FC<ParagraphProps>;
80
+ list: React.FC<ListProps>;
81
+ listItem: React.FC<ListItemProps>;
82
+ table: React.FC<TableProps>;
83
+ tableRow: React.FC<TableRowProps>;
84
+ tableCell: React.FC<TableCellProps>;
85
+ code: React.FC<CodeProps>;
86
+ inlineCode: React.FC<InlineCodeProps>;
87
+ link: React.FC<LinkProps>;
88
+ image: React.FC<ImageProps>;
89
+ blockquote: React.FC<BlockquoteProps>;
90
+ [key: string]: React.FC<any>;
91
+ }
92
+ /**
93
+ * Default component map
94
+ */
95
+ declare const defaultComponents: ComponentMap;
96
+
97
+ interface MarkdownRendererProps {
98
+ /** Markdown source string (will be parsed) */
99
+ source?: string;
100
+ /** Pre-parsed AST (skip parsing, useful for SSR) */
101
+ ast?: Root;
102
+ /** Custom component overrides */
103
+ components?: Partial<ComponentMap>;
104
+ /** CSS class name for wrapper */
105
+ className?: string;
106
+ /** Inline styles for wrapper */
107
+ style?: CSSProperties;
108
+ /** Parser options (only used when source is provided) */
109
+ parserOptions?: ParserOptions;
110
+ }
111
+ /**
112
+ * Main markdown renderer component
113
+ *
114
+ * Supports both client-side and server-side rendering:
115
+ * - Pass `source` for automatic parsing
116
+ * - Pass `ast` for pre-parsed content (SSR optimization)
117
+ */
118
+ declare const MarkdownRenderer: FC<MarkdownRendererProps>;
119
+
120
+ interface NodeRendererProps {
121
+ node: Content | Root;
122
+ }
123
+ /**
124
+ * Recursive node renderer that renders AST nodes to React elements
125
+ */
126
+ declare const NodeRenderer: FC<NodeRendererProps>;
127
+
128
+ interface StreamMarkdownRendererProps {
129
+ /** The streaming markdown source string — pass accumulated text */
130
+ source: string;
131
+ /** Whether the stream is currently active/receiving data */
132
+ isStreaming?: boolean;
133
+ /** Pre-parsed AST (skip internal parsing when using useStreamMarkdown) */
134
+ ast?: Root;
135
+ /** Custom component overrides */
136
+ components?: Partial<ComponentMap>;
137
+ /** CSS class name for wrapper */
138
+ className?: string;
139
+ /** Inline styles for wrapper */
140
+ style?: CSSProperties;
141
+ /** Parser options */
142
+ parserOptions?: ParserOptions;
143
+ /** Whether to show a blinking cursor at the end while streaming. Default: true */
144
+ showCursor?: boolean;
145
+ /** Custom cursor element */
146
+ cursorElement?: ReactNode;
147
+ /** CSS class name for the animated wrapper on new content */
148
+ animationClassName?: string;
149
+ /** Whether to enable fade-in animation for new blocks. Default: true */
150
+ enableAnimation?: boolean;
151
+ }
152
+ /**
153
+ * StreamMarkdownRenderer — A streaming-aware markdown renderer.
154
+ *
155
+ * This component is designed for rendering AI-generated streaming markdown.
156
+ * It shows a blinking cursor at the end while content is being streamed,
157
+ * and optionally animates new content blocks as they appear.
158
+ *
159
+ * Usage patterns:
160
+ *
161
+ * 1. **With `useStreamMarkdown` hook** (recommended):
162
+ * ```tsx
163
+ * const stream = useStreamMarkdown()
164
+ * // ... consume stream
165
+ * <StreamMarkdownRenderer
166
+ * source={stream.source}
167
+ * ast={stream.ast}
168
+ * isStreaming={stream.isStreaming}
169
+ * />
170
+ * ```
171
+ *
172
+ * 2. **Standalone** (pass source, let it parse internally):
173
+ * ```tsx
174
+ * <StreamMarkdownRenderer
175
+ * source={accumulatedText}
176
+ * isStreaming={isLoading}
177
+ * />
178
+ * ```
179
+ */
180
+ declare const StreamMarkdownRenderer: FC<StreamMarkdownRendererProps>;
181
+
182
+ /**
183
+ * Context value for markdown renderer
184
+ */
185
+ interface MarkdownContextValue {
186
+ /** Custom component overrides */
187
+ components: Partial<ComponentMap>;
188
+ }
189
+ /**
190
+ * Context for passing configuration down the component tree
191
+ */
192
+ declare const MarkdownContext: React.Context<MarkdownContextValue>;
193
+ /**
194
+ * Hook to access markdown context
195
+ */
196
+ declare function useMarkdownContext(): MarkdownContextValue;
197
+
198
+ /**
199
+ * Hook for parsing markdown on the client side
200
+ *
201
+ * @param source - Markdown source string
202
+ * @param options - Parser options
203
+ * @returns Parsed AST
204
+ */
205
+ declare function useMarkdown(source: string, options?: ParserOptions): Root;
206
+
207
+ interface StreamState {
208
+ /** The current accumulated markdown source */
209
+ source: string;
210
+ /** The parsed AST of the current source */
211
+ ast: Root;
212
+ /** Whether the stream is currently receiving data */
213
+ isStreaming: boolean;
214
+ /** Whether the stream has completed */
215
+ isDone: boolean;
216
+ /** Error if any occurred */
217
+ error: Error | null;
218
+ }
219
+ interface UseStreamMarkdownOptions {
220
+ /** Parser options */
221
+ parserOptions?: ParserOptions;
222
+ /** Callback when streaming starts */
223
+ onStart?: () => void;
224
+ /** Callback when a new chunk is received */
225
+ onChunk?: (chunk: string, fullText: string) => void;
226
+ /** Callback when streaming completes */
227
+ onDone?: (fullText: string) => void;
228
+ /** Callback on error */
229
+ onError?: (error: Error) => void;
230
+ /** Debounce interval for re-parsing (ms). Default: 50 */
231
+ parseDebounceMs?: number;
232
+ }
233
+ interface UseStreamMarkdownReturn extends StreamState {
234
+ /** Append a chunk of markdown text */
235
+ append: (chunk: string) => void;
236
+ /** Signal that the stream is complete */
237
+ done: () => void;
238
+ /** Reset the stream state */
239
+ reset: () => void;
240
+ /** Start consuming a ReadableStream */
241
+ consume: (stream: ReadableStream<string>) => Promise<void>;
242
+ /** Start consuming an async iterator */
243
+ consumeIterator: (iterator: AsyncIterable<string>) => Promise<void>;
244
+ /** Start consuming a fetch Response with SSE */
245
+ consumeResponse: (response: Response, options?: {
246
+ extractContent?: (data: string) => string | null;
247
+ }) => Promise<void>;
248
+ }
249
+ /**
250
+ * Hook for streaming markdown rendering.
251
+ *
252
+ * Provides a simple API to progressively append markdown text,
253
+ * automatically re-parsing into an AST that can be rendered
254
+ * by the MarkdownRenderer.
255
+ *
256
+ * Supports multiple consumption methods:
257
+ * - Manual `append()` + `done()` calls
258
+ * - `consume(readableStream)` for ReadableStream<string>
259
+ * - `consumeIterator(asyncIterable)` for async iterators
260
+ * - `consumeResponse(response)` for SSE/fetch responses
261
+ */
262
+ declare function useStreamMarkdown(options?: UseStreamMarkdownOptions): UseStreamMarkdownReturn;
263
+
264
+ export { Blockquote, Code, Heading, Image, InlineCodeComponent, Link, List, ListItem, MarkdownContext, MarkdownRenderer, NodeRenderer, Paragraph, StreamMarkdownRenderer, Table, TableCell, TableRow, defaultComponents, useMarkdown, useMarkdownContext, useStreamMarkdown };
265
+ export type { BlockquoteProps, CodeProps, ComponentMap, HeadingProps, ImageProps, InlineCodeProps, LinkProps, ListItemProps, ListProps, MarkdownContextValue, MarkdownRendererProps, NodeRendererProps, ParagraphProps, StreamMarkdownRendererProps, StreamState, TableCellProps, TableProps, TableRowProps, UseStreamMarkdownOptions, UseStreamMarkdownReturn };
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,YAAY,EACV,MAAM,EACN,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,QAAQ,GACT,MAAM,SAAS,CAAA;AAGhB,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAGxD,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA"}
@@ -1,4 +0,0 @@
1
- export { transformHeading } from './transform/heading';
2
- export { transformList } from './transform/list';
3
- export { transformTable } from './transform/table';
4
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugins/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA"}
@@ -1,6 +0,0 @@
1
- import type { Root } from 'mdast';
2
- /**
3
- * Transform plugin that adds slug IDs to headings
4
- */
5
- export declare function transformHeading(tree: Root): void;
6
- //# sourceMappingURL=heading.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"heading.d.ts","sourceRoot":"","sources":["../../../src/plugins/transform/heading.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAA4B,MAAM,OAAO,CAAA;AAqB3D;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAejD"}
@@ -1,14 +0,0 @@
1
- import type { Root } from 'mdast';
2
- /**
3
- * Extended list item with index
4
- */
5
- declare module 'mdast' {
6
- interface ListItemData {
7
- index?: number;
8
- }
9
- }
10
- /**
11
- * Transform plugin that adds index to list items
12
- */
13
- export declare function transformList(tree: Root): void;
14
- //# sourceMappingURL=list.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../src/plugins/transform/list.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAkB,MAAM,OAAO,CAAA;AAGjD;;GAEG;AACH,OAAO,QAAQ,OAAO,CAAC;IACrB,UAAU,YAAY;QACpB,KAAK,CAAC,EAAE,MAAM,CAAA;KACf;CACF;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAa9C"}
@@ -1,27 +0,0 @@
1
- import type { Root } from 'mdast';
2
- /**
3
- * Extended table data
4
- */
5
- declare module 'mdast' {
6
- interface TableData {
7
- /** Header row */
8
- header?: TableRow;
9
- /** Body rows */
10
- body?: TableRow[];
11
- }
12
- interface TableCellData {
13
- /** Whether this cell is in header */
14
- isHeader?: boolean;
15
- /** Column alignment */
16
- align?: 'left' | 'center' | 'right' | null;
17
- /** Column index */
18
- columnIndex?: number;
19
- }
20
- }
21
- /**
22
- * Transform plugin that enhances table structure
23
- * - Separates header and body rows
24
- * - Adds alignment and index info to cells
25
- */
26
- export declare function transformTable(tree: Root): void;
27
- //# sourceMappingURL=table.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../../src/plugins/transform/table.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAoB,MAAM,OAAO,CAAA;AAGnD;;GAEG;AACH,OAAO,QAAQ,OAAO,CAAC;IACrB,UAAU,SAAS;QACjB,iBAAiB;QACjB,MAAM,CAAC,EAAE,QAAQ,CAAA;QACjB,gBAAgB;QAChB,IAAI,CAAC,EAAE,QAAQ,EAAE,CAAA;KAClB;IAED,UAAU,aAAa;QACrB,qCAAqC;QACrC,QAAQ,CAAC,EAAE,OAAO,CAAA;QAClB,uBAAuB;QACvB,KAAK,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,GAAG,IAAI,CAAA;QAC1C,mBAAmB;QACnB,WAAW,CAAC,EAAE,MAAM,CAAA;KACrB;CACF;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAgC/C"}
@@ -1,22 +0,0 @@
1
- import type { Root } from 'mdast';
2
- import type { VFile } from 'vfile';
3
- import type { Parser, ParserOptions, ParserPlugin } from './types';
4
- /**
5
- * Create a markdown parser with the specified options
6
- *
7
- * @param options - Parser configuration options
8
- * @returns Parser instance with parse method
9
- */
10
- export declare function createParser(options?: ParserOptions): Parser;
11
- /**
12
- * Type-safe helper to define a parser plugin
13
- *
14
- * @param config - Plugin configuration
15
- * @returns Parser plugin
16
- */
17
- export declare function definePlugin<T = void>(config: {
18
- name: string;
19
- phase: 'before' | 'after';
20
- transform: (options?: T) => (tree: Root, file: VFile) => void;
21
- }, options?: T): ParserPlugin;
22
- //# sourceMappingURL=processor.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"processor.d.ts","sourceRoot":"","sources":["../src/processor.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,IAAI,EAAQ,MAAM,OAAO,CAAA;AACvC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AAElC,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,YAAY,EAAY,MAAM,SAAS,CAAA;AA2B5E;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,OAAO,GAAE,aAAkB,GAAG,MAAM,CAuDhE;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,CAAC,GAAG,IAAI,EACnC,MAAM,EAAE;IACN,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,QAAQ,GAAG,OAAO,CAAA;IACzB,SAAS,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,KAAK,IAAI,CAAA;CAC9D,EACD,OAAO,CAAC,EAAE,CAAC,GACV,YAAY,CAMd"}
@@ -1,55 +0,0 @@
1
- import type { Root } from 'mdast';
2
- import type { VFile } from 'vfile';
3
- /**
4
- * Parser plugin configuration
5
- */
6
- export interface ParserPlugin {
7
- /** Unique plugin name */
8
- name: string;
9
- /** When to run: before or after built-in transforms */
10
- phase: 'before' | 'after';
11
- /** Transform function */
12
- transform: (tree: Root, file: VFile) => void;
13
- }
14
- /**
15
- * Parser options
16
- */
17
- export interface ParserOptions {
18
- /** Custom plugins to add */
19
- plugins?: ParserPlugin[];
20
- /** Enable GFM syntax (default: true) */
21
- gfm?: boolean;
22
- /** Enable frontmatter parsing (default: true) */
23
- frontmatter?: boolean;
24
- }
25
- /**
26
- * Parser instance
27
- */
28
- export interface Parser {
29
- /** Parse markdown string to AST */
30
- parse(content: string): Root;
31
- }
32
- /**
33
- * Plugin definition helper config
34
- */
35
- export interface PluginConfig<T = unknown> {
36
- /** Plugin name */
37
- name: string;
38
- /** When to run */
39
- phase: 'before' | 'after';
40
- /** Transform function factory */
41
- transform: (options?: T) => (tree: Root, file: VFile) => void;
42
- }
43
- /**
44
- * Frontmatter data extracted from markdown
45
- */
46
- export interface FrontmatterData {
47
- [key: string]: unknown;
48
- }
49
- /**
50
- * Extended file data with frontmatter
51
- */
52
- export interface FileData {
53
- frontmatter?: FrontmatterData;
54
- }
55
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AAElC;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,yBAAyB;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,uDAAuD;IACvD,KAAK,EAAE,QAAQ,GAAG,OAAO,CAAA;IACzB,yBAAyB;IACzB,SAAS,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,KAAK,IAAI,CAAA;CAC7C;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,4BAA4B;IAC5B,OAAO,CAAC,EAAE,YAAY,EAAE,CAAA;IACxB,wCAAwC;IACxC,GAAG,CAAC,EAAE,OAAO,CAAA;IACb,iDAAiD;IACjD,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB,mCAAmC;IACnC,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,YAAY,CAAC,CAAC,GAAG,OAAO;IACvC,kBAAkB;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,kBAAkB;IAClB,KAAK,EAAE,QAAQ,GAAG,OAAO,CAAA;IACzB,iCAAiC;IACjC,SAAS,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,KAAK,IAAI,CAAA;CAC9D;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,WAAW,CAAC,EAAE,eAAe,CAAA;CAC9B"}
@@ -1,36 +0,0 @@
1
- import type { Node } from 'unist';
2
- import type { MdNode, Parent } from '../types';
3
- /**
4
- * Find all nodes of a specific type in the AST
5
- *
6
- * @param node - Root node to search from
7
- * @param type - Node type to find
8
- * @returns Array of matching nodes
9
- */
10
- export declare function findNodes<T extends Node = MdNode>(node: Node, type: string): T[];
11
- /**
12
- * Find the first node of a specific type in the AST
13
- *
14
- * @param node - Root node to search from
15
- * @param type - Node type to find
16
- * @returns The first matching node or undefined
17
- */
18
- export declare function findNode<T extends Node = MdNode>(node: Node, type: string): T | undefined;
19
- /**
20
- * Find all nodes matching a predicate
21
- *
22
- * @param node - Root node to search from
23
- * @param predicate - Function to test each node
24
- * @returns Array of matching nodes
25
- */
26
- export declare function findNodesBy<T extends Node = MdNode>(node: Node, predicate: (node: Node) => boolean): T[];
27
- /**
28
- * Get the parent of a node in the AST
29
- * Note: This requires traversing from root, use sparingly
30
- *
31
- * @param root - Root node of the AST
32
- * @param target - Node to find parent of
33
- * @returns Parent node or undefined if not found or is root
34
- */
35
- export declare function findParent(root: Node, target: Node): Parent | undefined;
36
- //# sourceMappingURL=query.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/ast/query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAG9C;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,IAAI,GAAG,MAAM,EAC/C,IAAI,EAAE,IAAI,EACV,IAAI,EAAE,MAAM,GACX,CAAC,EAAE,CAiBL;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,IAAI,GAAG,MAAM,EAC9C,IAAI,EAAE,IAAI,EACV,IAAI,EAAE,MAAM,GACX,CAAC,GAAG,SAAS,CAsBf;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,IAAI,GAAG,MAAM,EACjD,IAAI,EAAE,IAAI,EACV,SAAS,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,GACjC,CAAC,EAAE,CAiBL;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,GAAG,MAAM,GAAG,SAAS,CAsBvE"}
@@ -1,22 +0,0 @@
1
- import type { Node } from 'unist';
2
- import type { MdNode, Visitor } from '../types';
3
- /**
4
- * Traverse AST in depth-first order
5
- *
6
- * @param node - Root node to start traversal
7
- * @param visitor - Visitor function called for each node
8
- * Return `false` to skip children of current node
9
- * Return `true` or `undefined` to continue
10
- */
11
- export declare function traverseAst<T extends Node = MdNode>(node: T, visitor: Visitor<T>): void;
12
- /**
13
- * Traverse AST with enter and leave callbacks
14
- *
15
- * @param node - Root node to start traversal
16
- * @param callbacks - Object with optional enter and leave functions
17
- */
18
- export declare function traverseAstWithCallbacks<T extends Node = MdNode>(node: T, callbacks: {
19
- enter?: Visitor<T>;
20
- leave?: Visitor<T>;
21
- }): void;
22
- //# sourceMappingURL=traverse.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"traverse.d.ts","sourceRoot":"","sources":["../../src/ast/traverse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,KAAK,EAAU,MAAM,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAGvD;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,IAAI,GAAG,MAAM,EACjD,IAAI,EAAE,CAAC,EACP,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,GAClB,IAAI,CAsBN;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,SAAS,IAAI,GAAG,MAAM,EAC9D,IAAI,EAAE,CAAC,EACP,SAAS,EAAE;IACT,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAA;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAA;CACnB,GACA,IAAI,CAqBN"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,YAAY,EACV,MAAM,EACN,MAAM,EACN,MAAM,EACN,OAAO,EACP,OAAO,EACP,aAAa,EACb,QAAQ,EACR,QAAQ,GACT,MAAM,SAAS,CAAA;AAChB,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAGzD,OAAO,EAAE,WAAW,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAA;AACtE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAG1E,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AACzD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA"}
@@ -1,22 +0,0 @@
1
- /**
2
- * Escape HTML special characters
3
- *
4
- * @param text - Text to escape
5
- * @returns Escaped text safe for HTML insertion
6
- */
7
- export declare function escapeHtml(text: string): string;
8
- /**
9
- * Sanitize HTML string by removing dangerous content
10
- *
11
- * @param html - HTML string to sanitize
12
- * @returns Sanitized HTML string
13
- */
14
- export declare function sanitizeHtml(html: string): string;
15
- /**
16
- * Strip all HTML tags from a string
17
- *
18
- * @param html - HTML string to strip
19
- * @returns Plain text without HTML tags
20
- */
21
- export declare function stripHtml(html: string): string;
22
- //# sourceMappingURL=sanitize.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../src/string/sanitize.ts"],"names":[],"mappings":"AAWA;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE/C;AAwED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CA+CjD;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE9C"}
@@ -1,16 +0,0 @@
1
- /**
2
- * Convert text to URL-safe slug
3
- *
4
- * @param text - Text to slugify
5
- * @returns URL-safe slug
6
- */
7
- export declare function slugify(text: string): string;
8
- /**
9
- * Generate unique slug with counter suffix for duplicates
10
- *
11
- * @param text - Text to slugify
12
- * @param existingSlugs - Set of existing slugs to check against
13
- * @returns Unique slug
14
- */
15
- export declare function uniqueSlugify(text: string, existingSlugs: Set<string>): string;
16
- //# sourceMappingURL=slugify.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"slugify.d.ts","sourceRoot":"","sources":["../../src/string/slugify.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAe5C;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,MAAM,CAY9E"}
@@ -1,49 +0,0 @@
1
- import type { Root, Content, Parent, Literal } from 'mdast';
2
- import type { Node as UnistNode } from 'unist';
3
- export type { Root, Content, Parent, Literal };
4
- /**
5
- * All possible markdown node types
6
- */
7
- export type MdNode = Root | Content;
8
- /**
9
- * Root node of markdown AST
10
- */
11
- export type MdRoot = Root;
12
- /**
13
- * Visitor function for AST traversal
14
- */
15
- export type Visitor<T extends UnistNode = MdNode> = (node: T, index: number | undefined, parent: Parent | undefined) => void | boolean;
16
- /**
17
- * Plugin options base interface
18
- */
19
- export interface PluginOptions {
20
- [key: string]: unknown;
21
- }
22
- /**
23
- * Position information in source
24
- */
25
- export interface Position {
26
- line: number;
27
- column: number;
28
- offset?: number;
29
- }
30
- /**
31
- * Location in source
32
- */
33
- export interface Location {
34
- start: Position;
35
- end: Position;
36
- }
37
- /**
38
- * Type guard to check if node is a parent node
39
- */
40
- export declare function isParent(node: UnistNode): node is Parent;
41
- /**
42
- * Type guard to check if node is a literal node
43
- */
44
- export declare function isLiteral(node: UnistNode): node is Literal;
45
- /**
46
- * Type guard to check if node has specific type
47
- */
48
- export declare function isNodeType<T extends MdNode>(node: UnistNode, type: T['type']): node is T;
49
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC3D,OAAO,KAAK,EAAE,IAAI,IAAI,SAAS,EAAE,MAAM,OAAO,CAAA;AAG9C,YAAY,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAA;AAE9C;;GAEG;AACH,MAAM,MAAM,MAAM,GAAG,IAAI,GAAG,OAAO,CAAA;AAEnC;;GAEG;AACH,MAAM,MAAM,MAAM,GAAG,IAAI,CAAA;AAEzB;;GAEG;AACH,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,SAAS,GAAG,MAAM,IAAI,CAClD,IAAI,EAAE,CAAC,EACP,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,MAAM,EAAE,MAAM,GAAG,SAAS,KACvB,IAAI,GAAG,OAAO,CAAA;AAEnB;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE,QAAQ,CAAA;IACf,GAAG,EAAE,QAAQ,CAAA;CACd;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI,IAAI,MAAM,CAExD;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI,IAAI,OAAO,CAE1D;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,EACzC,IAAI,EAAE,SAAS,EACf,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,GACd,IAAI,IAAI,CAAC,CAEX"}
@@ -1,27 +0,0 @@
1
- import type { FC, CSSProperties } from 'react';
2
- import type { Root } from 'mdast';
3
- import { type ParserOptions } from 'pd-markdown-parser';
4
- import type { ComponentMap } from './defaults';
5
- export interface MarkdownRendererProps {
6
- /** Markdown source string (will be parsed) */
7
- source?: string;
8
- /** Pre-parsed AST (skip parsing, useful for SSR) */
9
- ast?: Root;
10
- /** Custom component overrides */
11
- components?: Partial<ComponentMap>;
12
- /** CSS class name for wrapper */
13
- className?: string;
14
- /** Inline styles for wrapper */
15
- style?: CSSProperties;
16
- /** Parser options (only used when source is provided) */
17
- parserOptions?: ParserOptions;
18
- }
19
- /**
20
- * Main markdown renderer component
21
- *
22
- * Supports both client-side and server-side rendering:
23
- * - Pass `source` for automatic parsing
24
- * - Pass `ast` for pre-parsed content (SSR optimization)
25
- */
26
- export declare const MarkdownRenderer: FC<MarkdownRendererProps>;
27
- //# sourceMappingURL=MarkdownRenderer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MarkdownRenderer.d.ts","sourceRoot":"","sources":["../../src/components/MarkdownRenderer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAC9C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,EAAgB,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAGrE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAE9C,MAAM,WAAW,qBAAqB;IACpC,8CAA8C;IAC9C,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,oDAAoD;IACpD,GAAG,CAAC,EAAE,IAAI,CAAA;IACV,iCAAiC;IACjC,UAAU,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,CAAA;IAClC,iCAAiC;IACjC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,gCAAgC;IAChC,KAAK,CAAC,EAAE,aAAa,CAAA;IACrB,yDAAyD;IACzD,aAAa,CAAC,EAAE,aAAa,CAAA;CAC9B;AAeD;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,EAAE,EAAE,CAAC,qBAAqB,CA2BtD,CAAA"}
@@ -1,10 +0,0 @@
1
- import type { FC } from 'react';
2
- import type { Content, Root } from 'mdast';
3
- export interface NodeRendererProps {
4
- node: Content | Root;
5
- }
6
- /**
7
- * Recursive node renderer that renders AST nodes to React elements
8
- */
9
- export declare const NodeRenderer: FC<NodeRendererProps>;
10
- //# sourceMappingURL=NodeRenderer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"NodeRenderer.d.ts","sourceRoot":"","sources":["../../src/components/NodeRenderer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAa,MAAM,OAAO,CAAA;AAC1C,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAA2B,MAAM,OAAO,CAAA;AAInE,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,OAAO,GAAG,IAAI,CAAA;CACrB;AAED;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,EAAE,CAAC,iBAAiB,CAgM9C,CAAA"}