markdown-parity-check 0.2.15 → 0.2.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.
@@ -39,6 +39,10 @@ export interface AlignmentLimits {
39
39
  maxSimilarityWork: number;
40
40
  }
41
41
  export declare const DEFAULT_LIMITS: Readonly<AlignmentLimits>;
42
+ /** Fills in the defaults for any limit the caller did not set, and validates every one. Exported so
43
+ * compare.ts can resolve the same limits once and thread maxSimilarityWork into its own link-pairing budget
44
+ * (0.2.16). */
45
+ export declare function resolveLimits(limits: Partial<AlignmentLimits> | undefined): AlignmentLimits;
42
46
  /** Thrown when the comparison would exceed a documented resource limit. The caller reports it as an
43
47
  * error result (exit 2), never as a pass or a silently truncated comparison. */
44
48
  export declare class AlignmentLimitError extends Error {
package/dist/src/align.js CHANGED
@@ -32,7 +32,10 @@ export const DEFAULT_LIMITS = Object.freeze({
32
32
  maxSimilarityCandidates: MAX_SIMILARITY_CANDIDATES,
33
33
  maxSimilarityWork: Number.POSITIVE_INFINITY,
34
34
  });
35
- function resolveLimits(limits) {
35
+ /** Fills in the defaults for any limit the caller did not set, and validates every one. Exported so
36
+ * compare.ts can resolve the same limits once and thread maxSimilarityWork into its own link-pairing budget
37
+ * (0.2.16). */
38
+ export function resolveLimits(limits) {
36
39
  const out = { ...DEFAULT_LIMITS, ...(limits ?? {}) };
37
40
  for (const [k, v] of Object.entries(out)) {
38
41
  if (typeof v !== 'number' || Number.isNaN(v) || v <= 0)
package/dist/src/cli.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { type FetchOptions, type FetchResult } from './fetch.js';
3
- export declare const HELP = "markdown-parity-check 0.2.15\nCompares the main content of a web page's HTML and Markdown representations and reports concrete\nmissing, added and changed blocks.\n\nUsage:\n markdown-parity-check --url <https://example.com/page> [--markdown-url <url>] [options]\n markdown-parity-check --html-file <page.html> --markdown-file <page.md> [--base-url <url>] [options]\n\nModes:\n --url <url> Fetch <url> twice: with Accept: text/html and with Accept: text/markdown.\n --markdown-url <url> Fetch the Markdown from this explicit address instead (requires --url).\n --html-file <path> Offline: local HTML file (requires --markdown-file).\n --markdown-file <path> Offline: local Markdown file (requires --html-file).\n --base-url <url> Offline: base for resolving relative links on both sides.\n\nOptions:\n --html-profile generic|starlight\n HTML extraction rules (default: generic). Starlight includes inactive tab panels.\n --selector <css> CSS selector for the HTML main content (default: main, article, [role=main], then body).\n --front-matter keep|strip\n Markdown front matter. keep (default) removes nothing and warns when the document\n starts with a YAML-looking fenced block; strip removes that leading block.\n --format text|json Report format (default: text).\n --output <path> Write the report to a file instead of stdout. Refuses to overwrite an input file.\n --timeout-ms <n> Per-fetch timeout in milliseconds (default: 15000).\n --max-bytes <n> Cap on decoded response bytes per fetch (default: 5242880).\n --strict Treat warnings as rejecting findings too.\n --help, -h Show this help.\n --version, -V Show the version.\n\nExit codes:\n 0 comparison completed, no rejecting finding\n 1 comparison completed, rejecting content or delivery differences found\n 2 input, fetch, parse or report error prevented a reliable comparison\n\nOnly http(s) URLs to public addresses are fetched; loopback, private, link-local and other non-public\naddresses are refused, also behind DNS and redirects. No JavaScript is executed. Exit 0 does not prove\nsemantic equivalence.\n";
3
+ export declare const HELP = "markdown-parity-check 0.2.16\nCompares the main content of a web page's HTML and Markdown representations and reports concrete\nmissing, added and changed blocks.\n\nUsage:\n markdown-parity-check --url <https://example.com/page> [--markdown-url <url>] [options]\n markdown-parity-check --html-file <page.html> --markdown-file <page.md> [--base-url <url>] [options]\n\nModes:\n --url <url> Fetch <url> twice: with Accept: text/html and with Accept: text/markdown.\n --markdown-url <url> Fetch the Markdown from this explicit address instead (requires --url).\n --html-file <path> Offline: local HTML file (requires --markdown-file).\n --markdown-file <path> Offline: local Markdown file (requires --html-file).\n --base-url <url> Offline: base for resolving relative links on both sides.\n\nOptions:\n --html-profile generic|starlight\n HTML extraction rules (default: generic). Starlight includes inactive tab panels.\n --selector <css> CSS selector for the HTML main content (default: main, article, [role=main], then body).\n --front-matter keep|strip\n Markdown front matter. keep (default) removes nothing and warns when the document\n starts with a YAML-looking fenced block; strip removes that leading block.\n --format text|json Report format (default: text).\n --output <path> Write the report to a file instead of stdout. Refuses to overwrite an input file.\n --timeout-ms <n> Per-fetch timeout in milliseconds (default: 15000).\n --max-bytes <n> Cap on decoded response bytes per fetch (default: 5242880).\n --strict Treat warnings as rejecting findings too.\n --help, -h Show this help.\n --version, -V Show the version.\n\nExit codes:\n 0 comparison completed, no rejecting finding\n 1 comparison completed, rejecting content or delivery differences found\n 2 input, fetch, parse or report error prevented a reliable comparison\n\nOnly http(s) URLs to public addresses are fetched; loopback, private, link-local and other non-public\naddresses are refused, also behind DNS and redirects. No JavaScript is executed. Exit 0 does not prove\nsemantic equivalence.\n";
4
4
  export declare class CliError extends Error {
5
5
  }
6
6
  export interface CliArgs {
package/dist/src/cli.js CHANGED
@@ -159,7 +159,11 @@ export function parseCliArgs(argv) {
159
159
  throw new Error('not http(s)');
160
160
  }
161
161
  catch {
162
- throw new CliError(`--base-url must be an absolute http(s) URL (got "${args.baseUrl}").`);
162
+ // args.baseUrl is embedded directly, so it must be masked here rather than left to the generic
163
+ // redactText pass over stderr/JSON: a raw space breaks that pass's run-based URL detection into
164
+ // fragments too small to recognize as one URL, leaving user information such as a password visible
165
+ // (0.2.16, found by an outside review 2026-09-28). maskUrl handles the whole value correctly regardless.
166
+ throw new CliError(`--base-url must be an absolute http(s) URL (got "${maskUrl(args.baseUrl)}").`);
163
167
  }
164
168
  }
165
169
  }
@@ -39,7 +39,7 @@ export declare function diffNumbers(a: string[], b: string[]): {
39
39
  * whose text differs only in case or punctuation is one changed text and not a missing and an added link (0.2.13).
40
40
  * @internal Exported for test/compare-links.test.ts.
41
41
  */
42
- export declare function pairLinks(hLinks: Link[], mLinks: Link[]): {
42
+ export declare function pairLinks(hLinks: Link[], mLinks: Link[], maxWork?: number): {
43
43
  pairs: Array<[number, number]>;
44
44
  missing: number[];
45
45
  added: number[];
@@ -1,5 +1,5 @@
1
1
  // The comparison core: aligns blocks and turns the alignment into findings. Pure and network-free.
2
- import { align, UNCERTAIN_THRESHOLD } from './align.js';
2
+ import { align, resolveLimits, AlignmentLimitError, UNCERTAIN_THRESHOLD } from './align.js';
3
3
  import { excerpt, hrefDifference, looseNormalize, maskHref, redactText, relativeHrefRelation, visibleNumbers } from './normalize.js';
4
4
  // The excerpt masks the whole block text before it cuts it, so it is computed once per block. Up to 0.2.11 every
5
5
  // finding computed it again, and a block with thousands of link findings did that thousands of times (0.2.12).
@@ -73,7 +73,7 @@ const linkHref = (l, href) => (l.masked ? '***' : maskHref(href));
73
73
  * whose text differs only in case or punctuation is one changed text and not a missing and an added link (0.2.13).
74
74
  * @internal Exported for test/compare-links.test.ts.
75
75
  */
76
- export function pairLinks(hLinks, mLinks) {
76
+ export function pairLinks(hLinks, mLinks, maxWork = Number.POSITIVE_INFINITY) {
77
77
  const used = new Array(mLinks.length).fill(false);
78
78
  const lists = new Map();
79
79
  const heads = new Map();
@@ -113,6 +113,10 @@ export function pairLinks(hLinks, mLinks) {
113
113
  const seenInH = new Map();
114
114
  const pairs = [];
115
115
  let missing = [];
116
+ // Unresolved links with the same text and unequal counts scan the shared list below once per HTML link (step
117
+ // 2); work counts those scans so maxWork bounds the total the way maxSimilarityWork bounds align's own
118
+ // similarity search (0.2.16, found by an outside review 2026-09-28).
119
+ let work = 0;
116
120
  hLinks.forEach((hl, hi) => {
117
121
  let idx = -1;
118
122
  const k = seenInH.get(hl.text) ?? 0;
@@ -129,6 +133,10 @@ export function pairLinks(hLinks, mLinks) {
129
133
  else {
130
134
  const list = lists.get(key('text', hl.text)) ?? [];
131
135
  for (const i of list) {
136
+ work++;
137
+ if (work > maxWork) {
138
+ throw new AlignmentLimitError(`Comparison limit exceeded: pairing unresolved links by shared text needs more than ${maxWork} comparisons among ${hLinks.length} HTML and ${mLinks.length} Markdown links. Narrow the HTML content with --selector or compare a smaller page.`);
139
+ }
132
140
  if (!used[i] && sameTarget(hl, mLinks[i])) {
133
141
  idx = i;
134
142
  break;
@@ -186,9 +194,9 @@ export function pairLinks(hLinks, mLinks) {
186
194
  });
187
195
  return { pairs, missing, added };
188
196
  }
189
- function compareLinks(out, h, m, bothBases) {
197
+ function compareLinks(out, h, m, bothBases, maxSimilarityWork) {
190
198
  // Link targets are compared unmasked; every value that reaches a finding goes through maskHref.
191
- const { pairs, missing, added } = pairLinks(h.links, m.links);
199
+ const { pairs, missing, added } = pairLinks(h.links, m.links, maxSimilarityWork);
192
200
  const events = [...pairs.map(([hi, mi]) => ({ hi, mi })), ...missing.map((hi) => ({ hi, mi: -1 }))].sort((x, y) => x.hi - y.hi);
193
201
  for (const { hi, mi } of events) {
194
202
  const hl = h.links[hi];
@@ -256,6 +264,10 @@ function compareListItems(out, h, m) {
256
264
  }
257
265
  }
258
266
  function compareTables(out, h, m) {
267
+ // A spanned table already carries its one EXTRACTION_TABLE_SPAN_NOT_COMPARED issue from extraction; the cell
268
+ // positions html.ts still filled in are not reliable, so no cell-by-cell finding is added here (0.2.16).
269
+ if (h.spanned)
270
+ return;
259
271
  const hc = h.cells ?? [];
260
272
  const mc = m.cells ?? [];
261
273
  const hCols = Math.max(0, ...hc.map((r) => r.length));
@@ -274,7 +286,7 @@ function compareTables(out, h, m) {
274
286
  }
275
287
  }
276
288
  }
277
- function comparePair(out, p, h, m, bothBases) {
289
+ function comparePair(out, p, h, m, bothBases, maxSimilarityWork) {
278
290
  if (p.kind === 'moved') {
279
291
  out.push({ code: 'ORDER_CHANGED', severity: 'warning', direction: 'both', message: `The ${label(h)} appears in a different position in the Markdown.`, html: side(h), markdown: side(m) });
280
292
  }
@@ -325,12 +337,13 @@ function comparePair(out, p, h, m, bothBases) {
325
337
  }
326
338
  if (h.type === 'listItem' && m.type === 'listItem')
327
339
  compareListItems(out, h, m);
328
- compareLinks(out, h, m, bothBases);
340
+ compareLinks(out, h, m, bothBases, maxSimilarityWork);
329
341
  }
330
342
  const SEVERITY_ORDER = { error: 0, warning: 1, info: 2 };
331
343
  export function compare(html, markdown, options = {}) {
332
344
  const a = html.blocks;
333
345
  const b = markdown.blocks;
346
+ const lim = resolveLimits(options.limits);
334
347
  const al = align(a, b, options.limits);
335
348
  const findings = [];
336
349
  const bothBases = options.bothBases ?? false;
@@ -342,7 +355,7 @@ export function compare(html, markdown, options = {}) {
342
355
  for (const i of markdown.issues)
343
356
  findings.push({ code: i.code, severity: i.severity, direction: 'markdown_only', message: i.message, markdown: { line: i.line, excerpt: i.excerpt } });
344
357
  for (const p of al.pairs)
345
- comparePair(findings, p, a[p.a], b[p.b], bothBases);
358
+ comparePair(findings, p, a[p.a], b[p.b], bothBases, lim.maxSimilarityWork);
346
359
  for (const i of al.unmatchedA) {
347
360
  const h = a[i];
348
361
  findings.push({ code: 'BLOCK_MISSING', severity: 'error', direction: 'html_only', message: `The ${label(h)} is in the HTML but not in the Markdown.`, html: side(h), before: excerpt(h.type === 'code' ? (h.code ?? h.text) : h.text) });
package/dist/src/html.js CHANGED
@@ -295,8 +295,11 @@ function listInfo(ctx, li) {
295
295
  }
296
296
  const info = { ordered, depth: ctx.listBase + Math.max(0, lists - 1), checked: taskState(li) };
297
297
  if (ordered && parent) {
298
+ const reversed = parent.attribs['reversed'] !== undefined;
298
299
  const ordinal = listOrdinals(ctx, parent).get(li);
299
- if (ordinal !== undefined)
300
+ // A reversed list's numbering is not compared (see listOrdinals); every item is left consistent instead of
301
+ // comparing only the first one.
302
+ if (ordinal !== undefined && !reversed)
300
303
  info.ordinal = ordinal;
301
304
  }
302
305
  return info;
@@ -326,16 +329,27 @@ function listOrdinals(ctx, ol) {
326
329
  out.set(item, n);
327
330
  n += reversed ? -1 : 1;
328
331
  });
332
+ // A reversed list only gives its first item a browser-shown number (see above); Markdown has no reversed list,
333
+ // so the later numbers are never compared. Up to 0.2.15 that was silent; listInfo below now also leaves every
334
+ // item's ordinal out, not only the ones already undefined (0.2.16, found by an outside review 2026-09-28).
335
+ if (reversed && items.length > 0) {
336
+ ctx.issues.push({ code: 'EXTRACTION_LIST_REVERSED_NOT_COMPARED', severity: 'info', message: 'This list is reversed; its numbering is not compared, because Markdown has no reversed list to compare it against.', line: lineOf(ctx, ol) });
337
+ }
329
338
  ctx.ordinals.set(ol, out);
330
339
  return out;
331
340
  }
332
- /** The state of the item's own checkbox, not one inside a nested list: true, false, or null without one. */
341
+ /** The state of the item's own checkbox, not one inside a nested list: true, false, or null without one. A
342
+ * checkbox hidden by the hidden or aria-hidden attribute, or wrapped in a hidden ancestor, is skipped like any
343
+ * other hidden content: its subtree is never pushed onto the stack, so an earlier hidden checkbox cannot answer
344
+ * for a later visible one (0.2.16, found by an outside review 2026-09-28). */
333
345
  function taskState(li) {
334
346
  const stack = [...li.children].reverse();
335
347
  while (stack.length > 0) {
336
348
  const node = stack.pop();
337
349
  if (!(node instanceof Element) || node.name === 'ul' || node.name === 'ol')
338
350
  continue;
351
+ if (hiddenAttr(node))
352
+ continue;
339
353
  if (node.name === 'input' && (node.attribs['type'] ?? '').toLowerCase() === 'checkbox')
340
354
  return node.attribs['checked'] !== undefined;
341
355
  for (let i = node.children.length - 1; i >= 0; i--)
@@ -395,7 +409,10 @@ function starlightCode(pre) {
395
409
  const language = pre.attribs['data-language'];
396
410
  const diffMarkers = Boolean(language) && language !== 'diff'
397
411
  && lines.some((line) => line instanceof Element && (hasClass(line, 'ins') || hasClass(line, 'del')));
398
- return lines.map((line) => starlightLineText(line.children.filter((node) => !gutter(node)), line, diffMarkers)).join('\n');
412
+ // A line hidden with the hidden attribute is not exported either: up to 0.2.15 every .ec-line reached the text
413
+ // regardless of visibility (0.2.16, found by an outside review 2026-09-28).
414
+ const visibleLines = lines.filter((line) => !(line instanceof Element && hiddenAttr(line)));
415
+ return visibleLines.map((line) => starlightLineText(line.children.filter((node) => !gutter(node)), line, diffMarkers)).join('\n');
399
416
  }
400
417
  /** One Expressive Code line as starlight-llms-txt exports it. The marker goes before the first text of the first
401
418
  * span that is not an indent span; a line whose first such span does not start with text gets no marker. */
@@ -500,6 +517,19 @@ function handleStarlightTabs(ctx, component) {
500
517
  ctx.listBase--;
501
518
  }
502
519
  }
520
+ /** Whether a table cell carries a rowspan or colspan that actually spans more than one row or column; an
521
+ * absent, empty or "1" value is the default and is not a span. An unparseable value is treated as a span too,
522
+ * because a plain grid reading cannot tell what it means either. */
523
+ function hasSpan(el) {
524
+ const spans = (attr) => {
525
+ const v = el.attribs[attr];
526
+ if (v === undefined)
527
+ return false;
528
+ const n = Number.parseInt(v, 10);
529
+ return !Number.isFinite(n) || n > 1;
530
+ };
531
+ return spans('rowspan') || spans('colspan');
532
+ }
503
533
  function handleTable(ctx, table) {
504
534
  // The caption is content: a paragraph before the table, the way a Markdown table's title has to be written. Up to
505
535
  // 0.2.12 it was dropped with its text, numbers and links (found by an outside review 2026-09-26).
@@ -520,6 +550,15 @@ function handleTable(ctx, table) {
520
550
  return true;
521
551
  };
522
552
  const rows = selectAll('tr', table).filter((tr) => closestTable(tr) === table && shown(tr));
553
+ // A rowspan or colspan moves a cell's value into a column a plain row/column reading does not predict, so the
554
+ // table body is not compared, the way a footnote's content is not: the block is still pushed, so it keeps
555
+ // aligning with its Markdown counterpart instead of showing up as a missing and an added block, but compare.ts
556
+ // skips the cell-by-cell check for it once it sees the flag (0.2.16, found by an outside review 2026-09-28); the
557
+ // caption above is unaffected and stays compared either way.
558
+ const spanned = rows.some((tr) => tr.children.some((c) => c instanceof Element && (c.name === 'td' || c.name === 'th') && !isSkipped(c, ctx.root, ctx.profile) && hasSpan(c)));
559
+ if (spanned) {
560
+ ctx.issues.push({ code: 'EXTRACTION_TABLE_SPAN_NOT_COMPARED', severity: 'info', message: 'A table cell carries a rowspan or colspan attribute; a plain row/column reading cannot place its value reliably, so the table body was not compared.', line: lineOf(ctx, table) });
561
+ }
523
562
  const cells = [];
524
563
  const links = [];
525
564
  for (const tr of rows) {
@@ -539,7 +578,7 @@ function handleTable(ctx, table) {
539
578
  if (cells.length === 0)
540
579
  return;
541
580
  const text = cells.map((r) => r.join(' | ')).join(' \n ');
542
- pushBlock(ctx, { type: 'table', text: strictNormalize(text), cells, links }, table, table);
581
+ pushBlock(ctx, { type: 'table', text: strictNormalize(text), cells, links, ...(spanned ? { spanned: true } : {}) }, table, table);
543
582
  }
544
583
  function closestTable(el) {
545
584
  let cur = el.parent;
@@ -632,7 +671,7 @@ export function extractHtml(source, options = {}) {
632
671
  lineStarts.push(i + 1);
633
672
  if (profile === 'starlight')
634
673
  notes.push('Starlight profile: all associated tab panels are compared, including inactive panels; Expressive Code line boundaries and aside titles are retained.');
635
- const ctx = { profile, base, source, lineStarts, blocks: [], notes, root, listBase: 0, ordinals: new Map(), segments: new Map() };
674
+ const ctx = { profile, base, source, lineStarts, blocks: [], notes, root, listBase: 0, ordinals: new Map(), segments: new Map(), issues };
636
675
  // A selector that picks a heading, list item, table or pre keeps that block type, so the root goes
637
676
  // through handleBlock. Every other root is read as a container, a list included: handleBlock's list
638
677
  // branch reads only <li> children, and a root list would lose any other content it holds.
@@ -59,7 +59,11 @@ function inlineChildren(ctx, children, run, line) {
59
59
  // HTML side. Up to 0.2.12 only the tags were dropped and the text between them stayed (found by an outside review
60
60
  // 2026-09-26). Its content up to the matching closing tag is left out; without one the tag is reported.
61
61
  if (!tag.closing && (tag.attribs['hidden'] !== undefined || tag.attribs['aria-hidden'] === 'true')) {
62
- if (VOID_TAGS.has(tag.name) || /\/>\s*$/.test(node.value))
62
+ // A trailing "/>" on a non-void element is not a self-close in HTML: <span hidden/>text</span> does not
63
+ // show "text" in a browser either, only a void element's own tag ends there. Up to 0.2.15 the slash alone
64
+ // was read as a close, so a malformed but common self-closing spelling left hidden text visible (0.2.16,
65
+ // found by an outside review 2026-09-28).
66
+ if (VOID_TAGS.has(tag.name))
63
67
  continue;
64
68
  closes ??= closingTags(children);
65
69
  const end = closes.get(i) ?? -1;
@@ -28,6 +28,10 @@ export interface Block {
28
28
  depth?: number;
29
29
  /** Table cells row by row, strictly normalized. Only for type 'table'. */
30
30
  cells?: string[][];
31
+ /** Only for type 'table', HTML side: a cell carries a rowspan or colspan, so a plain row/column reading cannot
32
+ * place its value reliably. compare.ts skips the cell-by-cell check for this block and relies on the
33
+ * EXTRACTION_TABLE_SPAN_NOT_COMPARED issue extraction already raised (0.2.16). */
34
+ spanned?: boolean;
31
35
  /** Code content after normalizeCode: line endings normalized to LF and trailing newlines removed. Only for type 'code'. */
32
36
  code?: string;
33
37
  /** Where a list item sits in its list. Only for type 'listItem' (0.2.13). */
@@ -2,10 +2,17 @@ export declare function strictNormalize(text: string): string;
2
2
  export declare function looseNormalize(text: string): string;
3
3
  /** Code content: CRLF and CR line endings become LF and every trailing newline is removed; other whitespace is kept. */
4
4
  export declare function normalizeCode(code: string): string;
5
+ /** Removes ANSI escape sequences and other C0 controls from a value that may come from a compared page or a raw
6
+ * argument, so a plain --format text report cannot replay them at the terminal (0.2.16, found by an outside
7
+ * review 2026-09-28). */
8
+ export declare function stripControlChars(text: string): string;
5
9
  /** Extracts numeric tokens (prices, percentages, dates, versions, signed values) in source order. */
6
10
  export declare function extractNumbers(text: string): string[];
7
11
  /** Report excerpt: URLs inside the text are masked BEFORE truncation, so a cut query value cannot leak. */
8
12
  export declare function excerpt(text: string, max?: number): string;
13
+ /** Masks a "scheme://(name):secret@" userinfo, leaving the scheme and an unmasked "***@" behind so the rest of
14
+ * the URL (host, path, query, fragment) reaches the ordinary run-based masking below as one unbroken run. */
15
+ export declare function maskParenUserinfo(text: string): string;
9
16
  /**
10
17
  * Whether position at of a source text lies in a part of a URL that maskHref hides: user information, a query
11
18
  * value or the fragment. GFM links a bare address it finds inside another URL on its own: the part after the
@@ -16,7 +23,10 @@ export declare function excerpt(text: string, max?: number): string;
16
23
  * on the side of masking.
17
24
  */
18
25
  export declare function insideHiddenUrlPart(text: string, at: number): boolean;
19
- /** Masks user information, query values and fragments of every URL-like run in a piece of report text. */
26
+ /** Masks user information, query values and fragments of every URL-like run in a piece of report text.
27
+ * maskParenUserinfo runs first for the parenthesized-userinfo shape RUN cannot see as one run, and
28
+ * stripControlChars runs last so a raw ANSI escape from a compared page or an argument cannot reach a plain
29
+ * --format text report (0.2.16, found by an outside review 2026-09-28). */
20
30
  export declare function redactText(text: string): string;
21
31
  /**
22
32
  * The text with the parts that maskHref hides taken out of every URL-like run: user information, query values
@@ -34,6 +34,17 @@ export function looseNormalize(text) {
34
34
  export function normalizeCode(code) {
35
35
  return code.replace(/\r\n?/g, '\n').replace(/\n+$/, '');
36
36
  }
37
+ // Terminal control characters (ANSI escape sequences and other C0 controls) reach a text report unescaped if a
38
+ // compared page or an argument carries one, while --format json is already safe because JSON.stringify escapes
39
+ // every control character. Tab, newline and carriage return are kept: they are ordinary formatting, and by the
40
+ // time most report text reaches this point strictNormalize has already collapsed them to a single space anyway.
41
+ const CONTROL_CHARS = /[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g;
42
+ /** Removes ANSI escape sequences and other C0 controls from a value that may come from a compared page or a raw
43
+ * argument, so a plain --format text report cannot replay them at the terminal (0.2.16, found by an outside
44
+ * review 2026-09-28). */
45
+ export function stripControlChars(text) {
46
+ return text.replace(CONTROL_CHARS, '');
47
+ }
37
48
  // A numeric token: optional sign (ASCII hyphen, Unicode minus or plus) that is not preceded by a letter
38
49
  // or digit (so the "-09" in 2026-09-10 is a separator, not a sign), digits with inner separators
39
50
  // (decimal, thousands, date, time, version), optional percent or currency sign on either side.
@@ -258,6 +269,33 @@ function rewriteUrlRuns(text, rewrite) {
258
269
  }
259
270
  // How far insideHiddenUrlPart reads the token around a position. A longer token counts as hidden.
260
271
  const HIDDEN_SCAN = 4096;
272
+ // A userinfo wrapped in parentheses right after "scheme://", such as scheme://(name):secret@host, is not a
273
+ // URL-like run under RUN above, because "(" and ")" split runs there: "scheme://", the parenthesized name and
274
+ // the rest starting at the colon become three separate runs, and none of them alone looks like a URL with user
275
+ // information (found by an outside review 2026-09-28). This pattern is narrow and every quantifier is bounded on
276
+ // purpose, so it stays linear by itself and is checked before the general run-splitting scan, not folded into it.
277
+ const PAREN_USERINFO = /\b([a-z][a-z0-9+.-]{0,15}):\/\/\(([^()\s]{0,256})\):([^@\s<>"'()]{0,1024})@/giu;
278
+ /** Masks a "scheme://(name):secret@" userinfo, leaving the scheme and an unmasked "***@" behind so the rest of
279
+ * the URL (host, path, query, fragment) reaches the ordinary run-based masking below as one unbroken run. */
280
+ export function maskParenUserinfo(text) {
281
+ return text.replace(PAREN_USERINFO, (_m, scheme) => `${scheme}://***@`);
282
+ }
283
+ /** Whether position `at` falls inside the parenthesized name or the secret of a PAREN_USERINFO match, the same
284
+ * shape maskParenUserinfo hides. The search window is the same HIDDEN_SCAN bound insideHiddenUrlPart itself uses,
285
+ * so a link deep inside a large document does not rescan the whole source. */
286
+ function insideParenUserinfo(text, at) {
287
+ const from = Math.max(0, at - HIDDEN_SCAN);
288
+ const to = Math.min(text.length, at + HIDDEN_SCAN);
289
+ const window = text.slice(from, to);
290
+ const re = new RegExp(PAREN_USERINFO.source, PAREN_USERINFO.flags);
291
+ for (let m = re.exec(window); m !== null; m = re.exec(window)) {
292
+ const hiddenStart = from + m.index + m[1].length + 3; // scheme + "://", at the "("
293
+ const hiddenEnd = from + m.index + m[0].length - 1; // at the "@"
294
+ if (at >= hiddenStart && at < hiddenEnd)
295
+ return true;
296
+ }
297
+ return false;
298
+ }
261
299
  /**
262
300
  * Whether position at of a source text lies in a part of a URL that maskHref hides: user information, a query
263
301
  * value or the fragment. GFM links a bare address it finds inside another URL on its own: the part after the
@@ -268,6 +306,8 @@ const HIDDEN_SCAN = 4096;
268
306
  * on the side of masking.
269
307
  */
270
308
  export function insideHiddenUrlPart(text, at) {
309
+ if (insideParenUserinfo(text, at))
310
+ return true;
271
311
  const isEdge = (i) => {
272
312
  const ch = text[i];
273
313
  return ch === '<' || ch === '>' || /\s/u.test(ch);
@@ -302,9 +342,12 @@ export function insideHiddenUrlPart(text, at) {
302
342
  }
303
343
  return false;
304
344
  }
305
- /** Masks user information, query values and fragments of every URL-like run in a piece of report text. */
345
+ /** Masks user information, query values and fragments of every URL-like run in a piece of report text.
346
+ * maskParenUserinfo runs first for the parenthesized-userinfo shape RUN cannot see as one run, and
347
+ * stripControlChars runs last so a raw ANSI escape from a compared page or an argument cannot reach a plain
348
+ * --format text report (0.2.16, found by an outside review 2026-09-28). */
306
349
  export function redactText(text) {
307
- return rewriteUrlRuns(text, maskHref);
350
+ return stripControlChars(rewriteUrlRuns(maskParenUserinfo(text), maskHref));
308
351
  }
309
352
  /**
310
353
  * The text with the parts that maskHref hides taken out of every URL-like run: user information, query values
@@ -1,2 +1,2 @@
1
1
  export declare const TOOL_NAME = "markdown-parity-check";
2
- export declare const TOOL_VERSION = "0.2.15";
2
+ export declare const TOOL_VERSION = "0.2.16";
@@ -2,4 +2,4 @@
2
2
  // Cloudflare Worker as well as under Node.js. test/version.test.ts fails the build when these differ
3
3
  // from package.json, which stays the version the release workflow publishes.
4
4
  export const TOOL_NAME = 'markdown-parity-check';
5
- export const TOOL_VERSION = '0.2.15';
5
+ export const TOOL_VERSION = '0.2.16';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markdown-parity-check",
3
- "version": "0.2.15",
3
+ "version": "0.2.16",
4
4
  "description": "Compares the main content of a web page's HTML and Markdown representations and reports concrete differences.",
5
5
  "keywords": [
6
6
  "markdown",