markdown-parity-check 0.2.4 → 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/README.md +2 -2
- package/dist/src/align.js +6 -4
- package/dist/src/cli.d.ts +1 -1
- package/dist/src/compare.js +9 -2
- package/dist/src/model.d.ts +3 -3
- package/dist/src/normalize.d.ts +20 -1
- package/dist/src/normalize.js +61 -3
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ Compare the main content of a page's HTML and Markdown versions. The report list
|
|
|
4
4
|
|
|
5
5
|
## Try it in the browser
|
|
6
6
|
|
|
7
|
-
The [hosted Markdown parity check](https://turva.dev/markdown-parity-check) runs this comparison on turva.dev. It currently checks the published pages of turva.dev only. An address on any other site is refused with a message that points to the command-line tool below.
|
|
7
|
+
The [hosted Markdown parity check](https://turva.dev/markdown-parity-check) runs this comparison on turva.dev. It currently checks the published pages of turva.dev only, and the page states that limit in its opening paragraph and again at the address field. An address on any other site is refused with a message that points to the command-line tool below. Fill in an example puts turva.dev's own tools page in the address field, and Check runs the comparison as a separate step.
|
|
8
8
|
|
|
9
9
|
## Check your own site
|
|
10
10
|
|
|
@@ -83,7 +83,7 @@ Both use the comparison core of this package. They differ in which pages they re
|
|
|
83
83
|
|
|
84
84
|
The hosted page also answers a JSON POST, described on the page. It runs the release of this package pinned in [turva-worker](https://github.com/erekola/turva-worker), which can be older than the latest npm release. The report's `toolVersion` field shows which release produced it.
|
|
85
85
|
|
|
86
|
-
A hosted check can fail on turva.dev's own pages as well. On 2026-09-11 the check of https://turva.dev/tools returned `fail` with five errors. The Markdown carries a Related heading and four links that the HTML page
|
|
86
|
+
A hosted check can fail on turva.dev's own pages as well. On 2026-09-11 the check of https://turva.dev/tools returned `fail` with five errors. The Markdown carries a Related heading and four links that the HTML page does not repeat as a list, and the report listed each of them. The same four targets are links inside that page's tool cards, so the report found a missing structure and not missing content. [HTML and Markdown can disagree](https://turva.dev/blog/html-and-markdown-can-disagree) reads that result in full.
|
|
87
87
|
|
|
88
88
|
## Library use
|
|
89
89
|
|
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
|
|
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
|
|
169
|
-
// by document order to keep results deterministic. Token counts are
|
|
170
|
-
// candidate list is bounded by
|
|
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.
|
|
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 {
|
package/dist/src/compare.js
CHANGED
|
@@ -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
|
-
//
|
|
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) {
|
package/dist/src/model.d.ts
CHANGED
|
@@ -17,15 +17,15 @@ export interface Location {
|
|
|
17
17
|
}
|
|
18
18
|
export interface Block {
|
|
19
19
|
type: BlockType;
|
|
20
|
-
/**
|
|
20
|
+
/** Comparison text after strictNormalize: case kept, NFC applied, ZERO_WIDTH characters removed, whitespace collapsed. */
|
|
21
21
|
text: string;
|
|
22
|
-
/** Loosely normalized text used
|
|
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
|
-
/**
|
|
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[];
|
package/dist/src/normalize.d.ts
CHANGED
|
@@ -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:
|
|
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;
|
package/dist/src/normalize.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
// Text normalization. Strict normalization preserves case
|
|
2
|
-
//
|
|
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:
|
|
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
|
+
}
|
package/dist/src/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const TOOL_NAME = "markdown-parity-check";
|
|
2
|
-
export declare const TOOL_VERSION = "0.2.
|
|
2
|
+
export declare const TOOL_VERSION = "0.2.6";
|
package/dist/src/version.js
CHANGED
|
@@ -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
|
+
export const TOOL_VERSION = '0.2.6';
|
package/package.json
CHANGED