@f-o-t/markdown 1.0.2 → 1.0.6
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/LICENSE +21 -0
- package/dist/block-parser.d.ts +66 -0
- package/dist/block-parser.d.ts.map +1 -0
- package/dist/generator.d.ts +222 -0
- package/dist/generator.d.ts.map +1 -0
- package/dist/html-parser.d.ts +62 -0
- package/dist/html-parser.d.ts.map +1 -0
- package/dist/html-renderer.d.ts +47 -0
- package/dist/html-renderer.d.ts.map +1 -0
- package/dist/index.d.ts +12 -780
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -21
- package/dist/index.js.map +18 -0
- package/dist/inline-parser.d.ts +13 -0
- package/dist/inline-parser.d.ts.map +1 -0
- package/dist/parser.d.ts +185 -0
- package/dist/parser.d.ts.map +1 -0
- package/dist/schemas.d.ts +936 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/stream.d.ts +71 -0
- package/dist/stream.d.ts.map +1 -0
- package/dist/types.d.ts +188 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils.d.ts +268 -0
- package/dist/utils.d.ts.map +1 -0
- package/package.json +23 -49
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 FOT (F-O-T)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { BlockNode } from "./schemas";
|
|
2
|
+
import type { BlockContext } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Creates a new block parsing context.
|
|
5
|
+
*/
|
|
6
|
+
export declare function createBlockContext(): BlockContext;
|
|
7
|
+
/**
|
|
8
|
+
* Checks if a line starts a thematic break.
|
|
9
|
+
*/
|
|
10
|
+
export declare function isThematicBreak(line: string): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Checks if a line starts an ATX heading.
|
|
13
|
+
*/
|
|
14
|
+
export declare function isAtxHeading(line: string): RegExpExecArray | null;
|
|
15
|
+
/**
|
|
16
|
+
* Checks if a line is a setext heading underline.
|
|
17
|
+
*/
|
|
18
|
+
export declare function isSetextUnderline(line: string): RegExpExecArray | null;
|
|
19
|
+
/**
|
|
20
|
+
* Checks if a line starts a fenced code block.
|
|
21
|
+
*/
|
|
22
|
+
export declare function isFencedCodeStart(line: string): RegExpExecArray | null;
|
|
23
|
+
/**
|
|
24
|
+
* Checks if a line starts an indented code block.
|
|
25
|
+
*/
|
|
26
|
+
export declare function isIndentedCode(line: string, context: BlockContext): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Checks if a line starts a blockquote.
|
|
29
|
+
*/
|
|
30
|
+
export declare function isBlockquoteStart(line: string): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Checks if a line starts a list item.
|
|
33
|
+
*/
|
|
34
|
+
export declare function isListItemStart(line: string): {
|
|
35
|
+
ordered: boolean;
|
|
36
|
+
marker: string;
|
|
37
|
+
start?: number;
|
|
38
|
+
indent: number;
|
|
39
|
+
} | null;
|
|
40
|
+
/**
|
|
41
|
+
* Checks if a line is a link reference definition.
|
|
42
|
+
*/
|
|
43
|
+
export declare function isLinkReferenceDefinition(line: string): {
|
|
44
|
+
label: string;
|
|
45
|
+
url: string;
|
|
46
|
+
title?: string;
|
|
47
|
+
} | null;
|
|
48
|
+
/**
|
|
49
|
+
* Checks if a line looks like a table row (contains pipes).
|
|
50
|
+
*/
|
|
51
|
+
export declare function isTableRow(line: string): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Checks if a line is a table delimiter row.
|
|
54
|
+
*/
|
|
55
|
+
export declare function isTableDelimiter(line: string): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Parses all blocks from content.
|
|
58
|
+
*/
|
|
59
|
+
export declare function parseBlocks(content: string, context?: BlockContext, includePositions?: boolean, depth?: number): {
|
|
60
|
+
blocks: BlockNode[];
|
|
61
|
+
references: Map<string, {
|
|
62
|
+
url: string;
|
|
63
|
+
title?: string;
|
|
64
|
+
}>;
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=block-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block-parser.d.ts","sourceRoot":"","sources":["../src/block-parser.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACT,SAAS,EAaX,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,EAAE,YAAY,EAAY,MAAM,SAAS,CAAC;AAsBtD;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,YAAY,CAWjD;AAyBD;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAErD;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC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AE,CAAC,CAAC;CAC3D,CAyBA"}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import type { DocumentNode, GenerateOptions, MarkdownDocument, Node } from "./schemas";
|
|
2
|
+
/**
|
|
3
|
+
* Generates markdown string from a document AST.
|
|
4
|
+
*
|
|
5
|
+
* @param document - The markdown document or root node to convert
|
|
6
|
+
* @param options - Generation options
|
|
7
|
+
* @returns The generated markdown string
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const doc = parse("# Hello");
|
|
12
|
+
* const markdown = generate(doc);
|
|
13
|
+
* console.log(markdown); // "# Hello"
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare function generate(document: MarkdownDocument | DocumentNode, options?: GenerateOptions): string;
|
|
17
|
+
/**
|
|
18
|
+
* Generates markdown string from any AST node.
|
|
19
|
+
*
|
|
20
|
+
* @param node - The node to convert
|
|
21
|
+
* @param options - Generation options
|
|
22
|
+
* @returns The generated markdown string
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const node: HeadingNode = { type: "heading", level: 1, children: [...], style: "atx" };
|
|
27
|
+
* const markdown = generateNode(node);
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function generateNode(node: Node, options?: GenerateOptions): string;
|
|
31
|
+
/**
|
|
32
|
+
* Creates an incremental markdown generator.
|
|
33
|
+
*
|
|
34
|
+
* @param options - Generation options
|
|
35
|
+
* @returns A generator object with methods to add nodes
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* const gen = createGenerator();
|
|
40
|
+
* gen.addNode({ type: "heading", level: 1, children: [...], style: "atx" });
|
|
41
|
+
* gen.addNode({ type: "paragraph", children: [...] });
|
|
42
|
+
* console.log(gen.toString());
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare function createGenerator(options?: GenerateOptions): {
|
|
46
|
+
addNode: (node: Node) => void;
|
|
47
|
+
toString: () => string;
|
|
48
|
+
toStream: () => ReadableStream<string>;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Generates a heading string.
|
|
52
|
+
*
|
|
53
|
+
* @param level - Heading level (1-6)
|
|
54
|
+
* @param text - Heading text
|
|
55
|
+
* @param style - Heading style (atx or setext)
|
|
56
|
+
* @returns The generated heading
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* generateHeadingString(1, "Hello"); // "# Hello"
|
|
61
|
+
* generateHeadingString(2, "World", "setext"); // "World\n------"
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare function generateHeadingString(level: 1 | 2 | 3 | 4 | 5 | 6, text: string, style?: "atx" | "setext"): string;
|
|
65
|
+
/**
|
|
66
|
+
* Generates a link string.
|
|
67
|
+
*
|
|
68
|
+
* @param text - Link text
|
|
69
|
+
* @param url - Link URL
|
|
70
|
+
* @param title - Optional link title
|
|
71
|
+
* @returns The generated link
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* generateLinkString("Example", "https://example.com"); // "[Example](https://example.com)"
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export declare function generateLinkString(text: string, url: string, title?: string): string;
|
|
79
|
+
/**
|
|
80
|
+
* Generates an image string.
|
|
81
|
+
*
|
|
82
|
+
* @param alt - Alt text
|
|
83
|
+
* @param url - Image URL
|
|
84
|
+
* @param title - Optional image title
|
|
85
|
+
* @returns The generated image
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* generateImageString("Logo", "logo.png"); // ""
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export declare function generateImageString(alt: string, url: string, title?: string): string;
|
|
93
|
+
/**
|
|
94
|
+
* Generates a code block string.
|
|
95
|
+
*
|
|
96
|
+
* @param code - The code content
|
|
97
|
+
* @param lang - Optional language identifier
|
|
98
|
+
* @param style - Code block style (fenced or indented)
|
|
99
|
+
* @returns The generated code block
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* generateCodeBlockString("console.log('hi');", "js");
|
|
104
|
+
* // "```js\nconsole.log('hi');\n```"
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
export declare function generateCodeBlockString(code: string, lang?: string, style?: "fenced" | "indented"): string;
|
|
108
|
+
/**
|
|
109
|
+
* Generates a list string from items.
|
|
110
|
+
*
|
|
111
|
+
* @param items - List items (strings or nested lists)
|
|
112
|
+
* @param ordered - Whether the list is ordered
|
|
113
|
+
* @param start - Starting number for ordered lists
|
|
114
|
+
* @returns The generated list
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* generateListString(["First", "Second"]); // "- First\n- Second"
|
|
119
|
+
* generateListString(["First", "Second"], true); // "1. First\n2. Second"
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
export declare function generateListString(items: string[], ordered?: boolean, start?: number): string;
|
|
123
|
+
/**
|
|
124
|
+
* Generates a blockquote string.
|
|
125
|
+
*
|
|
126
|
+
* @param content - The content to quote
|
|
127
|
+
* @returns The generated blockquote
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```typescript
|
|
131
|
+
* generateBlockquoteString("Hello world"); // "> Hello world"
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
export declare function generateBlockquoteString(content: string): string;
|
|
135
|
+
/**
|
|
136
|
+
* Wraps text with emphasis markers.
|
|
137
|
+
*
|
|
138
|
+
* @param text - The text to emphasize
|
|
139
|
+
* @param marker - The emphasis marker (* or _)
|
|
140
|
+
* @returns The emphasized text
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```typescript
|
|
144
|
+
* generateEmphasisString("hello"); // "*hello*"
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
export declare function generateEmphasisString(text: string, marker?: "*" | "_"): string;
|
|
148
|
+
/**
|
|
149
|
+
* Wraps text with strong emphasis markers.
|
|
150
|
+
*
|
|
151
|
+
* @param text - The text to emphasize
|
|
152
|
+
* @param marker - The strong marker (** or __)
|
|
153
|
+
* @returns The strongly emphasized text
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* generateStrongString("hello"); // "**hello**"
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
export declare function generateStrongString(text: string, marker?: "**" | "__"): string;
|
|
161
|
+
/**
|
|
162
|
+
* Wraps text in inline code.
|
|
163
|
+
*
|
|
164
|
+
* @param text - The text to wrap
|
|
165
|
+
* @returns The inline code
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```typescript
|
|
169
|
+
* generateInlineCodeString("foo"); // "`foo`"
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
export declare function generateInlineCodeString(text: string): string;
|
|
173
|
+
/**
|
|
174
|
+
* Generates a GFM table string from headers, rows, and optional alignment.
|
|
175
|
+
*
|
|
176
|
+
* @param headers - Array of column header strings
|
|
177
|
+
* @param rows - 2D array of cell values
|
|
178
|
+
* @param alignments - Optional array of alignment values ('left' | 'center' | 'right')
|
|
179
|
+
* @returns The generated table markdown
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```typescript
|
|
183
|
+
* generateTableString(
|
|
184
|
+
* ["Name", "Age"],
|
|
185
|
+
* [["Alice", "30"], ["Bob", "25"]]
|
|
186
|
+
* );
|
|
187
|
+
* // "| Name | Age |\n| --- | --- |\n| Alice | 30 |\n| Bob | 25 |"
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
export declare function generateTableString(headers: string[], rows: string[][], alignments?: ("left" | "center" | "right" | null)[]): string;
|
|
191
|
+
/**
|
|
192
|
+
* Generates a task list (checklist) string.
|
|
193
|
+
*
|
|
194
|
+
* @param items - Array of items with text and optional checked state
|
|
195
|
+
* @returns The generated task list markdown
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```typescript
|
|
199
|
+
* generateTaskListString([
|
|
200
|
+
* { text: "Buy groceries", checked: true },
|
|
201
|
+
* { text: "Walk the dog", checked: false },
|
|
202
|
+
* ]);
|
|
203
|
+
* // "- [x] Buy groceries\n- [ ] Walk the dog"
|
|
204
|
+
* ```
|
|
205
|
+
*/
|
|
206
|
+
export declare function generateTaskListString(items: Array<{
|
|
207
|
+
text: string;
|
|
208
|
+
checked?: boolean;
|
|
209
|
+
}>): string;
|
|
210
|
+
/**
|
|
211
|
+
* Wraps text with strikethrough markers (GFM extension).
|
|
212
|
+
*
|
|
213
|
+
* @param text - The text to strike through
|
|
214
|
+
* @returns The strikethrough text
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
* ```typescript
|
|
218
|
+
* generateStrikethroughString("deleted"); // "~~deleted~~"
|
|
219
|
+
* ```
|
|
220
|
+
*/
|
|
221
|
+
export declare function generateStrikethroughString(text: string): string;
|
|
222
|
+
//# sourceMappingURL=generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIT,YAAY,EACZ,eAAe,EAMf,gBAAgB,EAChB,IAAI,EAMN,MAAM,WAAW,CAAC;AA0BnB;;;;;;;;;;;;;GAaG;AACH,wBAAgB,QAAQ,CACrB,QAAQ,EAAE,gBAAgB,GAAG,YAAY,EACzC,OAAO,CAAC,EAAE,eAAe,GACzB,MAAM,CAUR;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,MAAM,CAiB1E;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAAC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CACjC,IAAI,EAAE,MAAM,EACZ,MAAM,GAAE,IAAI,GAAG,IAAW,GAC1B,MAAM,CAER;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE7D;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,mBAAmB,CAChC,OAAO,EAAE,MAAM,EAAE,EACjB,IAAI,EAAE,MAAM,EAAE,EAAE,EAChB,UAAU,CAAC,EAAE,CAAC,MAAM,GAAG,QAAQ,GAAG,OAAO,GAAG,IAAI,CAAC,EAAE,GACnD,MAAM,CAuCR;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,sBAAsB,CACnC,KAAK,EAAE,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC,GACjD,MAAM,CAIR;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEhE"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTML to Markdown Parser
|
|
3
|
+
*
|
|
4
|
+
* Converts HTML content to Markdown format using a lightweight state machine parser.
|
|
5
|
+
* Supports all common HTML elements including headings, paragraphs, lists, tables,
|
|
6
|
+
* code blocks, links, images, and inline formatting.
|
|
7
|
+
*/
|
|
8
|
+
import type { DocumentNode } from "./schemas";
|
|
9
|
+
/**
|
|
10
|
+
* Options for HTML to Markdown conversion
|
|
11
|
+
*/
|
|
12
|
+
export interface HtmlToMarkdownOptions {
|
|
13
|
+
/** Keep original whitespace (default: false) */
|
|
14
|
+
preserveWhitespace?: boolean;
|
|
15
|
+
/** Heading style: "atx" (#) or "setext" (===) (default: "atx") */
|
|
16
|
+
headingStyle?: "atx" | "setext";
|
|
17
|
+
/** Unordered list marker (default: "-") */
|
|
18
|
+
bulletMarker?: "-" | "*" | "+";
|
|
19
|
+
/** Code block style (default: "fenced") */
|
|
20
|
+
codeBlockStyle?: "fenced" | "indented";
|
|
21
|
+
/** Fence character (default: "`") */
|
|
22
|
+
fence?: "`" | "~";
|
|
23
|
+
/** Strong marker (default: "**") */
|
|
24
|
+
strongMarker?: "**" | "__";
|
|
25
|
+
/** Emphasis marker (default: "*") */
|
|
26
|
+
emphasisMarker?: "*" | "_";
|
|
27
|
+
/** Link style (default: "inline") */
|
|
28
|
+
linkStyle?: "inline" | "reference";
|
|
29
|
+
}
|
|
30
|
+
/** Intermediate HTML node representation */
|
|
31
|
+
interface HtmlNode {
|
|
32
|
+
type: "element" | "text" | "comment";
|
|
33
|
+
tag?: string;
|
|
34
|
+
attributes?: Record<string, string>;
|
|
35
|
+
children?: HtmlNode[];
|
|
36
|
+
content?: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Parse HTML string into an intermediate AST
|
|
40
|
+
*/
|
|
41
|
+
export declare function parseHtml(html: string): HtmlNode[];
|
|
42
|
+
/**
|
|
43
|
+
* Convert HTML AST to Markdown AST
|
|
44
|
+
*/
|
|
45
|
+
export declare function htmlAstToMarkdownAst(nodes: HtmlNode[], options?: HtmlToMarkdownOptions): DocumentNode;
|
|
46
|
+
/**
|
|
47
|
+
* Convert HTML string to Markdown string
|
|
48
|
+
*
|
|
49
|
+
* @param html - The HTML content to convert
|
|
50
|
+
* @param options - Conversion options
|
|
51
|
+
* @returns Markdown string
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* const html = '<h1>Hello</h1><p>This is <strong>bold</strong> text.</p>';
|
|
56
|
+
* const markdown = htmlToMarkdown(html);
|
|
57
|
+
* // Result: "# Hello\n\nThis is **bold** text."
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare function htmlToMarkdown(html: string, options?: HtmlToMarkdownOptions): string;
|
|
61
|
+
export {};
|
|
62
|
+
//# sourceMappingURL=html-parser.d.ts.map
|
|
@@ -0,0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,cAAc,CAC3B,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,qBAA0B,GACnC,MAAM,CA6BR"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { DocumentNode, MarkdownDocument, Node } from "./schemas";
|
|
2
|
+
/**
|
|
3
|
+
* Options for HTML rendering.
|
|
4
|
+
*/
|
|
5
|
+
export interface HtmlRenderOptions {
|
|
6
|
+
/** Whether to sanitize raw HTML blocks/inline (default: true) */
|
|
7
|
+
sanitizeHtml?: boolean;
|
|
8
|
+
/** Whether to add target="_blank" to external links (default: false) */
|
|
9
|
+
externalLinksNewTab?: boolean;
|
|
10
|
+
/** Custom class prefix for elements (default: none) */
|
|
11
|
+
classPrefix?: string;
|
|
12
|
+
/** Whether to render soft breaks as <br> (default: false) */
|
|
13
|
+
softBreakAsBr?: boolean;
|
|
14
|
+
/** Custom URL transformer for links and images */
|
|
15
|
+
transformUrl?: (url: string, type: "link" | "image") => string;
|
|
16
|
+
/** Custom attributes to add to specific elements */
|
|
17
|
+
elementAttributes?: {
|
|
18
|
+
link?: Record<string, string>;
|
|
19
|
+
image?: Record<string, string>;
|
|
20
|
+
codeBlock?: Record<string, string>;
|
|
21
|
+
heading?: Record<string, string>;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Renders a markdown document to HTML string.
|
|
26
|
+
*
|
|
27
|
+
* @param document - The markdown document or root node
|
|
28
|
+
* @param options - Rendering options
|
|
29
|
+
* @returns The generated HTML string
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* const doc = parse("# Hello **World**");
|
|
34
|
+
* const html = renderToHtml(doc);
|
|
35
|
+
* // => "<h1>Hello <strong>World</strong></h1>"
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function renderToHtml(document: MarkdownDocument | DocumentNode, options?: HtmlRenderOptions): string;
|
|
39
|
+
/**
|
|
40
|
+
* Renders any AST node to HTML string.
|
|
41
|
+
*
|
|
42
|
+
* @param node - The node to render
|
|
43
|
+
* @param options - Rendering options
|
|
44
|
+
* @returns The generated HTML string
|
|
45
|
+
*/
|
|
46
|
+
export declare function renderNodeToHtml(node: Node, options?: HtmlRenderOptions): string;
|
|
47
|
+
//# sourceMappingURL=html-renderer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html-renderer.d.ts","sourceRoot":"","sources":["../src/html-renderer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAKT,YAAY,EAUZ,gBAAgB,EAChB,IAAI,EAQN,MAAM,WAAW,CAAC;AAOnB;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAC/B,iEAAiE;IACjE,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,wEAAwE;IACxE,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,uDAAuD;IACvD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,6DAA6D;IAC7D,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,kDAAkD;IAClD,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,KAAK,MAAM,CAAC;IAC/D,oDAAoD;IACpD,iBAAiB,CAAC,EAAE;QACjB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC9B,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC/B,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACnC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KACnC,CAAC;CACJ;AAmBD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,CACzB,QAAQ,EAAE,gBAAgB,GAAG,YAAY,EACzC,OAAO,CAAC,EAAE,iBAAiB,GAC3B,MAAM,CAKR;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC7B,IAAI,EAAE,IAAI,EACV,OAAO,CAAC,EAAE,iBAAiB,GAC3B,MAAM,CAYR"}
|