@dunkinfrunkin/mdcat 0.1.14 → 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 +2 -1
- package/package.json +1 -1
- package/src/cli.js +23 -0
package/README.md
CHANGED
|
@@ -34,6 +34,7 @@ npx @dunkinfrunkin/mdcat README.md
|
|
|
34
34
|
```sh
|
|
35
35
|
mdcat README.md # open a file
|
|
36
36
|
mdcat --web README.md # render and open in browser
|
|
37
|
+
mdcat -p README.md # plain text output (no TUI, no ANSI)
|
|
37
38
|
mdcat -n README.md # show line numbers
|
|
38
39
|
mdcat --light README.md # force light theme
|
|
39
40
|
mdcat --dark README.md # force dark theme
|
|
@@ -108,7 +109,7 @@ npm install
|
|
|
108
109
|
npm test
|
|
109
110
|
```
|
|
110
111
|
|
|
111
|
-
All PRs must pass `npm test` (
|
|
112
|
+
All PRs must pass `npm test` (90 tests).
|
|
112
113
|
|
|
113
114
|
See [CONTRIBUTING.md](CONTRIBUTING.md) for more details.
|
|
114
115
|
|
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -30,6 +30,7 @@ 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")}`);
|
|
35
36
|
console.log(` mdcat ${dim("-n, --number")} ${dim("# show line numbers")}`);
|
|
@@ -50,6 +51,10 @@ const activeTheme = themeFromArgs(args) ?? detectTheme();
|
|
|
50
51
|
args = stripThemeArgs(args);
|
|
51
52
|
setTheme(activeTheme);
|
|
52
53
|
|
|
54
|
+
// Plain mode flag
|
|
55
|
+
const plainMode = args.includes("-p") || args.includes("--plain");
|
|
56
|
+
args = args.filter(a => a !== "-p" && a !== "--plain");
|
|
57
|
+
|
|
53
58
|
// Line numbers flag
|
|
54
59
|
const showLineNumbers = args.includes("-n") || args.includes("--number");
|
|
55
60
|
args = args.filter(a => a !== "-n" && a !== "--number");
|
|
@@ -61,6 +66,22 @@ if (args[0] === "--version" || args[0] === "-v") {
|
|
|
61
66
|
|
|
62
67
|
const MAX_COLS = 100;
|
|
63
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
|
+
|
|
64
85
|
function escapeHtml(s) {
|
|
65
86
|
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
66
87
|
}
|
|
@@ -158,6 +179,7 @@ if (!process.stdin.isTTY && fileArgs.length === 0) {
|
|
|
158
179
|
process.stdin.on("end", () => {
|
|
159
180
|
if (docMode) exportDocx("stdin", input);
|
|
160
181
|
else if (webMode) openInBrowser("stdin", input);
|
|
182
|
+
else if (plainMode) runPlain(input);
|
|
161
183
|
else runTUI("stdin", input);
|
|
162
184
|
});
|
|
163
185
|
} else if (fileArgs.length === 0) {
|
|
@@ -175,5 +197,6 @@ if (!process.stdin.isTTY && fileArgs.length === 0) {
|
|
|
175
197
|
const title = basename(filePath);
|
|
176
198
|
if (docMode) exportDocx(title, content);
|
|
177
199
|
else if (webMode) openInBrowser(title, content);
|
|
200
|
+
else if (plainMode) runPlain(content);
|
|
178
201
|
else runTUI(title, content);
|
|
179
202
|
}
|