markdown-parity-check 0.2.9 → 0.2.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/README.md +1 -1
- package/SECURITY.md +1 -1
- package/dist/src/cli.d.ts +1 -1
- package/dist/src/compare.js +12 -2
- package/dist/src/html.js +7 -1
- package/dist/src/normalize.d.ts +18 -4
- package/dist/src/normalize.js +121 -19
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -68,7 +68,7 @@ Headings, paragraphs, list items, tables, code blocks and links are compared blo
|
|
|
68
68
|
|
|
69
69
|
In URL mode the Markdown response is checked first. An HTTP error or an HTML page in place of Markdown fails the check, and nothing is compared.
|
|
70
70
|
|
|
71
|
-
JavaScript is not executed. Content that a page builds in the browser is compared as the server sent it. Block matching is heuristic, so some layouts need an explicit selector. Reports mask URL query values
|
|
71
|
+
JavaScript is not executed. Content that a page builds in the browser is compared as the server sent it. Block matching is heuristic, so some layouts need an explicit selector. Reports mask URL query values and fragments and remove any user name or password from a URL. Excerpts may still contain private page content. Review a report before you share it.
|
|
72
72
|
|
|
73
73
|
## Command line and hosted page
|
|
74
74
|
|
package/SECURITY.md
CHANGED
|
@@ -16,7 +16,7 @@ URL mode requests HTML and Markdown over HTTP or HTTPS. Non-public network targe
|
|
|
16
16
|
|
|
17
17
|
The comparison work is bounded by the product of the two block counts, at most 4 000 000 block pairs. The number of similar block pairs kept for matching is bounded as well. Above either limit the tool stops with exit code 2 and an error message instead of reporting a pass for a comparison it did not complete.
|
|
18
18
|
|
|
19
|
-
Offline mode reads the two files supplied by the caller. The output option writes a report to the selected path. Reports mask URL query values
|
|
19
|
+
Offline mode reads the two files supplied by the caller. The output option writes a report to the selected path. Reports mask URL query values and fragments and remove any user name or password from a URL. Excerpts may contain private page content. Review reports before sharing them.
|
|
20
20
|
|
|
21
21
|
## Dependencies and releases
|
|
22
22
|
|
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.11\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/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, relativeHrefRelation } from './normalize.js';
|
|
3
|
+
import { excerpt, hrefDifference, maskHref, redactText, relativeHrefRelation, visibleNumbers } 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
|
}
|
|
@@ -133,7 +133,17 @@ function comparePair(out, p, h, m, bothBases) {
|
|
|
133
133
|
else if (h.text !== m.text) {
|
|
134
134
|
const nd = diffNumbers(h.numbers, m.numbers);
|
|
135
135
|
if (nd) {
|
|
136
|
-
|
|
136
|
+
// Block.numbers holds every numeric token, also one inside a URL's query value, fragment or user
|
|
137
|
+
// information, so a change there is still a number change and the classification does not move. What the
|
|
138
|
+
// finding shows is read again from the text with those parts taken out, because the report masks them and
|
|
139
|
+
// a bare number is not recognisable as part of a URL at the reporting boundary (0.2.10).
|
|
140
|
+
const shown = diffNumbers(visibleNumbers(h.text), visibleNumbers(m.text));
|
|
141
|
+
if (shown) {
|
|
142
|
+
out.push({ code: 'NUMBER_CHANGED', severity: 'error', direction: 'both', message: `Numeric value differs in the ${label(h)}: ${shown.before.join(', ') || '(none)'} in HTML, ${shown.after.join(', ') || '(none)'} in Markdown.`, html: side(h), markdown: side(m), before: shown.before.join(', '), after: shown.after.join(', ') });
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
out.push({ code: 'NUMBER_CHANGED', severity: 'error', direction: 'both', message: `Numeric value differs in the ${label(h)} inside a masked part of a URL (a query value, the fragment or user information), so the values are not shown.`, html: side(h), markdown: side(m) });
|
|
146
|
+
}
|
|
137
147
|
}
|
|
138
148
|
else if (h.loose === m.loose) {
|
|
139
149
|
out.push({ code: 'TEXT_MINOR_CHANGED', severity: 'warning', direction: 'both', message: `The ${label(h)} differs only in case, punctuation or typographic characters.`, html: side(h), markdown: side(m), before: excerpt(h.text), after: excerpt(m.text) });
|
package/dist/src/html.js
CHANGED
|
@@ -501,6 +501,12 @@ export function extractHtml(source, options = {}) {
|
|
|
501
501
|
if (profile === 'starlight')
|
|
502
502
|
notes.push('Starlight profile: all associated tab panels are compared, including inactive panels; Expressive Code line boundaries and aside titles are retained.');
|
|
503
503
|
const ctx = { profile, base, source, lineStarts, blocks: [], notes, root };
|
|
504
|
-
|
|
504
|
+
// A selector that picks a heading, list item, table or pre keeps that block type, so the root goes
|
|
505
|
+
// through handleBlock. Every other root is read as a container, a list included: handleBlock's list
|
|
506
|
+
// branch reads only <li> children, and a root list would lose any other content it holds.
|
|
507
|
+
if (HEADING_RE.test(root.name) || root.name === 'li' || root.name === 'table' || root.name === 'pre')
|
|
508
|
+
handleBlock(ctx, root);
|
|
509
|
+
else
|
|
510
|
+
walk(ctx, root);
|
|
505
511
|
return { blocks: ctx.blocks, strategy: profile === 'generic' ? strategy : `${strategy};profile:starlight`, confidence, notes, issues: [] };
|
|
506
512
|
}
|
package/dist/src/normalize.d.ts
CHANGED
|
@@ -6,14 +6,28 @@ export declare function normalizeCode(code: string): string;
|
|
|
6
6
|
export declare function extractNumbers(text: string): string[];
|
|
7
7
|
/** Report excerpt: URLs inside the text are masked BEFORE truncation, so a cut query value cannot leak. */
|
|
8
8
|
export declare function excerpt(text: string, max?: number): string;
|
|
9
|
-
/** Masks query values and fragments of every URL-like run in a piece of report text. */
|
|
9
|
+
/** Masks user information, query values and fragments of every URL-like run in a piece of report text. */
|
|
10
10
|
export declare function redactText(text: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* The text with the parts that maskHref hides taken out of every URL-like run: user information, query values
|
|
13
|
+
* and the fragment. Nothing else moves, and nothing is normalized, so every other number stays as it was.
|
|
14
|
+
*/
|
|
15
|
+
export declare function hideUrlSecrets(text: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* The numeric tokens a report may show. extractNumbers reads the whole text, so a numeric query value, such as
|
|
18
|
+
* an access token in a link printed on the page, is among them, and the recursive report redactor does not
|
|
19
|
+
* recognise a bare number as part of a URL. A value is reported only when it survives the URL masking (found
|
|
20
|
+
* by an outside review 2026-09-22).
|
|
21
|
+
*/
|
|
22
|
+
export declare function visibleNumbers(text: string): string[];
|
|
11
23
|
/** Resolves a possibly relative href against a base. Returns null when it cannot be resolved. */
|
|
12
24
|
export declare function resolveHref(rawHref: string, base: string | null): string | null;
|
|
13
|
-
/** Masks query values
|
|
14
|
-
* query of an unparseable input either. */
|
|
25
|
+
/** Masks query values, drops the fragment and removes user information for display in reports and logs.
|
|
26
|
+
* Never returns the raw query or the credentials of an unparseable input either. */
|
|
15
27
|
export declare function maskUrl(url: string): string;
|
|
16
|
-
/** Masks query values
|
|
28
|
+
/** Masks query values, drops the fragment and removes user information of an absolute or relative href for
|
|
29
|
+
* display. The user name goes with the password, because either one can be the secret. Up to 0.2.9 both
|
|
30
|
+
* stayed in the output, and so in the error of a refused URL (found by an outside review 2026-09-22). */
|
|
17
31
|
export declare function maskHref(href: string): string;
|
|
18
32
|
/** Describes how two hrefs differ without revealing masked parts. */
|
|
19
33
|
export declare function hrefDifference(a: string, b: string): string;
|
package/dist/src/normalize.js
CHANGED
|
@@ -125,10 +125,33 @@ function urlStart(t, s, e) {
|
|
|
125
125
|
best = p;
|
|
126
126
|
break;
|
|
127
127
|
}
|
|
128
|
+
// [\/\\]{2}[^\s<>"'()\/\\?#]*@ An authority that carries user information (0.2.10): the first pair of
|
|
129
|
+
// slashes or backslashes whose authority, up to the next / \ ? or #, holds an '@'. Without it
|
|
130
|
+
// //user:secret@host/path passed through a report unmasked, because no other alternative reads a run without
|
|
131
|
+
// a scheme, query or fragment, and neither did https:\\user:secret@host, because the scheme alternative wants
|
|
132
|
+
// "://". A failed candidate is scanned only to its own delimiter, so the scans do not overlap.
|
|
133
|
+
const isSep = (c) => c === 0x2f || c === 0x5c;
|
|
134
|
+
for (let p = s; p + 2 < e && (best < 0 || p < best); p++) {
|
|
135
|
+
if (!isSep(t.charCodeAt(p)) || !isSep(t.charCodeAt(p + 1)))
|
|
136
|
+
continue;
|
|
137
|
+
let k = p + 2;
|
|
138
|
+
while (k < e) {
|
|
139
|
+
const c = t.charCodeAt(k);
|
|
140
|
+
if (c === 0x2f || c === 0x5c || c === 0x3f || c === 0x23 || c === 0x40)
|
|
141
|
+
break;
|
|
142
|
+
k++;
|
|
143
|
+
}
|
|
144
|
+
if (k < e && t.charCodeAt(k) === 0x40) {
|
|
145
|
+
best = p;
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
if (k > p + 2)
|
|
149
|
+
p = k - 1;
|
|
150
|
+
}
|
|
128
151
|
return best;
|
|
129
152
|
}
|
|
130
|
-
/**
|
|
131
|
-
|
|
153
|
+
/** Rewrites the URL-like part of every run in a piece of text and leaves the rest untouched. */
|
|
154
|
+
function rewriteUrlRuns(text, rewrite) {
|
|
132
155
|
let out = '';
|
|
133
156
|
let done = 0;
|
|
134
157
|
for (const run of text.matchAll(RUN)) {
|
|
@@ -141,11 +164,31 @@ export function redactText(text) {
|
|
|
141
164
|
let end = e;
|
|
142
165
|
while (end > p && TRAIL.includes(text[end - 1]))
|
|
143
166
|
end--;
|
|
144
|
-
out += text.slice(done, p) +
|
|
167
|
+
out += text.slice(done, p) + rewrite(text.slice(p, end)) + text.slice(end, e);
|
|
145
168
|
done = e;
|
|
146
169
|
}
|
|
147
170
|
return out + text.slice(done);
|
|
148
171
|
}
|
|
172
|
+
/** Masks user information, query values and fragments of every URL-like run in a piece of report text. */
|
|
173
|
+
export function redactText(text) {
|
|
174
|
+
return rewriteUrlRuns(text, maskHref);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* The text with the parts that maskHref hides taken out of every URL-like run: user information, query values
|
|
178
|
+
* and the fragment. Nothing else moves, and nothing is normalized, so every other number stays as it was.
|
|
179
|
+
*/
|
|
180
|
+
export function hideUrlSecrets(text) {
|
|
181
|
+
return rewriteUrlRuns(text, withoutUrlSecrets);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* The numeric tokens a report may show. extractNumbers reads the whole text, so a numeric query value, such as
|
|
185
|
+
* an access token in a link printed on the page, is among them, and the recursive report redactor does not
|
|
186
|
+
* recognise a bare number as part of a URL. A value is reported only when it survives the URL masking (found
|
|
187
|
+
* by an outside review 2026-09-22).
|
|
188
|
+
*/
|
|
189
|
+
export function visibleNumbers(text) {
|
|
190
|
+
return extractNumbers(hideUrlSecrets(text));
|
|
191
|
+
}
|
|
149
192
|
/** Resolves a possibly relative href against a base. Returns null when it cannot be resolved. */
|
|
150
193
|
export function resolveHref(rawHref, base) {
|
|
151
194
|
const href = rawHref.trim();
|
|
@@ -166,33 +209,29 @@ export function resolveHref(rawHref, base) {
|
|
|
166
209
|
return null;
|
|
167
210
|
}
|
|
168
211
|
}
|
|
169
|
-
/** Masks query values
|
|
170
|
-
* query of an unparseable input either. */
|
|
212
|
+
/** Masks query values, drops the fragment and removes user information for display in reports and logs.
|
|
213
|
+
* Never returns the raw query or the credentials of an unparseable input either. */
|
|
171
214
|
export function maskUrl(url) {
|
|
172
|
-
|
|
173
|
-
const u = new URL(url);
|
|
174
|
-
for (const key of Array.from(u.searchParams.keys()))
|
|
175
|
-
u.searchParams.set(key, '***');
|
|
176
|
-
u.hash = '';
|
|
177
|
-
return u.href;
|
|
178
|
-
}
|
|
179
|
-
catch {
|
|
180
|
-
return maskHref(url);
|
|
181
|
-
}
|
|
215
|
+
return maskHref(url);
|
|
182
216
|
}
|
|
183
|
-
/** Masks query values
|
|
217
|
+
/** Masks query values, drops the fragment and removes user information of an absolute or relative href for
|
|
218
|
+
* display. The user name goes with the password, because either one can be the secret. Up to 0.2.9 both
|
|
219
|
+
* stayed in the output, and so in the error of a refused URL (found by an outside review 2026-09-22). */
|
|
184
220
|
export function maskHref(href) {
|
|
185
221
|
try {
|
|
186
222
|
const u = new URL(href);
|
|
223
|
+
u.username = '';
|
|
224
|
+
u.password = '';
|
|
187
225
|
for (const key of Array.from(u.searchParams.keys()))
|
|
188
226
|
u.searchParams.set(key, '***');
|
|
189
227
|
u.hash = '';
|
|
190
228
|
return u.href;
|
|
191
229
|
}
|
|
192
230
|
catch {
|
|
193
|
-
// Relative or unparseable: mask by hand.
|
|
194
|
-
const
|
|
195
|
-
|
|
231
|
+
// Relative, protocol-relative or unparseable: mask by hand.
|
|
232
|
+
const plain = withoutUserinfo(href);
|
|
233
|
+
const hashAt = plain.indexOf('#');
|
|
234
|
+
let h = hashAt >= 0 ? plain.slice(0, hashAt) : plain;
|
|
196
235
|
const q = h.indexOf('?');
|
|
197
236
|
if (q >= 0) {
|
|
198
237
|
const params = h.slice(q + 1).split('&').map((kv) => (kv === '' ? kv : `${kv.split('=')[0]}=***`));
|
|
@@ -201,6 +240,69 @@ export function maskHref(href) {
|
|
|
201
240
|
return h;
|
|
202
241
|
}
|
|
203
242
|
}
|
|
243
|
+
const SPECIAL_SCHEMES = new Set(['ftp', 'file', 'http', 'https', 'ws', 'wss']);
|
|
244
|
+
/**
|
|
245
|
+
* The href without its user information. The authority is found where the URL parser looks for it: after
|
|
246
|
+
* "scheme:" and any slashes or backslashes for a special scheme, after "//" for any other scheme, and after two
|
|
247
|
+
* slashes or backslashes when there is no scheme, because a relative reference in a web page resolves against
|
|
248
|
+
* an http or https base. When the parser reads the address, the user information ends at the last '@' before
|
|
249
|
+
* the authority ends, so an '@' in a path stays. When the parser refuses the address, nothing tells which '@'
|
|
250
|
+
* ends the user information, so everything up to the last '@' before the query or the fragment is shown as ***.
|
|
251
|
+
* The mask is visible on purpose. Three review rounds on 2026-09-22 measured every rule that guessed: stopping
|
|
252
|
+
* at the first slash returned a password that holds a slash, reading to the last '@' made a host vanish without
|
|
253
|
+
* a trace, and telling user:password from host:port by the digits did both. The
|
|
254
|
+
* string is first read the way the parser reads it (urlParserInput), so a tab or newline cannot hide a
|
|
255
|
+
* delimiter.
|
|
256
|
+
*/
|
|
257
|
+
function withoutUserinfo(href) {
|
|
258
|
+
const h = urlParserInput(href);
|
|
259
|
+
const scheme = /^[a-z][a-z0-9+.-]*:/i.exec(h);
|
|
260
|
+
const special = scheme === null || SPECIAL_SCHEMES.has(scheme[0].slice(0, -1).toLowerCase());
|
|
261
|
+
const isSlash = (c) => c === 0x2f || (special && c === 0x5c);
|
|
262
|
+
const from = scheme ? scheme[0].length : 0;
|
|
263
|
+
let j = from;
|
|
264
|
+
while (j < h.length && isSlash(h.charCodeAt(j)))
|
|
265
|
+
j++;
|
|
266
|
+
const hasAuthority = scheme === null ? j - from >= 2 : special || h.startsWith('//', from);
|
|
267
|
+
if (!hasAuthority)
|
|
268
|
+
return href;
|
|
269
|
+
if (scheme !== null && !special)
|
|
270
|
+
j = from + 2;
|
|
271
|
+
let parsed = null;
|
|
272
|
+
try {
|
|
273
|
+
parsed = new URL(h, scheme === null ? 'https://base.invalid/' : undefined);
|
|
274
|
+
}
|
|
275
|
+
catch {
|
|
276
|
+
parsed = null;
|
|
277
|
+
}
|
|
278
|
+
let at = -1;
|
|
279
|
+
for (let k = j; k < h.length; k++) {
|
|
280
|
+
const c = h.charCodeAt(k);
|
|
281
|
+
if (c === 0x3f || c === 0x23 || (parsed !== null && isSlash(c)))
|
|
282
|
+
break;
|
|
283
|
+
if (c === 0x40)
|
|
284
|
+
at = k;
|
|
285
|
+
}
|
|
286
|
+
if (at < 0)
|
|
287
|
+
return href;
|
|
288
|
+
return h.slice(0, j) + (parsed === null ? '***@' : '') + h.slice(at + 1);
|
|
289
|
+
}
|
|
290
|
+
/** The URL-like string with what maskHref hides taken out: user information, query values and the fragment.
|
|
291
|
+
* Query names stay, as they do in maskHref. */
|
|
292
|
+
function withoutUrlSecrets(url) {
|
|
293
|
+
let h = withoutUserinfo(url);
|
|
294
|
+
const hashAt = h.indexOf('#');
|
|
295
|
+
if (hashAt >= 0)
|
|
296
|
+
h = h.slice(0, hashAt);
|
|
297
|
+
const q = h.indexOf('?');
|
|
298
|
+
if (q < 0)
|
|
299
|
+
return h;
|
|
300
|
+
const params = h.slice(q + 1).split('&').map((kv) => {
|
|
301
|
+
const eq = kv.indexOf('=');
|
|
302
|
+
return eq < 0 ? kv : kv.slice(0, eq + 1);
|
|
303
|
+
});
|
|
304
|
+
return `${h.slice(0, q)}?${params.join('&')}`;
|
|
305
|
+
}
|
|
204
306
|
/** Describes how two hrefs differ without revealing masked parts. */
|
|
205
307
|
export function hrefDifference(a, b) {
|
|
206
308
|
const parse = (h) => {
|
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.11";
|
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.11';
|
package/package.json
CHANGED