markdown-parity-check 0.2.5 → 0.2.6

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/dist/src/align.js CHANGED
@@ -1,7 +1,8 @@
1
1
  // Block alignment between the HTML block list (A) and the Markdown block list (B).
2
2
  // 1. Exact matches in order (LCS over strict keys) preserve duplicates and order.
3
3
  // 2. Remaining exact-key blocks are paired as moved blocks (order changed).
4
- // 3. Remaining blocks of the same type are paired by loose-key equality, then by token similarity.
4
+ // 3. Remaining blocks in the same typeGroup (paragraphs and list items share one) are paired by loose-key
5
+ // equality, then by token similarity.
5
6
  // Everything left is missing (HTML only) or added (Markdown only).
6
7
  /** paragraph and listItem are one group for alignment: a list rendered as paragraphs is a structure
7
8
  * difference, not missing content. */
@@ -165,9 +166,10 @@ export function align(a, b, limits) {
165
166
  usedB.add(j);
166
167
  }
167
168
  }
168
- // Similar pairs: greedy best-match by similarity above the threshold, same type only. Ties are broken
169
- // by document order to keep results deterministic. Token counts are computed once per block, and the
170
- // candidate list is bounded by MAX_SIMILARITY_CANDIDATES.
169
+ // Similar pairs: greedy best match by similarity within the same typeGroup, keeping scores at or above
170
+ // SIMILARITY_THRESHOLD. Ties are broken by document order to keep results deterministic. Token counts are
171
+ // computed once per block, and the candidate list is bounded by the configured maxSimilarityCandidates
172
+ // (MAX_SIMILARITY_CANDIDATES by default).
171
173
  const freeA = [];
172
174
  const freeBs = [];
