@changerawr/markdown 1.0.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.
@@ -0,0 +1,264 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import React, { ReactNode } from 'react';
3
+
4
+ interface MarkdownToken {
5
+ type: string;
6
+ content: string;
7
+ raw: string;
8
+ attributes?: Record<string, string>;
9
+ }
10
+ interface ParseRule {
11
+ name: string;
12
+ pattern: RegExp;
13
+ render: (match: RegExpMatchArray) => MarkdownToken;
14
+ }
15
+ interface RenderRule {
16
+ type: string;
17
+ render: (token: MarkdownToken) => string;
18
+ }
19
+ interface Extension {
20
+ name: string;
21
+ parseRules: ParseRule[];
22
+ renderRules: RenderRule[];
23
+ }
24
+ type OutputFormat = 'html' | 'tailwind' | 'json';
25
+ interface RendererConfig {
26
+ format: OutputFormat;
27
+ sanitize?: boolean;
28
+ allowUnsafeHtml?: boolean;
29
+ customClasses?: Record<string, string>;
30
+ debugMode?: boolean;
31
+ }
32
+ interface ParserConfig {
33
+ debugMode?: boolean;
34
+ maxIterations?: number;
35
+ validateMarkdown?: boolean;
36
+ }
37
+ interface EngineConfig {
38
+ parser?: ParserConfig;
39
+ renderer?: RendererConfig;
40
+ extensions?: Extension[];
41
+ }
42
+ interface DebugInfo {
43
+ warnings: string[];
44
+ parseTime: number;
45
+ renderTime: number;
46
+ tokenCount: number;
47
+ iterationCount: number;
48
+ }
49
+ interface PerformanceMetrics {
50
+ parseTime: number;
51
+ renderTime: number;
52
+ totalTime: number;
53
+ tokenCount: number;
54
+ memoryUsed?: number;
55
+ }
56
+ interface ExtensionRegistration {
57
+ success: boolean;
58
+ extensionName: string;
59
+ error?: string;
60
+ conflictingRules?: string[];
61
+ }
62
+
63
+ /**
64
+ * Props for the MarkdownRenderer component
65
+ */
66
+ interface MarkdownRendererProps {
67
+ /** Markdown content to render */
68
+ content: string;
69
+ /** Additional CSS classes to apply to the wrapper */
70
+ className?: string;
71
+ /** Engine configuration */
72
+ config?: EngineConfig;
73
+ /** Output format (defaults to 'tailwind') */
74
+ format?: OutputFormat;
75
+ /** Custom wrapper element (defaults to 'div') */
76
+ as?: keyof JSX.IntrinsicElements;
77
+ /** Additional HTML attributes for the wrapper */
78
+ wrapperProps?: React.HTMLAttributes<HTMLElement>;
79
+ /** Enable debug mode */
80
+ debug?: boolean;
81
+ /** Custom error fallback component */
82
+ errorFallback?: (error: Error) => ReactNode;
83
+ /** Loading component while processing */
84
+ loading?: ReactNode;
85
+ /** Callback when rendering completes */
86
+ onRender?: (html: string, tokens: MarkdownToken[]) => void;
87
+ /** Callback when an error occurs */
88
+ onError?: (error: Error) => void;
89
+ /** Custom extensions to register */
90
+ extensions?: Extension[];
91
+ /** Whether to sanitize HTML output */
92
+ sanitize?: boolean;
93
+ /** Allow unsafe HTML (use with caution) */
94
+ allowUnsafeHtml?: boolean;
95
+ }
96
+ /**
97
+ * Options for useMarkdown hook
98
+ */
99
+ interface UseMarkdownOptions {
100
+ /** Engine configuration */
101
+ config?: EngineConfig;
102
+ /** Output format */
103
+ format?: OutputFormat;
104
+ /** Enable debug mode */
105
+ debug?: boolean;
106
+ /** Custom extensions */
107
+ extensions?: Extension[];
108
+ /** Debounce delay in milliseconds */
109
+ debounceMs?: number;
110
+ /** Whether to memoize results */
111
+ memoize?: boolean;
112
+ }
113
+ /**
114
+ * Return type for useMarkdown hook
115
+ */
116
+ interface UseMarkdownResult {
117
+ /** Rendered HTML */
118
+ html: string;
119
+ /** Parsed tokens */
120
+ tokens: MarkdownToken[];
121
+ /** Loading state */
122
+ isLoading: boolean;
123
+ /** Error state */
124
+ error: Error | null;
125
+ /** Debug information */
126
+ debug: MarkdownDebugInfo | null;
127
+ /** Re-render with new content */
128
+ render: (content: string) => void;
129
+ /** Clear current state */
130
+ clear: () => void;
131
+ }
132
+ /**
133
+ * Options for useMarkdownEngine hook
134
+ */
135
+ interface MarkdownEngineHookOptions {
136
+ /** Initial engine configuration */
137
+ config?: EngineConfig;
138
+ /** Auto-register built-in extensions */
139
+ autoRegisterExtensions?: boolean;
140
+ }
141
+ /**
142
+ * Debug information for React components - extends the core DebugInfo
143
+ */
144
+ interface MarkdownDebugInfo {
145
+ /** Core debug info from engine */
146
+ core: DebugInfo | null;
147
+ /** Performance metrics */
148
+ performance: PerformanceMetrics | null;
149
+ /** Render timestamp */
150
+ renderedAt: Date;
151
+ /** Input content length */
152
+ contentLength: number;
153
+ /** Output HTML length */
154
+ htmlLength: number;
155
+ /** Extensions used */
156
+ extensionsUsed: string[];
157
+ }
158
+
159
+ /**
160
+ * MarkdownRenderer - Main React component for rendering markdown
161
+ *
162
+ * @example
163
+ * ```tsx
164
+ * <MarkdownRenderer
165
+ * content="# Hello **World**!"
166
+ * className="prose"
167
+ * />
168
+ * ```
169
+ */
170
+ declare function MarkdownRenderer({ content, className, config, format, as: Component, wrapperProps, debug, errorFallback, loading, onRender, onError, extensions, sanitize, allowUnsafeHtml, ...restProps }: MarkdownRendererProps): react_jsx_runtime.JSX.Element;
171
+ declare namespace MarkdownRenderer {
172
+ var displayName: string;
173
+ }
174
+
175
+ declare class ChangerawrMarkdown {
176
+ private parser;
177
+ private renderer;
178
+ private extensions;
179
+ constructor(config?: EngineConfig);
180
+ /**
181
+ * Register a custom extension
182
+ */
183
+ registerExtension(extension: Extension): ExtensionRegistration;
184
+ /**
185
+ * Unregister an extension
186
+ */
187
+ unregisterExtension(name: string): boolean;
188
+ /**
189
+ * Parse markdown content into tokens
190
+ */
191
+ parse(markdown: string): MarkdownToken[];
192
+ /**
193
+ * Render tokens to HTML
194
+ */
195
+ render(tokens: MarkdownToken[]): string;
196
+ /**
197
+ * Parse and render markdown to HTML in one step
198
+ */
199
+ toHtml(markdown: string): string;
200
+ /**
201
+ * Get list of registered extensions
202
+ */
203
+ getExtensions(): string[];
204
+ /**
205
+ * Check if extension is registered
206
+ */
207
+ hasExtension(name: string): boolean;
208
+ /**
209
+ * Get parser warnings
210
+ */
211
+ getWarnings(): string[];
212
+ /**
213
+ * Get debug information from last render
214
+ */
215
+ getDebugInfo(): DebugInfo | null;
216
+ /**
217
+ * Get performance metrics for the last operation
218
+ */
219
+ getPerformanceMetrics(): PerformanceMetrics | null;
220
+ /**
221
+ * Register built-in extensions
222
+ */
223
+ private registerBuiltInExtensions;
224
+ /**
225
+ * Rebuild parser and renderer with current extensions
226
+ */
227
+ private rebuildParserAndRenderer;
228
+ }
229
+
230
+ /**
231
+ * Main hook for rendering markdown content
232
+ */
233
+ declare function useMarkdown(initialContent?: string, options?: UseMarkdownOptions): UseMarkdownResult;
234
+ /**
235
+ * Hook for managing a markdown engine instance
236
+ */
237
+ declare function useMarkdownEngine(options?: MarkdownEngineHookOptions): {
238
+ engine: ChangerawrMarkdown;
239
+ toHtml: (content: string) => string;
240
+ parse: (content: string) => MarkdownToken[];
241
+ render: (tokens: MarkdownToken[]) => string;
242
+ getExtensions: () => string[];
243
+ hasExtension: (name: string) => boolean;
244
+ registerExtension: (extension: Parameters<ChangerawrMarkdown["registerExtension"]>[0]) => ExtensionRegistration;
245
+ unregisterExtension: (name: string) => boolean;
246
+ getWarnings: () => string[];
247
+ getDebugInfo: () => DebugInfo | null;
248
+ getPerformanceMetrics: () => PerformanceMetrics | null;
249
+ };
250
+ /**
251
+ * Debug hook for markdown processing
252
+ */
253
+ declare function useMarkdownDebug(content: string): {
254
+ html: string;
255
+ tokens: MarkdownToken[];
256
+ debug: MarkdownDebugInfo | null;
257
+ stats: {
258
+ tokenCount: number;
259
+ htmlLength: number;
260
+ contentLength: number;
261
+ };
262
+ };
263
+
264
+ export { type EngineConfig, type Extension, type MarkdownDebugInfo, type MarkdownEngineHookOptions, MarkdownRenderer, type MarkdownRendererProps, type MarkdownToken, type OutputFormat, type UseMarkdownOptions, type UseMarkdownResult, useMarkdown, useMarkdownDebug, useMarkdownEngine };