ironmark 1.8.0 → 1.9.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 CHANGED
@@ -84,6 +84,37 @@ 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
+ ### ANSI Terminal Output
88
+
89
+ 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.
90
+
91
+ ````ts
92
+ import { renderAnsi } from "ironmark";
93
+
94
+ // Render with defaults (width 80, colour enabled)
95
+ const ansi = renderAnsi("# Hello\n\n**bold** and `code`");
96
+ process.stdout.write(ansi);
97
+
98
+ // Custom terminal width and line numbers in code blocks
99
+ const ansi = renderAnsi(
100
+ "# Hello\n\n```rust\nfn main() {}\n```",
101
+ {}, // parse options (same as parse())
102
+ { width: 120, lineNumbers: true },
103
+ );
104
+ process.stdout.write(ansi);
105
+
106
+ // Plain text — strips all ANSI codes (useful for piping to files)
107
+ const plain = renderAnsi("# Hello\n\n> quote", {}, { color: false });
108
+ ````
109
+
110
+ #### ANSI options
111
+
112
+ | Option | Type | Default | Description |
113
+ | ------------- | --------- | ------- | ------------------------------------------------------------------------------- |
114
+ | `width` | `number` | `80` | Column width for word-wrap, heading underlines, rule length. `0` = use default. |
115
+ | `color` | `boolean` | `true` | Emit ANSI colour codes. `false` = plain text output. |
116
+ | `lineNumbers` | `boolean` | `false` | Show line numbers in fenced code blocks. |
117
+
87
118
  ### Browser / Bundler
88
119
 
89
120
  Call `init()` once before using `parse()`. It's idempotent and optionally accepts a custom `.wasm` URL.
@@ -107,6 +138,46 @@ await init(wasmUrl);
107
138
  const html = parse("# Hello\n\nThis is **fast**.");
108
139
  ```
109
140
 
141
+ ## CLI — `imcat`
142
+
143
+ `imcat` renders Markdown files as coloured terminal output. It is built from the same ANSI renderer as `renderAnsi()`.
144
+
145
+ ```bash
146
+ cargo install ironmark --bin imcat
147
+ ```
148
+
149
+ ```text
150
+ USAGE:
151
+ imcat [OPTIONS] [FILE...]
152
+
153
+ When no FILE is given, reads from stdin. Use '-' for stdin explicitly.
154
+
155
+ OPTIONS:
156
+ --width N Terminal column width for word-wrap and heading underlines
157
+ (default: auto-detect via $COLUMNS / tput cols, fallback 80)
158
+ --no-color Disable ANSI escape codes (plain text)
159
+ -n, --line-numbers Show line numbers in fenced code blocks
160
+ --no-hard-breaks Don't turn soft newlines into hard line breaks
161
+ --no-tables Disable pipe table syntax
162
+ --no-highlight Disable ==highlight== syntax
163
+ --no-strikethrough Disable ~~strikethrough~~ syntax
164
+ --no-underline Disable ++underline++ syntax
165
+ --no-autolink Disable bare URL auto-linking
166
+ --no-task-lists Disable - [x] task list syntax
167
+ --math Enable $inline$ and $$display$$ math
168
+ --wiki-links Enable [[wiki link]] syntax
169
+ --max-size N Truncate input to N bytes (0 = unlimited)
170
+ -h, --help Print this help and exit
171
+ -V, --version Print version and exit
172
+
173
+ EXAMPLES:
174
+ imcat README.md
175
+ imcat --width 120 README.md
176
+ imcat --no-color README.md | less
177
+ echo '# Hello' | imcat
178
+ cat doc.md | imcat --math --wiki-links
179
+ ```
180
+
110
181
  ## Rust
111
182
 
112
183
  ```bash
@@ -162,6 +233,43 @@ Exported AST types:
162
233
  - `TableData`
163
234
  - `TableAlignment`
164
235
 