173
175
  for (let i = 0; i < a.length; i++)
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.5\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 --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.6\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 --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 {
@@ -1,6 +1,6 @@
1
1
  // The comparison core: aligns blocks and turns the alignment into findings. Pure and network-free.
2
2
  import { align, UNCERTAIN_THRESHOLD } from './align.js';
3
- import { excerpt, hrefDifference, maskHref, redactText } from './normalize.js';
3
+ import { excerpt, hrefDifference, maskHref, redactText, relativeHrefRelation } from './normalize.js';
4
4
  function side(b) {
5
5
  return { line: b.location.line, path: b.location.path, blockIndex: b.location.blockIndex, excerpt: excerpt(b.type === 'code' ? (b.code ?? b.text) : b.text) };
6
6
  }
@@ -59,8 +59,13 @@ function compareLinks(out, h, m, bothBases) {
59
59
  const diff = hrefDifference(hl.resolved, ml.resolved);
60
60
  out.push({ code: 'LINK_TARGET_CHANGED', severity: 'error', direction: 'both', message: `Link "${redactText(hl.text)}" points to a different target (${diff} differs).`, html: side(h), markdown: side(m), before: maskHref(hl.resolved), after: maskHref(ml.resolved) });
61
61
  }
62
+ else if (hl.resolved === null && ml.resolved === null && relativeHrefRelation(hl.rawHref, ml.rawHref) === 'uncertain') {
63
+ // Neither side resolved and no base could be ruled out as making them meet. A textual difference
64
+ // alone does not establish different destinations, so this is a warning and not an error.
65
+ out.push({ code: 'LINK_UNVERIFIED', severity: 'warning', direction: 'both', message: `Link "${redactText(hl.text)}" differs textually and no base URL is known, so the two relative forms cannot be confirmed equal or different.`, html: side(h), markdown: side(m), before: maskHref(hl.rawHref), after: maskHref(ml.rawHref) });
66
+ }
62
67
  else if (hl.resolved === null && ml.resolved === null) {
63
- // Both relative and textually different: they differ under any common base.
68
+ // Neither side resolved, and relativeHrefRelation found a difference no base can remove.
64
69
  const diff = hrefDifference(hl.rawHref, ml.rawHref);
65
70
  out.push({ code: 'LINK_TARGET_CHANGED', severity: 'error', direction: 'both', message: `Link "${redactText(hl.text)}" points to a different relative target (${diff} differs).`, html: side(h), markdown: side(m), before: maskHref(hl.rawHref), after: maskHref(ml.rawHref) });
66
71
  }
@@ -75,6 +80,8 @@ function compareLinks(out, h, m, bothBases) {
75
80
  function sameTarget(a, b) {
76
81
  if (a.resolved !== null && b.resolved !== null)
77
82
  return a.resolved === b.resolved;
83
+ if (a.resolved === null && b.resolved === null)
84
+ return relativeHrefRelation(a.rawHref, b.rawHref) === 'same';
78
85
  return a.rawHref.trim() === b.rawHref.trim();
79
86
  }
80
87
  function compareTables(out, h, m) {
@@ -17,15 +17,15 @@ export interface Location {
17
17
  }
18
18
  export interface Block {
19
19
  type: BlockType;
20
- /** Strictly normalized comparison text (case and content characters preserved). */
20
+ /** Comparison text after strictNormalize: case kept, NFC applied, ZERO_WIDTH characters removed, whitespace collapsed. */
21
21
  text: string;
22
- /** Loosely normalized text used only for alignment. */
22
+ /** Loosely normalized text, used for alignment and to classify minor text differences. */
23
23
  loose: string;
24
24
  /** Heading depth 1..6 for headings. */
25
25
  depth?: number;
26
26
  /** Table cells row by row, strictly normalized. Only for type 'table'. */
27
27
  cells?: string[][];
28
- /** Raw code content with whitespace preserved. Only for type 'code'. */
28
+ /** Code content after normalizeCode: line endings normalized to LF and trailing newlines removed. Only for type 'code'. */
29
29
  code?: string;
30
30
  links: Link[];
31
31
  numbers: string[];
@@ -1,6 +1,6 @@
1
1
  export declare function strictNormalize(text: string): string;
2
2
  export declare function looseNormalize(text: string): string;
3
- /** Code content: normalize line endings and strip a trailing newline only. */
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
5
  /** Extracts numeric tokens (prices, percentages, dates, versions, signed values) in source order. */
6
6
  export declare function extractNumbers(text: string): string[];
@@ -17,3 +17,22 @@ export declare function maskUrl(url: string): string;
17
17
  export declare function maskHref(href: string): string;
18
18
  /** Describes how two hrefs differ without revealing masked parts. */
19
19
  export declare function hrefDifference(a: string, b: string): string;
20
+ export type HrefRelation = 'same' | 'different' | 'uncertain';
21
+ /**
22
+ * How two references relate when neither could be resolved, which is the case for two relative
23
+ * links and no base URL. A textual difference alone does not make two targets different: ./guide
24
+ * and guide are the same address under every base.
25
+ *
26
+ * 'same': the two resolve equal under synthetic bases that cover every way a base takes part in
27
+ * resolution, so they are equal under any base. The bases are two origins with different schemes, and
28
+ * for each, two sets of names that share none (directory segment, file and query), each used as a
29
+ * directory, a file and a file with a query, all deeper than any ".." segment in either reference. Two
30
+ * name sets are needed because a reference that climbs above its start and descends again, such as
31
+ * ../d//.., reuses the base's own segment names: under one set it can equal a different reference
32
+ * (found by an independent property test 2026-09-12 before 0.2.6 was released).
33
+ * 'different': the difference cannot depend on the base, because both are network-path references,
34
+ * both are absolute-path references, or both are relative-path references with a non-empty path and
35
+ * no ".." segment. 'uncertain': anything else, because some base could make the two meet
36
+ * (../guide and guide are equal at the root, ?q and ./?q under a directory base).
37
+ */
38
+ export declare function relativeHrefRelation(a: string, b: string): HrefRelation;
@@ -1,5 +1,6 @@
1
- // Text normalization. Strict normalization preserves case and content characters; loose normalization is
2
- // used only as an alignment aid.
1
+ // Text normalization. Strict normalization preserves case, applies NFC, removes the characters in ZERO_WIDTH,
2
+ // maps the spaces in NBSP to a plain space and collapses whitespace. Loose normalization aligns blocks and
3
+ // classifies minor text differences (TEXT_MINOR_CHANGED).
3
4
  const NBSP = /[\u00a0\u2007\u202f]/g;
4
5
  const WS = /[ \t\r\n\f\v]+/g;
5
6
  const ZERO_WIDTH = /[\u200b-\u200d\ufeff\u00ad]/g;
@@ -23,7 +24,7 @@ export function looseNormalize(text) {
23
24
  .replace(/\s+/g, ' ')
24
25
  .trim();
25
26
  }
26
- /** Code content: normalize line endings and strip a trailing newline only. */
27
+ /** Code content: CRLF and CR line endings become LF and every trailing newline is removed; other whitespace is kept. */
27
28
  export function normalizeCode(code) {
28
29
  return code.replace(/\r\n?/g, '\n').replace(/\n+$/, '');
29
30
  }
@@ -222,3 +223,60 @@ export function hrefDifference(a, b) {
222
223
  parts.push('fragment');
223
224
  return parts.length ? parts.join(', ') : 'nothing visible';
224
225
  }
226
+ /**
227
+ * How two references relate when neither could be resolved, which is the case for two relative
228
+ * links and no base URL. A textual difference alone does not make two targets different: ./guide
229
+ * and guide are the same address under every base.
230
+ *
231
+ * 'same': the two resolve equal under synthetic bases that cover every way a base takes part in
232
+ * resolution, so they are equal under any base. The bases are two origins with different schemes, and
233
+ * for each, two sets of names that share none (directory segment, file and query), each used as a
234
+ * directory, a file and a file with a query, all deeper than any ".." segment in either reference. Two
235
+ * name sets are needed because a reference that climbs above its start and descends again, such as
236
+ * ../d//.., reuses the base's own segment names: under one set it can equal a different reference
237
+ * (found by an independent property test 2026-09-12 before 0.2.6 was released).
238
+ * 'different': the difference cannot depend on the base, because both are network-path references,
239
+ * both are absolute-path references, or both are relative-path references with a non-empty path and
240
+ * no ".." segment. 'uncertain': anything else, because some base could make the two meet
241
+ * (../guide and guide are equal at the root, ?q and ./?q under a directory base).
242
+ */
243
+ export function relativeHrefRelation(a, b) {
244
+ const x = a.trim();
245
+ const y = b.trim();
246
+ if (x === y)
247
+ return 'same';
248
+ const pathOf = (h) => h.replace(/\\/g, '/').split(/[?#]/, 1)[0] ?? '';
249
+ const dotDots = (h) => pathOf(h).split('/').filter((s) => /^(?:\.|%2e){2}$/i.test(s)).length;
250
+ const depth = Math.max(dotDots(x), dotDots(y)) + 1;
251
+ const bases = [];
252
+ for (const origin of ['https://base.invalid/', 'http://other.invalid/']) {
253
+ for (const [segment, file, query] of [['d', 'f', '?q'], ['e', 'g', '?r']]) {
254
+ const dir = origin + `${segment}/`.repeat(depth);
255
+ bases.push(dir, dir + file, dir + file + query);
256
+ }
257
+ }
258
+ const resolveAll = (h) => {
259
+ try {
260
+ return bases.map((base) => new URL(h, base).href).join(' ');
261
+ }
262
+ catch {
263
+ return null;
264
+ }
265
+ };
266
+ const rx = resolveAll(x);
267
+ const ry = resolveAll(y);
268
+ if (rx === null || ry === null)
269
+ return 'different';
270
+ if (rx === ry)
271
+ return 'same';
272
+ const kind = (h) => {
273
+ const p = h.replace(/\\/g, '/');
274
+ if (p.startsWith('//'))
275
+ return 'network';
276
+ if (p.startsWith('/'))
277
+ return 'absolute';
278
+ return pathOf(h) !== '' && dotDots(h) === 0 ? 'relative' : 'base-dependent';
279
+ };
280
+ const kx = kind(x);
281
+ return kx !== 'base-dependent' && kx === kind(y) ? 'different' : 'uncertain';
282
+ }
@@ -1,2 +1,2 @@
1
1
  export declare const TOOL_NAME = "markdown-parity-check";
2
- export declare const TOOL_VERSION = "0.2.5";
2
+ export declare const TOOL_VERSION = "0.2.6";
@@ -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.5';
5
+ export const TOOL_VERSION = '0.2.6';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markdown-parity-check",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
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",