ironmark 1.9.0 → 1.10.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
@@ -138,23 +138,39 @@ await init(wasmUrl);
138
138
  const html = parse("# Hello\n\nThis is **fast**.");
139
139
  ```
140
140
 
141
- ## CLI — `imcat`
141
+ ## CLI
142
142
 
143
- `imcat` renders Markdown files as coloured terminal output. It is built from the same ANSI renderer as `renderAnsi()`.
143
+ Render Markdown as coloured terminal output. Two ways to install:
144
+
145
+ ### npm
144
146
 
145
147
  ```bash
146
- cargo install ironmark --bin imcat
148
+ npx ironmark --ansi README.md
147
149
  ```
148
150
 
149
- ```text
150
- USAGE:
151
- imcat [OPTIONS] [FILE...]
151
+ Or install globally:
152
+
153
+ ```bash
154
+ npm install -g ironmark
155
+ ironmark --ansi README.md
156
+ ```
157
+
158
+ ### Rust
152
159
 
153
- When no FILE is given, reads from stdin. Use '-' for stdin explicitly.
160
+ Native binary faster startup, auto-detects terminal width via `$COLUMNS` / `tput cols`.
154
161
 
162
+ ```bash
163
+ cargo install ironmark --features cli
164
+ ironmark --ansi README.md
165
+ ```
166
+
167
+ ### Options
168
+
169
+ Both CLIs support the same flags (the npm CLI requires `--ansi` as the first flag):
170
+
171
+ ```text
155
172
  OPTIONS:
156
- --width N Terminal column width for word-wrap and heading underlines
157
- (default: auto-detect via $COLUMNS / tput cols, fallback 80)
173
+ --width N Terminal column width (default: auto-detect, fallback 80)
158
174
  --no-color Disable ANSI escape codes (plain text)
159
175
  -n, --line-numbers Show line numbers in fenced code blocks
160
176
  --no-hard-breaks Don't turn soft newlines into hard line breaks
@@ -166,16 +182,25 @@ OPTIONS:
166
182
  --no-task-lists Disable - [x] task list syntax
167
183
  --math Enable $inline$ and $$display$$ math
168
184
  --wiki-links Enable [[wiki link]] syntax
169
- --max-size N Truncate input to N bytes (0 = unlimited)
185
+ --max-size N Truncate input to N bytes (Rust only)
170
186
  -h, --help Print this help and exit
171
187
  -V, --version Print version and exit
188
+ ```
189
+
190
+ ### Examples
172
191
 
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
192
+ ```bash
193
+ # npm
194
+ npx ironmark --ansi README.md
195
+ npx ironmark --ansi --width 120 README.md
196
+ echo '# Hello' | npx ironmark --ansi
197
+ npx ironmark --ansi --no-color README.md | less
198
+
199
+ # Rust (after cargo install ironmark --features cli)
200
+ ironmark --ansi README.md
201
+ ironmark --ansi --width 120 README.md
202
+ echo '# Hello' | ironmark --ansi
203
+ cat doc.md | ironmark --ansi --math --wiki-links
179
204
  ```
180
205
 
181
206
  ## Rust
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ironmark",
3
- "version": "1.9.0",
3
+ "version": "1.10.0",
4
4
  "description": "Very fast markdown parser in Rust, consumable from JavaScript/TypeScript via WebAssembly",
5
5
  "keywords": [
6
6
  "markdown",
@@ -17,11 +17,15 @@
17
17
  "type": "git",
18
18
  "url": "https://github.com/ph1p/ironmark.git"
19
19
  },
20
+ "bin": {
21
+ "ironmark": "wasm/cli.js"
22
+ },
20
23
  "files": [
21
24
  "wasm/pkg",
22
25
  "wasm/shared.js",
23
26
  "wasm/web.js",
24
27
  "wasm/node.js",
28
+ "wasm/cli.js",
25
29
  "wasm/index.d.ts",
26
30
  "README.md"
27
31
  ],