236
+ ### ANSI Terminal Output
237
+
238
+ `render_ansi()` renders Markdown as ANSI-coloured terminal output. Pass `Some(&AnsiOptions { .. })` to control width, colour, and line numbers, or `None` for defaults.
239
+
240
+ ````rust
241
+ use ironmark::{AnsiOptions, ParseOptions, render_ansi};
242
+
243
+ fn main() {
244
+ // Defaults — width 80, colour enabled
245
+ let out = render_ansi("# Hello\n\n**bold** and `code`", &ParseOptions::default(), None);
246
+ print!("{out}");
247
+
248
+ // Custom options — 120 columns, line numbers in code blocks
249
+ let out = render_ansi(
250
+ "# Hello\n\n```rust\nfn main() {}\n```",
251
+ &ParseOptions::default(),
252
+ Some(&AnsiOptions { width: 120, line_numbers: true, ..AnsiOptions::default() }),
253
+ );
254
+ print!("{out}");
255
+
256
+ // Plain text — no ANSI codes (e.g. for writing to a file)
257
+ let plain = render_ansi(
258
+ "# Hello",
259
+ &ParseOptions::default(),
260
+ Some(&AnsiOptions { color: false, ..AnsiOptions::default() }),
261
+ );
262
+ }
263
+ ````
264
+
265
+ `AnsiOptions` fields:
266
+
267
+ | Field | Type | Default | Description |
268
+ | -------------- | ------- | ------- | --------------------------------------------------------------------------- |
269
+ | `width` | `usize` | `80` | Column width for word-wrap, heading underlines, rule length. `0` = disable. |
270
+ | `color` | `bool` | `true` | Emit ANSI 256-colour escape codes. |
271
+ | `line_numbers` | `bool` | `false` | Show line numbers in fenced code blocks. |
272
+
165
273
  ## C / C++
166
274
 
167
275
  The crate compiles to a static library (`libironmark.a`) that exposes two C functions. A header is provided at `include/ironmark.h`.
@@ -236,4 +344,4 @@ pnpm build
236
344
 
237
345
  ### Troubleshooting
238
346
 
239
- **`wasm32-unknown-unknown target not found`** or **`wasm-bindgen not found`** — run `pnpm setup:wasm` to install all prerequisites.
347
+ **`wasm32-unknown-unknown target not found`** or **`wasm-bindgen not found`** — run `pnpm setup:wasm` to install all prerequisites
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ironmark",
3
- "version": "1.8.0",
3
+ "version": "1.9.0",
4
4
  "description": "Very fast markdown parser in Rust, consumable from JavaScript/TypeScript via WebAssembly",
5
5
  "keywords": [
6
6
  "markdown",
package/wasm/index.d.ts CHANGED
@@ -66,3 +66,49 @@ export declare function parse(markdown: MarkdownInput, options?: ParseOptions):
66
66
  * @returns JSON string representing the AST.
67
67
  */
68
68
  export declare function parseToAst(markdown: MarkdownInput, options?: ParseOptions): string;
69
+
70
+ /**
71
+ * Options for the ANSI terminal renderer.
72
+ */
73
+ export interface AnsiOptions {
74
+ /**
75
+ * Terminal column width for word-wrap, heading underlines, and thematic breaks.
76
+ * Set to `0` to disable all width-dependent formatting. Default: `80`.
77
+ */
78
+ width?: number;
79
+ /**
80
+ * Emit ANSI 256-colour escape codes. Set to `false` for plain-text output
81
+ * (e.g. when piping to a file or a non-colour terminal). Default: `true`.
82
+ */
83
+ color?: boolean;
84
+ /**
85
+ * Show line numbers in fenced code blocks, right-aligned to the total line
86
+ * count and separated from the code by a `│` border. Default: `false`.
87
+ */
88
+ lineNumbers?: boolean;
89
+ }
90
+
91
+ /**
92
+ * Render Markdown as ANSI-coloured terminal output.
93
+ *
94
+ * Produces a string containing ANSI 256-colour escape codes suitable for
95
+ * display in a terminal emulator. Headings, code blocks, inline code,
96
+ * blockquotes, tables, and inline formatting are all styled distinctly.
97
+ *
98
+ * @param markdown - Markdown source (string or binary).
99
+ * @param options - Optional parse options (same flags as `parse()`).
100
+ * @param ansiOptions - Optional ANSI rendering options (width, color, lineNumbers).
101
+ * @returns String with ANSI escape codes (or plain text when `color: false`).
102
+ *
103
+ * @example
104
+ * ```ts
105
+ * import { renderAnsi } from "ironmark";
106
+ * const out = renderAnsi("# Hello\n\n**bold** and `code`");
107
+ * process.stdout.write(out);
108
+ * ```
109
+ */
110
+ export declare function renderAnsi(
111
+ markdown: MarkdownInput,
112
+ options?: ParseOptions,
113
+ ansiOptions?: AnsiOptions,
114
+ ): string;