@dunkinfrunkin/mdcat 0.1.15 → 0.1.16

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
@@ -33,6 +33,7 @@ npx @dunkinfrunkin/mdcat README.md
33
33
 
34
34
  ```sh
35
35
  mdcat README.md # open a file
36
+ mdcat file1.md file2.md file3.md # view multiple files
36
37
  mdcat --web README.md # render and open in browser
37
38
  mdcat -p README.md # plain text output (no TUI, no ANSI)
38
39
  mdcat -n README.md # show line numbers
@@ -109,7 +110,7 @@ npm install
109
110
  npm test
110
111
  ```
111
112
 
112
- All PRs must pass `npm test` (90 tests).
113
+ All PRs must pass `npm test` (97 tests).
113
114
 
114
115
  See [CONTRIBUTING.md](CONTRIBUTING.md) for more details.
115
116
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dunkinfrunkin/mdcat",
3
- "version": "0.1.15",
3
+ "version": "0.1.16",
4
4
  "description": "View markdown files beautifully in your terminal",
5
5
  "type": "module",
6
6
  "bin": {
package/src/cli.js CHANGED
@@ -8,6 +8,7 @@ import { renderTokens, setTheme } from "./render.js";
8
8
  import { launch } from "./tui.js";
9
9
  import { toDocx } from "./docx.js";
10
10
  import { detectTheme, themeFromArgs, stripThemeArgs } from "./theme.js";
11
+ import { concatFiles } from "./concat.js";
11
12
 
12
13
  marked.use({ gfm: true });
13
14
 
@@ -27,7 +28,7 @@ if (args[0] === "--help" || args[0] === "-h") {
27
28
  console.log(`\n${CAT} ${bold("mdcat")} ${dim(`v${pkg.version}`)}`);
28
29
  console.log(`${dim(" markdown pager for your terminal")}\n`);
29
30
  console.log(`${bold("Usage:")}`);
30
- console.log(` mdcat ${dim("<file.md>")}`);
31
+ console.log(` mdcat ${dim("<file.md> [file2.md ...]")}`);
31
32
  console.log(` mdcat ${dim("--web <file.md>")} ${dim("# open in browser")}`);
32
33
  console.log(` mdcat ${dim("--doc <file.md>")} ${dim("# export to .docx")}`);
33
34
  console.log(` mdcat ${dim("-p, --plain")} ${dim("# plain output (no TUI, no ANSI)")}`);
@@ -183,18 +184,24 @@ if (!process.stdin.isTTY && fileArgs.length === 0) {
183
184
  else runTUI("stdin", input);
184
185
  });
185
186
  } else if (fileArgs.length === 0) {
186
- console.error("Usage: mdcat <file.md>");
187
+ console.error("Usage: mdcat <file.md> [file2.md ...]");
187
188
  process.exit(1);
188
189
  } else {
189
- const filePath = resolve(fileArgs[0]);
190
- let content;
191
- try {
192
- content = readFileSync(filePath, "utf8");
193
- } catch (err) {
194
- console.error(`mdcat: ${fileArgs[0]}: ${err.code === "ENOENT" ? "No such file" : err.message}`);
195
- process.exit(1);
190
+ const parts = [];
191
+ for (const arg of fileArgs) {
192
+ const filePath = resolve(arg);
193
+ let text;
194
+ try {
195
+ text = readFileSync(filePath, "utf8");
196
+ } catch (err) {
197
+ console.error(`mdcat: ${arg}: ${err.code === "ENOENT" ? "No such file" : err.message}`);
198
+ process.exit(1);
199
+ }
200
+ parts.push({ name: basename(filePath), content: text });
196
201
  }
197
- const title = basename(filePath);
202
+
203
+ const { title, content } = concatFiles(parts);
204
+
198
205
  if (docMode) exportDocx(title, content);
199
206
  else if (webMode) openInBrowser(title, content);
200
207
  else if (plainMode) runPlain(content);
package/src/concat.js ADDED
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Concatenate multiple file entries into a single markdown document.
3
+ * Each entry is { name, content }. When there is more than one file,
4
+ * a `## filename` heading and `---` separator are inserted between files.
5
+ * Returns { title, content }.
6
+ */
7
+ export function concatFiles(parts) {
8
+ if (parts.length === 0) return { title: "", content: "" };
9
+ if (parts.length === 1) return { title: parts[0].name, content: parts[0].content };
10
+ return {
11
+ title: `${parts.length} files`,
12
+ content: parts
13
+ .map(p => `## ${p.name}\n\n${p.content}`)
14
+ .join("\n\n---\n\n"),
15
+ };
16
+ }