@dunkinfrunkin/mdcat 0.1.10 → 0.1.11

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dunkinfrunkin/mdcat",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "description": "View markdown files beautifully in your terminal",
5
5
  "type": "module",
6
6
  "bin": {
package/src/cli.js CHANGED
@@ -3,7 +3,7 @@ import { readFileSync, writeFileSync } from "fs";
3
3
  import { resolve, basename } from "path";
4
4
  import { tmpdir } from "os";
5
5
  import { execFileSync } from "child_process";
6
- import { marked } from "marked";
6
+ import { marked, Marked } from "marked";
7
7
  import { renderTokens } from "./render.js";
8
8
  import { launch } from "./tui.js";
9
9
  import { toDocx } from "./docx.js";
@@ -52,7 +52,7 @@ function escapeHtml(s) {
52
52
  function openInBrowser(title, content) {
53
53
  // Use a custom renderer that escapes raw HTML tokens so bare <tag> in
54
54
  // markdown text isn't swallowed by the browser.
55
- const webMarked = new marked.Marked({ gfm: true });
55
+ const webMarked = new Marked({ gfm: true });
56
56
  webMarked.use({
57
57
  renderer: {
58
58
  html(token) {
@@ -112,9 +112,10 @@ function openInBrowser(title, content) {
112
112
  }
113
113
 
114
114
  function runTUI(title, content) {
115
- const cols = Math.min(process.stdout.columns || 80, MAX_COLS);
115
+ const termCols = process.stdout.columns || 80;
116
+ const cols = Math.min(termCols, MAX_COLS);
116
117
  const tokens = marked.lexer(content);
117
- const lines = renderTokens(tokens, cols);
118
+ const lines = renderTokens(tokens, cols, termCols > MAX_COLS ? termCols : undefined);
118
119
  launch(title, lines);
119
120
  }
120
121
 
package/src/render.js CHANGED
@@ -468,7 +468,7 @@ function hr(w) {
468
468
 
469
469
  // ─── Token dispatcher ──────────────────────────────────────────────────────────
470
470
 
471
- function token(tok, w) {
471
+ function token(tok, w, tableW) {
472
472
  try {
473
473
  switch (tok.type) {
474
474
  case "heading":
@@ -482,7 +482,7 @@ function token(tok, w) {
482
482
  case "list":
483
483
  return ["", ...list(tok, w, 0), ""];
484
484
  case "table":
485
- return table(tok, w);
485
+ return table(tok, tableW ?? w);
486
486
  case "hr":
487
487
  return hr(w);
488
488
  case "space":
@@ -504,9 +504,11 @@ function token(tok, w) {
504
504
  *
505
505
  * @param {import("marked").Token[]} tokens - Output of `marked.lexer()`
506
506
  * @param {number} cols - Terminal width (default 80)
507
+ * @param {number} [fullCols] - Uncapped terminal width for tables
507
508
  * @returns {string[]}
508
509
  */
509
- export function renderTokens(tokens, cols = 80) {
510
+ export function renderTokens(tokens, cols = 80, fullCols) {
510
511
  const w = Math.max(20, cols - MARGIN.length * 2);
511
- return tokens.flatMap((tok) => token(tok, w));
512
+ const tableW = fullCols ? Math.max(20, fullCols - MARGIN.length * 2) : undefined;
513
+ return tokens.flatMap((tok) => token(tok, w, tableW));
512
514
  }