package/wasm/cli.js ADDED
@@ -0,0 +1,154 @@
1
+ #!/usr/bin/env node
2
+ import { readFileSync } from "node:fs";
3
+ import { renderAnsi } from "./node.js";
4
+
5
+ const VERSION = JSON.parse(
6
+ readFileSync(new URL("../package.json", import.meta.url), "utf8"),
7
+ ).version;
8
+
9
+ const HELP = `ironmark — render Markdown as coloured terminal output
10
+
11
+ USAGE:
12
+ ironmark --ansi [OPTIONS] [FILE...]
13
+
14
+ When no FILE is given, reads from stdin. Use '-' for stdin explicitly.
15
+
16
+ OPTIONS:
17
+ --ansi Render as ANSI-coloured terminal output (required)
18
+ --width N Terminal column width (default: auto-detect, fallback 80)
19
+ --no-color Disable ANSI escape codes (plain text)
20
+ -n, --line-numbers Show line numbers in fenced code blocks
21
+ --no-hard-breaks Don't turn soft newlines into hard line breaks
22
+ --no-tables Disable pipe table syntax
23
+ --no-highlight Disable ==highlight== syntax
24
+ --no-strikethrough Disable ~~strikethrough~~ syntax
25
+ --no-underline Disable ++underline++ syntax
26
+ --no-autolink Disable bare URL auto-linking
27
+ --no-task-lists Disable - [x] task list syntax
28
+ --math Enable $inline$ and $$display$$ math
29
+ --wiki-links Enable [[wiki link]] syntax
30
+ -h, --help Print this help and exit
31
+ -V, --version Print version and exit
32
+
33
+ EXAMPLES:
34
+ npx ironmark --ansi README.md
35
+ npx ironmark --ansi --width 120 README.md
36
+ npx ironmark --ansi --no-color README.md | less
37
+ echo '# Hello' | npx ironmark --ansi
38
+ cat doc.md | npx ironmark --ansi --math --wiki-links
39
+ `;
40
+
41
+ const args = process.argv.slice(2);
42
+ const files = [];
43
+ const parseOptions = {};
44
+ const ansiOptions = {};
45
+ let ansiMode = false;
46
+
47
+ for (let i = 0; i < args.length; i++) {
48
+ switch (args[i]) {
49
+ case "-h":
50
+ case "--help":
51
+ process.stdout.write(HELP);
52
+ process.exit(0);
53
+ break;
54
+ case "-V":
55
+ case "--version":
56
+ console.log(`ironmark ${VERSION}`);
57
+ process.exit(0);
58
+ break;
59
+ case "--ansi":
60
+ ansiMode = true;
61
+ break;
62
+ case "--no-color":
63
+ case "--no-colour":
64
+ ansiOptions.color = false;
65
+ break;
66
+ case "-n":
67
+ case "--line-numbers":
68
+ ansiOptions.lineNumbers = true;
69
+ break;
70
+ case "--width": {
71
+ const val = args[++i];
72
+ if (val === undefined || Number.isNaN(Number(val))) {
73
+ console.error("error: --width requires a numeric value");
74
+ process.exit(2);
75
+ }
76
+ ansiOptions.width = Number(val);
77
+ break;
78
+ }
79
+ case "--no-hard-breaks":
80
+ parseOptions.hardBreaks = false;
81
+ break;
82
+ case "--no-tables":
83
+ parseOptions.enableTables = false;
84
+ break;
85
+ case "--no-highlight":
86
+ parseOptions.enableHighlight = false;
87
+ break;
88
+ case "--no-strikethrough":
89
+ parseOptions.enableStrikethrough = false;
90
+ break;
91
+ case "--no-underline":
92
+ parseOptions.enableUnderline = false;
93
+ break;
94
+ case "--no-autolink":
95
+ parseOptions.enableAutolink = false;
96
+ break;
97
+ case "--no-task-lists":
98
+ parseOptions.enableTaskLists = false;
99
+ break;
100
+ case "--math":
101
+ parseOptions.enableLatexMath = true;
102
+ break;
103
+ case "--wiki-links":
104
+ parseOptions.enableWikiLinks = true;
105
+ break;
106
+ default:
107
+ if (args[i].startsWith("--width=")) {
108
+ const val = Number(args[i].slice("--width=".length));
109
+ if (Number.isNaN(val)) {
110
+ console.error("error: --width requires a numeric value");
111
+ process.exit(2);
112
+ }
113
+ ansiOptions.width = val;
114
+ } else if (args[i].startsWith("-") && args[i] !== "-") {
115
+ console.error(`error: unknown flag: ${args[i]}`);
116
+ console.error("Run 'ironmark --help' for usage.");
117
+ process.exit(2);
118
+ } else {
119
+ files.push(args[i]);
120
+ }
121
+ }
122
+ }
123
+
124
+ if (!ansiMode) {
125
+ console.error("error: --ansi flag is required");
126
+ console.error("Run 'ironmark --help' for usage.");
127
+ process.exit(2);
128
+ }
129
+
130
+ // Auto-detect terminal width
131
+ if (ansiOptions.width === undefined) {
132
+ ansiOptions.width = process.stdout.columns || 80;
133
+ }
134
+
135
+ let input = "";
136
+
137
+ if (files.length === 0) {
138
+ input = readFileSync(0, "utf8");
139
+ } else {
140
+ for (const file of files) {
141
+ if (file === "-") {
142
+ input += readFileSync(0, "utf8");
143
+ } else {
144
+ try {
145
+ input += readFileSync(file, "utf8");
146
+ } catch (err) {
147
+ console.error(`error: ${file}: ${err.message}`);
148
+ process.exit(1);
149
+ }
150
+ }
151
+ }
152
+ }
153
+
154
+ process.stdout.write(renderAnsi(input, parseOptions, ansiOptions));