markdansi 0.2.0 → 0.2.1

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2025 Peter Steinberger
3
+ \g<1>2026 Peter Steinberger
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/dist/cli.d.ts CHANGED
@@ -13,4 +13,5 @@ export declare function handleStdoutEpipe(): void;
13
13
  * Parse CLI arguments into RenderOptions-ish object (plus in/out paths).
14
14
  */
15
15
  export declare function parseArgs(argv: string[]): CliArgs;
16
+ export declare function isDirectCliInvocation(metaUrl: string, argv1?: string): boolean;
16
17
  export {};
package/dist/cli.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import fs from "node:fs";
3
3
  import path from "node:path";
4
- import { pathToFileURL } from "node:url";
4
+ import { fileURLToPath } from "node:url";
5
5
  import { render } from "./index.js";
6
6
  /**
7
7
  * Ignore EPIPE when downstream (e.g., `head`) closes early.
@@ -157,10 +157,19 @@ function main() {
157
157
  process.stdout.write(output);
158
158
  }
159
159
  }
160
+ export function isDirectCliInvocation(metaUrl, argv1) {
161
+ if (!argv1)
162
+ return false;
163
+ try {
164
+ const entry = fs.realpathSync(argv1);
165
+ const self = fs.realpathSync(fileURLToPath(metaUrl));
166
+ return entry === self;
167
+ }
168
+ catch {
169
+ return false;
170
+ }
171
+ }
160
172
  // Only run the CLI when executed directly, not when imported for tests.
161
- const entryHref = process.argv[1]
162
- ? pathToFileURL(process.argv[1]).href
163
- : undefined;
164
- if (import.meta.url === entryHref) {
173
+ if (isDirectCliInvocation(import.meta.url, process.argv[1])) {
165
174
  main();
166
175
  }
package/dist/render.js CHANGED
@@ -565,13 +565,15 @@ function renderTable(node, ctx) {
565
565
  const widths = new Array(colCount).fill(1);
566
566
  const aligns = node.align || [];
567
567
  const pad = ctx.options.tablePadding;
568
+ const padStr = " ".repeat(Math.max(0, pad));
568
569
  const minContent = Math.max(1, ctx.options.tableEllipsis.length + 1);
569
570
  // ensure we always have room for at least one visible char + ellipsis + padding
570
571
  const minColWidth = Math.max(1, pad * 2 + minContent);
571
572
  cells.forEach((row) => {
572
573
  row.forEach((cell, idx) => {
574
+ const padded = `${padStr}${cell}${padStr}`;
573
575
  // Cap each column to MAX_COL but keep at least 1
574
- widths[idx] = Math.max(widths[idx], Math.min(MAX_COL, visibleWidth(cell)));
576
+ widths[idx] = Math.max(widths[idx], Math.min(MAX_COL, visibleWidth(padded)));
575
577
  });
576
578
  });
577
579
  const totalWidth = widths.reduce((a, b) => a + b, 0) + 3 * colCount + 1;
@@ -592,13 +594,16 @@ function renderTable(node, ctx) {
592
594
  }
593
595
  const renderRow = (row, isHeader = false) => {
594
596
  const linesPerCol = row.map((cell, idx) => {
595
- const padded = ` ${cell} `;
596
597
  const target = Math.max(minContent, widths[idx] - pad * 2);
597
- const cellText = ctx.options.tableTruncate
598
+ const content = ctx.options.tableTruncate
598
599
  ? truncateCell(cell, target, ctx.options.tableEllipsis)
599
- : padded;
600
- const wrapped = wrapText(cellText, ctx.options.wrap ? target : Number.MAX_SAFE_INTEGER, ctx.options.wrap);
601
- return wrapped.map((l) => padCell(` ${l} `, widths[idx], aligns[idx] ?? "left", ctx.options.tablePadding));
600
+ : cell;
601
+ const wrapped = wrapText(content, ctx.options.wrap ? target : Number.MAX_SAFE_INTEGER, ctx.options.wrap);
602
+ return wrapped.map((l) => {
603
+ const aligned = padCell(l, target, aligns[idx] ?? "left");
604
+ const padded = `${padStr}${aligned}${padStr}`;
605
+ return padCell(padded, widths[idx], "left");
606
+ });
602
607
  });
603
608
  // Row height = max wrapped lines in any column; pad shorter ones
604
609
  const height = Math.max(...linesPerCol.map((c) => c.length));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markdansi",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Tiny dependency-light markdown to ANSI converter.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",