@dunkinfrunkin/mdcat 0.1.13 → 0.1.15
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 +6 -2
- package/package.json +2 -2
- package/src/cli.js +30 -2
- package/src/tui.js +23 -7
package/README.md
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@dunkinfrunkin/mdcat)
|
|
4
4
|
[](LICENSE)
|
|
5
|
-
[](package.json)
|
|
6
|
+
[](https://github.com/dunkinfrunkin/mdcat/actions/workflows/ci.yml)
|
|
6
7
|
[](https://mdcat.frankchan.dev)
|
|
7
8
|
|
|
8
9
|
**Terminal pager for Markdown.** Full colour, syntax highlighting, incremental search, mouse support — zero config.
|
|
@@ -33,6 +34,8 @@ npx @dunkinfrunkin/mdcat README.md
|
|
|
33
34
|
```sh
|
|
34
35
|
mdcat README.md # open a file
|
|
35
36
|
mdcat --web README.md # render and open in browser
|
|
37
|
+
mdcat -p README.md # plain text output (no TUI, no ANSI)
|
|
38
|
+
mdcat -n README.md # show line numbers
|
|
36
39
|
mdcat --light README.md # force light theme
|
|
37
40
|
mdcat --dark README.md # force dark theme
|
|
38
41
|
cat CHANGELOG.md | mdcat # pipe from stdin
|
|
@@ -47,6 +50,7 @@ mdcat --version # show version
|
|
|
47
50
|
|-----|--------|
|
|
48
51
|
| `q` | Quit |
|
|
49
52
|
| `y` | Copy visible page to clipboard |
|
|
53
|
+
| `L` | Toggle line numbers |
|
|
50
54
|
| `M` | Toggle mouse (off = free text selection) |
|
|
51
55
|
| `j` / `k` | Scroll down / up |
|
|
52
56
|
| `Space` / `b` | Page down / up |
|
|
@@ -105,7 +109,7 @@ npm install
|
|
|
105
109
|
npm test
|
|
106
110
|
```
|
|
107
111
|
|
|
108
|
-
All PRs must pass `npm test` (
|
|
112
|
+
All PRs must pass `npm test` (90 tests).
|
|
109
113
|
|
|
110
114
|
See [CONTRIBUTING.md](CONTRIBUTING.md) for more details.
|
|
111
115
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dunkinfrunkin/mdcat",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.15",
|
|
4
4
|
"description": "View markdown files beautifully in your terminal",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"wrap-ansi": "^10.0.0"
|
|
22
22
|
},
|
|
23
23
|
"engines": {
|
|
24
|
-
"node": ">=
|
|
24
|
+
"node": ">=20"
|
|
25
25
|
},
|
|
26
26
|
"keywords": [
|
|
27
27
|
"markdown",
|
package/src/cli.js
CHANGED
|
@@ -30,8 +30,10 @@ if (args[0] === "--help" || args[0] === "-h") {
|
|
|
30
30
|
console.log(` mdcat ${dim("<file.md>")}`);
|
|
31
31
|
console.log(` mdcat ${dim("--web <file.md>")} ${dim("# open in browser")}`);
|
|
32
32
|
console.log(` mdcat ${dim("--doc <file.md>")} ${dim("# export to .docx")}`);
|
|
33
|
+
console.log(` mdcat ${dim("-p, --plain")} ${dim("# plain output (no TUI, no ANSI)")}`);
|
|
33
34
|
console.log(` mdcat ${dim("--light")} ${dim("# force light theme")}`);
|
|
34
35
|
console.log(` mdcat ${dim("--dark")} ${dim("# force dark theme")}`);
|
|
36
|
+
console.log(` mdcat ${dim("-n, --number")} ${dim("# show line numbers")}`);
|
|
35
37
|
console.log(` cat file.md ${dim("|")} mdcat\n`);
|
|
36
38
|
console.log(`${bold("Theme:")}`);
|
|
37
39
|
console.log(` Auto-detects terminal theme. Override with ${blue("--light")} / ${blue("--dark")}`);
|
|
@@ -40,7 +42,7 @@ if (args[0] === "--help" || args[0] === "-h") {
|
|
|
40
42
|
console.log(` ${blue("/")} search ${blue("n/N")} next/prev match`);
|
|
41
43
|
console.log(` ${blue("j/k")} ${dim("↑↓")} scroll line ${blue("space/b")} page down/up`);
|
|
42
44
|
console.log(` ${blue("d/u")} half page ${blue("g/G")} top/bottom`);
|
|
43
|
-
console.log(` ${blue("q")}
|
|
45
|
+
console.log(` ${blue("L")} line numbers ${blue("q")} quit\n`);
|
|
44
46
|
process.exit(0);
|
|
45
47
|
}
|
|
46
48
|
|
|
@@ -49,6 +51,14 @@ const activeTheme = themeFromArgs(args) ?? detectTheme();
|
|
|
49
51
|
args = stripThemeArgs(args);
|
|
50
52
|
setTheme(activeTheme);
|
|
51
53
|
|
|
54
|
+
// Plain mode flag
|
|
55
|
+
const plainMode = args.includes("-p") || args.includes("--plain");
|
|
56
|
+
args = args.filter(a => a !== "-p" && a !== "--plain");
|
|
57
|
+
|
|
58
|
+
// Line numbers flag
|
|
59
|
+
const showLineNumbers = args.includes("-n") || args.includes("--number");
|
|
60
|
+
args = args.filter(a => a !== "-n" && a !== "--number");
|
|
61
|
+
|
|
52
62
|
if (args[0] === "--version" || args[0] === "-v") {
|
|
53
63
|
console.log(`${CAT} ${bold("mdcat")} ${dim(`v${pkg.version}`)}`);
|
|
54
64
|
process.exit(0);
|
|
@@ -56,6 +66,22 @@ if (args[0] === "--version" || args[0] === "-v") {
|
|
|
56
66
|
|
|
57
67
|
const MAX_COLS = 100;
|
|
58
68
|
|
|
69
|
+
/** Strip ANSI SGR sequences and OSC 8 hyperlinks for plain text output. */
|
|
70
|
+
function stripAnsi(s) {
|
|
71
|
+
return s
|
|
72
|
+
.replace(/\x1B\]8;;.*?\x1B\\/gs, "")
|
|
73
|
+
.replace(/\x1B\[[0-9;]*m/g, "");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function runPlain(content) {
|
|
77
|
+
const cols = Math.min(process.stdout.columns || 80, MAX_COLS);
|
|
78
|
+
const tokens = marked.lexer(content);
|
|
79
|
+
const lines = renderTokens(tokens, cols);
|
|
80
|
+
for (const line of lines) {
|
|
81
|
+
console.log(stripAnsi(line));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
59
85
|
function escapeHtml(s) {
|
|
60
86
|
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
61
87
|
}
|
|
@@ -128,7 +154,7 @@ function runTUI(title, content) {
|
|
|
128
154
|
const cols = Math.min(termCols, MAX_COLS);
|
|
129
155
|
const tokens = marked.lexer(content);
|
|
130
156
|
const lines = renderTokens(tokens, cols, termCols > MAX_COLS ? termCols : undefined);
|
|
131
|
-
launch(title, lines, activeTheme);
|
|
157
|
+
launch(title, lines, activeTheme, { lineNumbers: showLineNumbers });
|
|
132
158
|
}
|
|
133
159
|
|
|
134
160
|
// --web / --doc flags
|
|
@@ -153,6 +179,7 @@ if (!process.stdin.isTTY && fileArgs.length === 0) {
|
|
|
153
179
|
process.stdin.on("end", () => {
|
|
154
180
|
if (docMode) exportDocx("stdin", input);
|
|
155
181
|
else if (webMode) openInBrowser("stdin", input);
|
|
182
|
+
else if (plainMode) runPlain(input);
|
|
156
183
|
else runTUI("stdin", input);
|
|
157
184
|
});
|
|
158
185
|
} else if (fileArgs.length === 0) {
|
|
@@ -170,5 +197,6 @@ if (!process.stdin.isTTY && fileArgs.length === 0) {
|
|
|
170
197
|
const title = basename(filePath);
|
|
171
198
|
if (docMode) exportDocx(title, content);
|
|
172
199
|
else if (webMode) openInBrowser(title, content);
|
|
200
|
+
else if (plainMode) runPlain(content);
|
|
173
201
|
else runTUI(title, content);
|
|
174
202
|
}
|
package/src/tui.js
CHANGED
|
@@ -129,7 +129,7 @@ function copyText(text) {
|
|
|
129
129
|
catch { /* not on macOS or pbcopy unavailable */ }
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
export function launch(title, lines, theme) {
|
|
132
|
+
export function launch(title, lines, theme, opts = {}) {
|
|
133
133
|
// Apply theme to TUI chrome
|
|
134
134
|
if (theme === "light") {
|
|
135
135
|
const pal = LIGHT;
|
|
@@ -137,6 +137,12 @@ export function launch(title, lines, theme) {
|
|
|
137
137
|
HL_MATCH = pal.hlMatch;
|
|
138
138
|
HL_CURRENT = pal.hlCurrent;
|
|
139
139
|
}
|
|
140
|
+
|
|
141
|
+
// Line numbers
|
|
142
|
+
let lineNumbers = opts.lineNumbers ?? false;
|
|
143
|
+
const totalDigits = String(lines.length).length;
|
|
144
|
+
const gutterW = totalDigits + 2; // " N " width
|
|
145
|
+
|
|
140
146
|
// Viewport state
|
|
141
147
|
let offset = 0;
|
|
142
148
|
|
|
@@ -225,10 +231,16 @@ export function launch(title, lines, theme) {
|
|
|
225
231
|
}
|
|
226
232
|
|
|
227
233
|
function gutterFor(absLine) {
|
|
228
|
-
|
|
229
|
-
if (
|
|
230
|
-
|
|
231
|
-
|
|
234
|
+
let prefix = "";
|
|
235
|
+
if (lineNumbers) {
|
|
236
|
+
const num = String(absLine + 1).padStart(totalDigits);
|
|
237
|
+
prefix = `${C.dimFg}${num}${RESET} `;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (mode === "normal" || !searchQuery) return prefix || " ";
|
|
241
|
+
if (matchLines[matchIdx] === absLine) return `${prefix}${C.matchFg}▶${RESET} `;
|
|
242
|
+
if (matchSet.has(absLine)) return `${prefix}${C.otherMatchFg}›${RESET} `;
|
|
243
|
+
return prefix || " ";
|
|
232
244
|
}
|
|
233
245
|
|
|
234
246
|
function statusBar(w) {
|
|
@@ -274,9 +286,9 @@ export function launch(title, lines, theme) {
|
|
|
274
286
|
|
|
275
287
|
const mouseHint = mouseEnabled ? "" : `${C.matchFg} [select mode]${RESET}`;
|
|
276
288
|
const mouseW = mouseEnabled ? 0 : " [select mode]".length;
|
|
277
|
-
const hints = `${C.dim} q y / j k ↑↓ space g G M${RESET}`;
|
|
289
|
+
const hints = `${C.dim} q y / j k ↑↓ space g G L M${RESET}`;
|
|
278
290
|
const right = `${C.dimFg} ${pct} ${RESET}`;
|
|
279
|
-
const hintsW = " q y / j k ↑↓ space g G M".length;
|
|
291
|
+
const hintsW = " q y / j k ↑↓ space g G L M".length;
|
|
280
292
|
const rightW = ` ${pct} `.length;
|
|
281
293
|
const gap = Math.max(0, w - hintsW - mouseW - rightW);
|
|
282
294
|
return `${C.chromeBg}${hints}${mouseHint}${" ".repeat(gap)}${right}${RESET}`;
|
|
@@ -368,6 +380,10 @@ export function launch(title, lines, theme) {
|
|
|
368
380
|
showToast("Copied to clipboard"); return;
|
|
369
381
|
}
|
|
370
382
|
|
|
383
|
+
case "L":
|
|
384
|
+
lineNumbers = !lineNumbers;
|
|
385
|
+
showToast(lineNumbers ? "Line numbers on" : "Line numbers off"); return;
|
|
386
|
+
|
|
371
387
|
case "M":
|
|
372
388
|
mouseEnabled = !mouseEnabled;
|
|
373
389
|
process.stdout.write(mouseEnabled ? MOUSE_ON : MOUSE_OFF);
|