ironmark 1.11.3 → 1.12.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.
- package/README.md +99 -0
- package/package.json +1 -1
- package/wasm/index.d.ts +66 -0
- package/wasm/node.js +12 -2
- package/wasm/pkg/ironmark.d.ts +35 -0
- package/wasm/pkg/ironmark.js +1 -1
- package/wasm/pkg/ironmark_bg.js +110 -0
- package/wasm/pkg/ironmark_bg.wasm +0 -0
- package/wasm/pkg/ironmark_bg.wasm.d.ts +3 -0
- package/wasm/shared.js +18 -0
- package/wasm/web.js +11 -1
package/README.md
CHANGED
|
@@ -84,6 +84,42 @@ const ast = JSON.parse(astJson);
|
|
|
84
84
|
|
|
85
85
|
`parseToAst()` returns a JSON string for portability across JS runtimes and WASM boundaries.
|
|
86
86
|
|
|
87
|
+
### HTML to Markdown
|
|
88
|
+
|
|
89
|
+
Convert HTML back to Markdown syntax using `htmlToMarkdown()`. Useful for importing content from HTML sources or round-trip conversion.
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
import { htmlToMarkdown } from "ironmark";
|
|
93
|
+
|
|
94
|
+
const md = htmlToMarkdown("<h1>Hello</h1><p><strong>Bold</strong> text</p>");
|
|
95
|
+
// Returns: "# Hello\n\n**Bold** text"
|
|
96
|
+
|
|
97
|
+
// Preserve unknown HTML tags (e.g., <sup>, <sub>) as raw HTML in output
|
|
98
|
+
const md = htmlToMarkdown("<p>H<sub>2</sub>O</p>", true);
|
|
99
|
+
// Returns: "H<sub>2</sub>O"
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
For AST access, use `parseHtmlToAst()`:
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
import { parseHtmlToAst } from "ironmark";
|
|
106
|
+
|
|
107
|
+
const astJson = parseHtmlToAst("<h1>Hello</h1><p>World</p>");
|
|
108
|
+
const ast = JSON.parse(astJson);
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### AST to Markdown
|
|
112
|
+
|
|
113
|
+
Render an AST back to Markdown syntax using `renderMarkdown()`. Combined with `parseToAst()` or `parseHtmlToAst()`, this enables round-trip conversion.
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
import { parseToAst, renderMarkdown } from "ironmark";
|
|
117
|
+
|
|
118
|
+
const ast = parseToAst("# Hello\n\n**World**");
|
|
119
|
+
const md = renderMarkdown(ast);
|
|
120
|
+
// Returns: "# Hello\n\n**World**"
|
|
121
|
+
```
|
|
122
|
+
|
|
87
123
|
### ANSI Terminal Output
|
|
88
124
|
|
|
89
125
|
Use `renderAnsi()` to render Markdown as coloured terminal output (ANSI 256-colour escape codes). Useful for CLI tools, terminal UIs, or any environment with a TTY.
|
|
@@ -264,6 +300,69 @@ Exported AST types:
|
|
|
264
300
|
- `TableData`
|
|
265
301
|
- `TableAlignment`
|
|
266
302
|
|
|
303
|
+
### HTML to Markdown
|
|
304
|
+
|
|
305
|
+
Convert HTML back to Markdown syntax:
|
|
306
|
+
|
|
307
|
+
```rust
|
|
308
|
+
use ironmark::{html_to_markdown, HtmlParseOptions};
|
|
309
|
+
|
|
310
|
+
fn main() {
|
|
311
|
+
let md = html_to_markdown(
|
|
312
|
+
"<h1>Hello</h1><p><strong>Bold</strong> text</p>",
|
|
313
|
+
&HtmlParseOptions::default(),
|
|
314
|
+
);
|
|
315
|
+
// Returns: "# Hello\n\n**Bold** text"
|
|
316
|
+
}
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
For AST access, use `parse_html_to_ast()`:
|
|
320
|
+
|
|
321
|
+
```rust
|
|
322
|
+
use ironmark::{parse_html_to_ast, HtmlParseOptions, UnknownInlineHandling};
|
|
323
|
+
|
|
324
|
+
fn main() {
|
|
325
|
+
// Default: strip unknown tags, keep text content
|
|
326
|
+
let ast = parse_html_to_ast("<p>H<sub>2</sub>O</p>", &HtmlParseOptions::default());
|
|
327
|
+
|
|
328
|
+
// Preserve unknown tags as raw HTML
|
|
329
|
+
let ast = parse_html_to_ast(
|
|
330
|
+
"<p>H<sub>2</sub>O</p>",
|
|
331
|
+
&HtmlParseOptions {
|
|
332
|
+
unknown_inline_handling: UnknownInlineHandling::PreserveAsHtml,
|
|
333
|
+
..Default::default()
|
|
334
|
+
},
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
`HtmlParseOptions` fields:
|
|
340
|
+
|
|
341
|
+
| Field | Type | Default | Description |
|
|
342
|
+
| ------------------------- | ----------------------- | ----------- | ------------------------------------- |
|
|
343
|
+
| `max_nesting_depth` | `usize` | `128` | Limit nesting depth (DoS prevention) |
|
|
344
|
+
| `unknown_inline_handling` | `UnknownInlineHandling` | `StripTags` | How to handle unknown HTML tags |
|
|
345
|
+
| `max_input_size` | `usize` | `0` | Truncate input beyond this byte count |
|
|
346
|
+
|
|
347
|
+
`UnknownInlineHandling` variants:
|
|
348
|
+
|
|
349
|
+
- `StripTags` — Remove unknown tags, keep text content (default)
|
|
350
|
+
- `PreserveAsHtml` — Keep unknown tags as raw HTML in output
|
|
351
|
+
|
|
352
|
+
### AST to Markdown
|
|
353
|
+
|
|
354
|
+
Render an AST back to Markdown syntax:
|
|
355
|
+
|
|
356
|
+
```rust
|
|
357
|
+
use ironmark::{parse_to_ast, render_markdown, ParseOptions};
|
|
358
|
+
|
|
359
|
+
fn main() {
|
|
360
|
+
let ast = parse_to_ast("# Hello\n\n**World**", &ParseOptions::default());
|
|
361
|
+
let md = render_markdown(&ast);
|
|
362
|
+
// Returns: "# Hello\n\n**World**"
|
|
363
|
+
}
|
|
364
|
+
```
|
|
365
|
+
|
|
267
366
|
### ANSI Terminal Output
|
|
268
367
|
|
|
269
368
|
`render_ansi()` renders Markdown as ANSI-coloured terminal output. Pass `Some(&AnsiOptions { .. })` to control width, colour, and line numbers, or `None` for defaults.
|
package/package.json
CHANGED
package/wasm/index.d.ts
CHANGED
|
@@ -118,3 +118,69 @@ export declare function renderAnsi(
|
|
|
118
118
|
options?: ParseOptions,
|
|
119
119
|
ansiOptions?: AnsiOptions,
|
|
120
120
|
): string;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Options for HTML-to-Markdown parsing.
|
|
124
|
+
*/
|
|
125
|
+
export interface HtmlParseOptions {
|
|
126
|
+
/**
|
|
127
|
+
* If true, unknown HTML tags (like `<sup>`, `<sub>`, `<abbr>`) are preserved
|
|
128
|
+
* as raw HTML in the Markdown output. If false (default), unknown tags are
|
|
129
|
+
* stripped but their text content is kept.
|
|
130
|
+
*/
|
|
131
|
+
preserveUnknownAsHtml?: boolean;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Parse an HTML string and return the AST as a JSON string.
|
|
136
|
+
*
|
|
137
|
+
* This converts HTML back into the same AST structure used by the Markdown parser,
|
|
138
|
+
* enabling HTML-to-Markdown conversion.
|
|
139
|
+
*
|
|
140
|
+
* @param html - HTML source string.
|
|
141
|
+
* @param preserveUnknownAsHtml - If true, unknown HTML tags are preserved as raw HTML.
|
|
142
|
+
* @returns JSON string representing the AST.
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```ts
|
|
146
|
+
* import { parseHtmlToAst } from "ironmark";
|
|
147
|
+
* const ast = parseHtmlToAst("<h1>Hello</h1><p>World</p>");
|
|
148
|
+
* console.log(JSON.parse(ast));
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
export declare function parseHtmlToAst(html: string, preserveUnknownAsHtml?: boolean): string;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Convert HTML to Markdown.
|
|
155
|
+
*
|
|
156
|
+
* This parses HTML and renders it as Markdown syntax.
|
|
157
|
+
*
|
|
158
|
+
* @param html - HTML source string.
|
|
159
|
+
* @param preserveUnknownAsHtml - If true, unknown HTML tags are preserved as raw HTML in output.
|
|
160
|
+
* @returns Markdown string.
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```ts
|
|
164
|
+
* import { htmlToMarkdown } from "ironmark";
|
|
165
|
+
* const md = htmlToMarkdown("<p><strong>Bold</strong> text</p>");
|
|
166
|
+
* // Returns: "**Bold** text"
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
export declare function htmlToMarkdown(html: string, preserveUnknownAsHtml?: boolean): string;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Render an AST (as JSON) to Markdown.
|
|
173
|
+
*
|
|
174
|
+
* This takes a JSON string representing an ironmark AST and renders it as Markdown.
|
|
175
|
+
*
|
|
176
|
+
* @param astJson - JSON string representing the AST (as returned by `parseToAst` or `parseHtmlToAst`).
|
|
177
|
+
* @returns Markdown string.
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```ts
|
|
181
|
+
* import { parseToAst, renderMarkdown } from "ironmark";
|
|
182
|
+
* const ast = parseToAst("# Hello\n\n**World**");
|
|
183
|
+
* const md = renderMarkdown(ast);
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
export declare function renderMarkdown(astJson: string): string;
|