markdown-parity-check 0.2.28 → 0.2.30
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 +7 -7
- package/SECURITY.md +1 -1
- package/dist/src/cli.d.ts +1 -1
- package/dist/src/cli.js +7 -3
- package/dist/src/deadline.d.ts +3 -0
- package/dist/src/deadline.js +60 -0
- package/dist/src/fetch.js +36 -1
- package/dist/src/html.d.ts +2 -2
- package/dist/src/html.js +49 -9
- package/dist/src/netguard.js +4 -0
- package/dist/src/normalize.d.ts +1 -1
- package/dist/src/normalize.js +15 -5
- package/dist/src/run-worker.d.ts +22 -0
- package/dist/src/run-worker.js +22 -0
- package/dist/src/run.d.ts +1 -1
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -69,7 +69,7 @@ Exit code 0 means the implemented checks found nothing to reject. It does not pr
|
|
|
69
69
|
| `--format text` or `--format json` | Print a readable report, which is the default, or a structured one. |
|
|
70
70
|
| `--output PATH` | Write the report to a file. An input file is never overwritten. |
|
|
71
71
|
| `--strict` | Treat warnings as rejecting findings. |
|
|
72
|
-
| `--timeout-ms MS` | Deadline
|
|
72
|
+
| `--timeout-ms MS` | Deadline for each request and for the parsing and comparison step. The default is 15 000 ms, and a run that passes it stops with exit code 2. The value must be a positive decimal integer no greater than 2147483647. |
|
|
73
73
|
| `--max-bytes N` | Limit on decoded bytes per response. The default is 5 MiB. The value must be a positive decimal integer no greater than 9007199254740991. |
|
|
74
74
|
| `--help`, `-h` | Print the help. |
|
|
75
75
|
| `--version`, `-V` | Print the version. |
|
|
@@ -78,10 +78,10 @@ A value that is outside these ranges, or that is not a plain run of digits, stop
|
|
|
78
78
|
|
|
79
79
|
### Example output
|
|
80
80
|
|
|
81
|
-
This is the text report for the matching fixture pair in this repository, run with version 0.2.
|
|
81
|
+
This is the text report for the matching fixture pair in this repository, run with version 0.2.30 on 2026-11-02. The exact command is in the Development section below. The text report ends with a list of limitations, which is omitted here:
|
|
82
82
|
|
|
83
83
|
```text
|
|
84
|
-
markdown-parity-check 0.2.
|
|
84
|
+
markdown-parity-check 0.2.30 (offline mode)
|
|
85
85
|
Result: PASS (0 error(s), 0 warning(s), 1 info)
|
|
86
86
|
|
|
87
87
|
HTML: test/fixtures/same/page.html (file, 1,017 bytes, base https://example.com/page)
|
|
@@ -110,7 +110,7 @@ Front matter is kept by default and compared as content. If the HTML does not ca
|
|
|
110
110
|
|
|
111
111
|
### Blocks and severities
|
|
112
112
|
|
|
113
|
-
Headings, paragraphs, list items, tables, code blocks and links are compared block by block. Content marked `hidden` or `aria-hidden="true"` is left out on both sides, also when a raw HTML wrapper such as `<div hidden>` is opened in one Markdown block and closed in a later one. A table caption counts as a paragraph before the table.
|
|
113
|
+
Headings, paragraphs, list items, tables, code blocks and links are compared block by block. A link that wraps block elements, such as a linked card with a heading and a paragraph, is compared as those blocks: each keeps its own type and heading level and carries the link, and the Markdown side is read the same way, so `## [Title](url)` is a heading with a link. In a table cell the link is read as part of the cell text. Content marked `hidden` or `aria-hidden="true"` is left out on both sides, also when a raw HTML wrapper such as `<div hidden>` is opened in one Markdown block and closed in a later one. A table caption counts as a paragraph before the table.
|
|
114
114
|
|
|
115
115
|
- Errors: missing and added blocks, a change in text or numbers, a changed table or link, and a list item that shows another number or a different checked or unchecked state.
|
|
116
116
|
- Warnings: a checkbox that is present on one side only, a difference in order, which is also reported for a block that moved and changed only in case, punctuation or typographic characters, and a difference in heading level, case, punctuation, list kind or nesting level. Each footnote in the Markdown is a warning, because footnotes are not compared. These are the main cases, and the `code` of each finding names the exact rule. A missing or extra copy of a repeated block is reported as a missing or added block, which is an error.
|
|
@@ -148,7 +148,7 @@ Both use the comparison core of this package. They differ in which pages they re
|
|
|
148
148
|
| Topic | Command-line tool | Hosted page |
|
|
149
149
|
| --- | --- | --- |
|
|
150
150
|
| Pages | Any public HTTP or HTTPS address, or two local files. | Published turva.dev pages only, except the two tool pages, this one and the llms.txt validator. |
|
|
151
|
-
| Fetching | Network requests from your machine. Non-public addresses are refused, also behind DNS and redirects. | The turva.dev Worker renders both versions itself, so a check sends no request over the network. |
|
|
151
|
+
| Fetching | Network requests from your machine. Non-public addresses are refused, also behind DNS and redirects. The tool connects directly to the validated address and does not use `HTTP_PROXY` or `HTTPS_PROXY`, so behind a mandatory proxy use the file mode. | The turva.dev Worker renders both versions itself, so a check sends no request over the network. |
|
|
152
152
|
| Response size | 5 MiB per response by default, adjustable with `--max-bytes`. | HTML up to 512 KiB. Markdown up to 128 KiB. |
|
|
153
153
|
| Comparison size | Up to 4 000 000 block pairs. | Up to 250 000 block pairs. |
|
|
154
154
|
| Rate | Not limited by the tool. | About 10 checks per minute from one IP address at each Cloudflare location. |
|
|
@@ -245,10 +245,10 @@ Only after that check does it create the GitHub release with the verified tarbal
|
|
|
245
245
|
GitHub Actions publishes every version from 0.1.2 on with npm trusted publishing, and each one carries a provenance attestation. To check one, install it in an empty directory and ask npm to verify the signatures. Replace the version with the one you want to check.
|
|
246
246
|
|
|
247
247
|
```sh
|
|
248
|
-
mkdir verify-mpc && cd verify-mpc && npm init -y && npm install markdown-parity-check@0.2.
|
|
248
|
+
mkdir verify-mpc && cd verify-mpc && npm init -y && npm install markdown-parity-check@0.2.30 --ignore-scripts && npm audit signatures
|
|
249
249
|
```
|
|
250
250
|
|
|
251
|
-
`npm audit signatures` checks the registry signature and the provenance attestation of each installed package that has one. The attestation of this package names three things to compare with what you expect: the repository `github.com/erekola/markdown-parity-check`, the workflow file `.github/workflows/release.yml` and the commit that produced the tarball. The npm version page shows them under Provenance. Tag `v0.2.
|
|
251
|
+
`npm audit signatures` checks the registry signature and the provenance attestation of each installed package that has one. The attestation of this package names three things to compare with what you expect: the repository `github.com/erekola/markdown-parity-check`, the workflow file `.github/workflows/release.yml` and the commit that produced the tarball. The npm version page shows them under Provenance. Tag `v0.2.30` must point at that same commit, and `gh api repos/erekola/markdown-parity-check/commits/v0.2.30 --jq .sha` prints it. A mismatch is a reason not to use that version. Provenance proves which workflow built a release and from which commit. It does not prove that the code is safe, so reading the source and the dependencies stays your job.
|
|
252
252
|
|
|
253
253
|
## Security
|
|
254
254
|
|
package/SECURITY.md
CHANGED
|
@@ -12,7 +12,7 @@ Please do not open a public issue for security reports. You can expect an initia
|
|
|
12
12
|
|
|
13
13
|
## Network and file access
|
|
14
14
|
|
|
15
|
-
URL mode requests HTML and Markdown over HTTP or HTTPS. Non-public network targets are blocked, including targets reached through DNS and redirects. Each fetch has a deadline and a limit on decoded response bytes. The defaults are 15 seconds and 5 MiB. JavaScript from fetched pages is not executed.
|
|
15
|
+
URL mode requests HTML and Markdown over HTTP or HTTPS. Non-public network targets are blocked, including targets reached through DNS and redirects. Each fetch has a deadline and a limit on decoded response bytes. The defaults are 15 seconds and 5 MiB. In the command line the same deadline also covers parsing and comparison, which run in a worker thread that is stopped when the deadline passes, and the tool then exits with code 2. The library entry point has no such deadline, so a program that compares untrusted documents with it needs a time limit of its own. JavaScript from fetched pages is not executed.
|
|
16
16
|
|
|
17
17
|
The work of pairing blocks 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. The pairing of links inside one block is not separately bounded by default: with the default limits it has no budget of its own, and a block with thousands of links that cannot be resolved against a base URL can take time that grows with the square of the link count. A library caller can set the maxSimilarityWork limit to stop it.
|
|
18
18
|
|
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.30\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> Timeout in milliseconds for each fetch and for the parse-and-compare step\n (default: 15000). When it runs out the exit code is 2.\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
|
@@ -7,7 +7,8 @@ import { parseArgs } from 'node:util';
|
|
|
7
7
|
import { fileURLToPath } from 'node:url';
|
|
8
8
|
import { fetchUrl, FetchError, validateUrl } from './fetch.js';
|
|
9
9
|
import { renderJson, renderText } from './report.js';
|
|
10
|
-
import {
|
|
10
|
+
import { runWithDeadline } from './deadline.js';
|
|
11
|
+
import { errorReport, RunError } from './run.js';
|
|
11
12
|
import { maskUrl, redactText } from './normalize.js';
|
|
12
13
|
import { TOOL_NAME, TOOL_VERSION } from './version.js';
|
|
13
14
|
export const HELP = `${TOOL_NAME} ${TOOL_VERSION}
|
|
@@ -34,7 +35,8 @@ Options:
|
|
|
34
35
|
starts with a YAML-looking fenced block; strip removes that leading block.
|
|
35
36
|
--format text|json Report format (default: text).
|
|
36
37
|
--output <path> Write the report to a file instead of stdout. Refuses to overwrite an input file.
|
|
37
|
-
--timeout-ms <n>
|
|
38
|
+
--timeout-ms <n> Timeout in milliseconds for each fetch and for the parse-and-compare step
|
|
39
|
+
(default: 15000). When it runs out the exit code is 2.
|
|
38
40
|
--max-bytes <n> Cap on decoded response bytes per fetch (default: 5242880).
|
|
39
41
|
--strict Treat warnings as rejecting findings too.
|
|
40
42
|
--help, -h Show this help.
|
|
@@ -345,7 +347,9 @@ export async function main(argv, io = { stdout: (s) => process.stdout.write(s),
|
|
|
345
347
|
html = readFileInput(args.htmlFile, base);
|
|
346
348
|
markdown = readFileInput(args.markdownFile, base);
|
|
347
349
|
}
|
|
348
|
-
|
|
350
|
+
// The deadline also covers parsing and comparison, which a timer on this thread cannot interrupt, so
|
|
351
|
+
// the step runs in a worker thread that is terminated when --timeout-ms has passed (exit 2).
|
|
352
|
+
report = await runWithDeadline(html, markdown, options, args.timeoutMs);
|
|
349
353
|
}
|
|
350
354
|
catch (err) {
|
|
351
355
|
let message;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type Report, type RunOptions, type SourceInput } from './run.js';
|
|
2
|
+
/** Runs run(html, markdown, options) in a worker thread and fails with a RunError (exit 2) when it has not finished after timeoutMs. */
|
|
3
|
+
export declare function runWithDeadline(html: SourceInput, markdown: SourceInput, options: RunOptions, timeoutMs: number): Promise<Report>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// Time limit for the parse-and-compare step of the command line. The Markdown and HTML parsers are
|
|
2
|
+
// synchronous, so a timer on the same thread cannot interrupt them. The step therefore runs in a
|
|
3
|
+
// worker thread (src/run-worker.ts) that is terminated at the deadline. The library core does not
|
|
4
|
+
// use this file (see src/core.ts).
|
|
5
|
+
//
|
|
6
|
+
// The deadline starts when the worker reports that its modules are loaded, not when it is spawned:
|
|
7
|
+
// starting a thread and loading the parsers takes about 170 ms, and counting that would make a small
|
|
8
|
+
// --timeout-ms value fail an ordinary local run (QA 1, Q6). A separate, generous start limit covers a
|
|
9
|
+
// worker that never becomes ready.
|
|
10
|
+
import { Worker } from 'node:worker_threads';
|
|
11
|
+
import { RunError } from './run.js';
|
|
12
|
+
/** How long the worker may take to load before the run is given up. Not tied to --timeout-ms. */
|
|
13
|
+
const START_LIMIT_MS = 30_000;
|
|
14
|
+
/** Runs run(html, markdown, options) in a worker thread and fails with a RunError (exit 2) when it has not finished after timeoutMs. */
|
|
15
|
+
export function runWithDeadline(html, markdown, options, timeoutMs) {
|
|
16
|
+
return new Promise((resolve, reject) => {
|
|
17
|
+
const input = { html, markdown, options };
|
|
18
|
+
const worker = new Worker(new URL('./run-worker.js', import.meta.url), { workerData: input });
|
|
19
|
+
let settled = false;
|
|
20
|
+
let timer;
|
|
21
|
+
const finish = (fn) => {
|
|
22
|
+
if (settled)
|
|
23
|
+
return;
|
|
24
|
+
settled = true;
|
|
25
|
+
clearTimeout(startTimer);
|
|
26
|
+
clearTimeout(timer);
|
|
27
|
+
void worker.terminate();
|
|
28
|
+
fn();
|
|
29
|
+
};
|
|
30
|
+
const startTimer = setTimeout(() => {
|
|
31
|
+
finish(() => reject(new RunError(`The comparison worker did not start within ${START_LIMIT_MS} ms.`)));
|
|
32
|
+
}, START_LIMIT_MS);
|
|
33
|
+
worker.on('message', (msg) => {
|
|
34
|
+
if (msg.ready) {
|
|
35
|
+
clearTimeout(startTimer);
|
|
36
|
+
if (!settled) {
|
|
37
|
+
timer = setTimeout(() => {
|
|
38
|
+
finish(() => reject(new RunError(`Timed out after ${timeoutMs} ms while parsing and comparing the two documents (--timeout-ms covers this step as well as each fetch).`)));
|
|
39
|
+
}, timeoutMs);
|
|
40
|
+
}
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const out = msg;
|
|
44
|
+
finish(() => {
|
|
45
|
+
if (out.ok)
|
|
46
|
+
resolve(out.report);
|
|
47
|
+
else if (out.runError)
|
|
48
|
+
reject(new RunError(out.message, out.value));
|
|
49
|
+
else {
|
|
50
|
+
const e = new Error(out.message);
|
|
51
|
+
if (out.stack !== undefined)
|
|
52
|
+
e.stack = out.stack;
|
|
53
|
+
reject(e);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
worker.once('error', (err) => finish(() => reject(err)));
|
|
58
|
+
worker.once('exit', (code) => finish(() => reject(new Error(`The comparison worker stopped without a result (exit ${code}).`))));
|
|
59
|
+
});
|
|
60
|
+
}
|
package/dist/src/fetch.js
CHANGED
|
@@ -88,13 +88,18 @@ function decompressor(encoding) {
|
|
|
88
88
|
}
|
|
89
89
|
/**
|
|
90
90
|
* One wall-clock deadline for a whole fetchUrl call: DNS, connect, headers, body, decompression and every
|
|
91
|
-
* redirect hop. When it fires, the active request
|
|
91
|
+
* redirect hop. When it fires, the active request, its response and its decompression stream are destroyed
|
|
92
|
+
* and the pending step rejects.
|
|
92
93
|
*/
|
|
93
94
|
class Deadline {
|
|
94
95
|
timer;
|
|
95
96
|
expired = false;
|
|
96
97
|
active = null;
|
|
97
98
|
waiters = new Set();
|
|
99
|
+
// Teardown callbacks of the response streams of the active hop. Destroying only the request leaves the
|
|
100
|
+
// decompression stream decoding what it already received (a gzip bomb of about 64 KiB on the wire decodes to
|
|
101
|
+
// 64 MiB, a brotli one to hundreds of MiB), so the streams are destroyed as well.
|
|
102
|
+
teardowns = new Set();
|
|
98
103
|
error;
|
|
99
104
|
constructor(url, timeoutMs) {
|
|
100
105
|
this.error = new FetchError('timeout', url, `Timed out after ${timeoutMs} ms (whole fetch including DNS, redirects and body).`);
|
|
@@ -104,10 +109,25 @@ class Deadline {
|
|
|
104
109
|
this.expired = true;
|
|
105
110
|
if (this.active)
|
|
106
111
|
this.active.destroy(this.error);
|
|
112
|
+
for (const t of this.teardowns)
|
|
113
|
+
t();
|
|
114
|
+
this.teardowns.clear();
|
|
107
115
|
for (const w of this.waiters)
|
|
108
116
|
w(this.error);
|
|
109
117
|
this.waiters.clear();
|
|
110
118
|
}
|
|
119
|
+
/** Registers a callback that destroys the response streams of the active hop when the deadline fires.
|
|
120
|
+
* Returns a function that removes it again. */
|
|
121
|
+
onFire(teardown) {
|
|
122
|
+
if (this.expired) {
|
|
123
|
+
teardown();
|
|
124
|
+
return () => { };
|
|
125
|
+
}
|
|
126
|
+
this.teardowns.add(teardown);
|
|
127
|
+
return () => {
|
|
128
|
+
this.teardowns.delete(teardown);
|
|
129
|
+
};
|
|
130
|
+
}
|
|
111
131
|
attach(req) {
|
|
112
132
|
this.active = req;
|
|
113
133
|
if (this.expired)
|
|
@@ -177,15 +197,30 @@ function requestOnce(url, address, options, deadline) {
|
|
|
177
197
|
reject(new FetchError('protocol', url.href, err.message));
|
|
178
198
|
return;
|
|
179
199
|
}
|
|
200
|
+
// Destroys the decompression stream and the response and detaches the pipe between them, so nothing decodes
|
|
201
|
+
// or reads on after the fetch has failed. No error is passed to destroy(), so neither stream emits one.
|
|
202
|
+
const teardown = () => {
|
|
203
|
+
if (dec) {
|
|
204
|
+
res.unpipe(dec);
|
|
205
|
+
dec.destroy();
|
|
206
|
+
}
|
|
207
|
+
res.destroy();
|
|
208
|
+
};
|
|
209
|
+
const unregister = deadline.onFire(teardown);
|
|
180
210
|
if (dec) {
|
|
181
211
|
stream = res.pipe(dec);
|
|
182
212
|
dec.on('error', (err) => finish(new FetchError('protocol', url.href, `Decompression failed: ${err.message}`)));
|
|
213
|
+
// A response that breaks off mid-body is a network failure; without this listener the error of the
|
|
214
|
+
// source stream of a pipe is not handled by anything.
|
|
215
|
+
res.on('error', (err) => finish(new FetchError('network', url.href, err.message)));
|
|
183
216
|
}
|
|
184
217
|
const finish = (err) => {
|
|
185
218
|
if (done)
|
|
186
219
|
return;
|
|
187
220
|
done = true;
|
|
221
|
+
unregister();
|
|
188
222
|
if (err) {
|
|
223
|
+
teardown();
|
|
189
224
|
req.destroy();
|
|
190
225
|
reject(err);
|
|
191
226
|
}
|
package/dist/src/html.d.ts
CHANGED
|
@@ -11,8 +11,8 @@ export interface HtmlExtractOptions {
|
|
|
11
11
|
maxDepth?: number;
|
|
12
12
|
}
|
|
13
13
|
export declare class HtmlExtractError extends Error {
|
|
14
|
-
/** The user-supplied value the message names (here, --selector), capped the way
|
|
15
|
-
* caps a reflected value: in its own field, not only interpolated into the sentence, and bounded so an
|
|
14
|
+
/** The user-supplied value the message names (here, --selector), capped the way the hosted validator's cut()
|
|
15
|
+
* (src/worker.ts in turva-worker) caps a reflected value: in its own field, not only interpolated into the sentence, and bounded so an
|
|
16
16
|
* arbitrarily long selector cannot make the error text arbitrarily long (V10-P3-01, found by an outside
|
|
17
17
|
* review 2026-09-28). Report rendering still masks every string, value included, through redactText. */
|
|
18
18
|
value?: string;
|
package/dist/src/html.js
CHANGED
|
@@ -5,8 +5,8 @@ import { selectAll, selectOne } from 'css-select';
|
|
|
5
5
|
import { Element, Text } from 'domhandler';
|
|
6
6
|
import { extractNumbers, looseNormalize, normalizeCode, resolveHref, strictNormalize } from './normalize.js';
|
|
7
7
|
export class HtmlExtractError extends Error {
|
|
8
|
-
/** The user-supplied value the message names (here, --selector), capped the way
|
|
9
|
-
* caps a reflected value: in its own field, not only interpolated into the sentence, and bounded so an
|
|
8
|
+
/** The user-supplied value the message names (here, --selector), capped the way the hosted validator's cut()
|
|
9
|
+
* (src/worker.ts in turva-worker) caps a reflected value: in its own field, not only interpolated into the sentence, and bounded so an
|
|
10
10
|
* arbitrarily long selector cannot make the error text arbitrarily long (V10-P3-01, found by an outside
|
|
11
11
|
* review 2026-09-28). Report rendering still masks every string, value included, through redactText. */
|
|
12
12
|
value;
|
|
@@ -16,7 +16,7 @@ export class HtmlExtractError extends Error {
|
|
|
16
16
|
this.value = capValue(value);
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
/** Caps a value that a message reflects back to the caller, the same length
|
|
19
|
+
/** Caps a value that a message reflects back to the caller, the same length the hosted validator's cut() (src/worker.ts in turva-worker) uses, and
|
|
20
20
|
* drops a trailing lone high surrogate a plain slice can leave behind. */
|
|
21
21
|
function capValue(s, n = 120) {
|
|
22
22
|
const cut = s.slice(0, n);
|
|
@@ -237,8 +237,43 @@ function flushRun(ctx, run, container, type = 'paragraph', list) {
|
|
|
237
237
|
const node = run.firstNode ?? container;
|
|
238
238
|
pushBlock(ctx, { type, text, links: run.links, ...(type === 'listItem' && list ? { list } : {}) }, node, container);
|
|
239
239
|
}
|
|
240
|
-
|
|
241
|
-
|
|
240
|
+
/**
|
|
241
|
+
* A link whose children hold a block element, such as a linked card (<a href><h2>..</h2><p>..</p></a>). Up to 0.2.29
|
|
242
|
+
* inlineText flattened it into one run of text, so the card's heading stopped being a heading: a faithful Markdown
|
|
243
|
+
* card (## [title](url)) failed with four errors, while a Markdown copy that wrote the title as a plain linked
|
|
244
|
+
* paragraph passed, also under --strict (found on real sites, 2026-11-02). Such an anchor is now a container in the
|
|
245
|
+
* walk (walkBlockAnchor). An anchor without href, or one with inline content only, is still inline text, and so is
|
|
246
|
+
* one whose block children are all skipped.
|
|
247
|
+
*/
|
|
248
|
+
function isBlockAnchor(ctx, el) {
|
|
249
|
+
if (el.name !== 'a' || el.attribs['href'] === undefined)
|
|
250
|
+
return false;
|
|
251
|
+
if (isSkipped(el, ctx.root, ctx.profile))
|
|
252
|
+
return false;
|
|
253
|
+
return el.children.some((c) => c instanceof Element && BLOCK_TAGS.has(c.name) && !SKIP_TAGS.has(c.name) && !isSkipped(c, ctx.root, ctx.profile));
|
|
254
|
+
}
|
|
255
|
+
function hasBlockChild(ctx, el) {
|
|
256
|
+
return el.children.some((c) => c instanceof Element && ((BLOCK_TAGS.has(c.name) && !SKIP_TAGS.has(c.name)) || isBlockAnchor(ctx, c)));
|
|
257
|
+
}
|
|
258
|
+
/** Walks the children of a block anchor as blocks, then records the anchor's link on every block that came out of
|
|
259
|
+
* it, with that block's own text as the link text, so a heading stays a heading of its depth and a paragraph a
|
|
260
|
+
* paragraph. Markdown reads `## [t](u)` as a heading with the link t, which this matches exactly. */
|
|
261
|
+
function walkBlockAnchor(ctx, a) {
|
|
262
|
+
const start = ctx.blocks.length;
|
|
263
|
+
walk(ctx, a);
|
|
264
|
+
const rawHref = a.attribs['href'] ?? '';
|
|
265
|
+
const resolved = resolveHref(rawHref, ctx.base);
|
|
266
|
+
for (let i = start; i < ctx.blocks.length; i++) {
|
|
267
|
+
const block = ctx.blocks[i];
|
|
268
|
+
block.links.unshift({ text: strictNormalize(block.text), rawHref, resolved });
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
/** In a list item, a link whose only content is one plain paragraph is the item's own text, as before: the item
|
|
272
|
+
* stays a listItem and the link text is the paragraph text. Any other block anchor is a block child of the item. */
|
|
273
|
+
function isParagraphOnlyAnchor(ctx, a) {
|
|
274
|
+
const meaningful = a.children.filter((c) => !(c instanceof Text && c.data.trim() === '') && !(c instanceof Element && isSkipped(c, ctx.root, ctx.profile)));
|
|
275
|
+
const only = meaningful.length === 1 ? meaningful[0] : null;
|
|
276
|
+
return only instanceof Element && only.name === 'p' && !hasBlockChild(ctx, only);
|
|
242
277
|
}
|
|
243
278
|
function walk(ctx, el) {
|
|
244
279
|
// A container: inline runs between block children become paragraphs; block children recurse.
|
|
@@ -246,7 +281,7 @@ function walk(ctx, el) {
|
|
|
246
281
|
for (const child of el.children) {
|
|
247
282
|
if (child instanceof Element && isSkipped(child, ctx.root, ctx.profile))
|
|
248
283
|
continue;
|
|
249
|
-
if (child instanceof Element && (BLOCK_TAGS.has(child.name) || (ctx.profile === 'starlight' && child.name === 'starlight-tabs'))) {
|
|
284
|
+
if (child instanceof Element && (BLOCK_TAGS.has(child.name) || isBlockAnchor(ctx, child) || (ctx.profile === 'starlight' && child.name === 'starlight-tabs'))) {
|
|
250
285
|
flushRun(ctx, run, el);
|
|
251
286
|
run = newRun();
|
|
252
287
|
handleBlock(ctx, child);
|
|
@@ -258,6 +293,10 @@ function walk(ctx, el) {
|
|
|
258
293
|
flushRun(ctx, run, el);
|
|
259
294
|
}
|
|
260
295
|
function handleBlock(ctx, el) {
|
|
296
|
+
if (el.name === 'a') {
|
|
297
|
+
walkBlockAnchor(ctx, el);
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
261
300
|
if (ctx.profile === 'starlight' && el.name === 'starlight-tabs') {
|
|
262
301
|
handleStarlightTabs(ctx, el);
|
|
263
302
|
return;
|
|
@@ -273,7 +312,7 @@ function handleBlock(ctx, el) {
|
|
|
273
312
|
return;
|
|
274
313
|
}
|
|
275
314
|
if (el.name === 'p' || el.name === 'dt' || el.name === 'dd' || el.name === 'figcaption' || el.name === 'summary' || el.name === 'caption' || el.name === 'address') {
|
|
276
|
-
if (hasBlockChild(el)) {
|
|
315
|
+
if (hasBlockChild(ctx, el)) {
|
|
277
316
|
walk(ctx, el);
|
|
278
317
|
return;
|
|
279
318
|
}
|
|
@@ -412,8 +451,9 @@ function handleListItem(ctx, li) {
|
|
|
412
451
|
for (const child of li.children) {
|
|
413
452
|
if (child instanceof Element && isSkipped(child, ctx.root, ctx.profile))
|
|
414
453
|
continue;
|
|
415
|
-
|
|
416
|
-
|
|
454
|
+
const blockAnchor = child instanceof Element && isBlockAnchor(ctx, child) && !isParagraphOnlyAnchor(ctx, child);
|
|
455
|
+
if (child instanceof Element && (BLOCK_TAGS.has(child.name) || blockAnchor || (ctx.profile === 'starlight' && child.name === 'starlight-tabs'))) {
|
|
456
|
+
if (!ownFlushed && child.name === 'p' && !hasBlockChild(ctx, child) && strictNormalize(run.text) === '') {
|
|
417
457
|
for (const c of child.children)
|
|
418
458
|
inlineText(ctx, c, run);
|
|
419
459
|
if (run.firstNode === null)
|
package/dist/src/netguard.js
CHANGED
|
@@ -140,6 +140,10 @@ export function isPublicIPv6(ip) {
|
|
|
140
140
|
return false; // ::1
|
|
141
141
|
if (allZeroTo(5) && g5 === 0xffff)
|
|
142
142
|
return isPublicIPv4(v4FromGroups(g6, g7)); // ::ffff:a.b.c.d
|
|
143
|
+
// ::ffff:0:a.b.c.d is the IPv4-translated range (RFC 2765 SIIT, ::ffff:0:0:0/96); like the mapped form it carries an IPv4
|
|
144
|
+
// address in the last 32 bits, so that address decides.
|
|
145
|
+
if (g0 === 0 && g1 === 0 && g2 === 0 && g3 === 0 && g4 === 0xffff && g5 === 0)
|
|
146
|
+
return isPublicIPv4(v4FromGroups(g6, g7));
|
|
143
147
|
if (allZeroTo(6))
|
|
144
148
|
return isPublicIPv4(v4FromGroups(g6, g7)); // ::a.b.c.d (deprecated compatible)
|
|
145
149
|
if (g0 === 0x64 && g1 === 0xff9b && g2 === 0 && g3 === 0 && g4 === 0 && g5 === 0)
|
package/dist/src/normalize.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export declare function looseNormalize(text: string): string;
|
|
|
8
8
|
export declare function codeWhitespaceKey(code: string): string;
|
|
9
9
|
/** Code content: CRLF and CR line endings become LF and every trailing newline is removed; other whitespace is kept. */
|
|
10
10
|
export declare function normalizeCode(code: string): string;
|
|
11
|
-
/** Removes ANSI escape sequences
|
|
11
|
+
/** Removes ANSI escape sequences, other C0 and C1 controls and the Unicode bidi controls from a value that may come from a compared page or a raw
|
|
12
12
|
* argument, so a plain --format text report cannot replay them at the terminal (0.2.16, found by an outside
|
|
13
13
|
* review 2026-09-28). */
|
|
14
14
|
export declare function stripControlChars(text: string): string;
|
package/dist/src/normalize.js
CHANGED
|
@@ -42,12 +42,15 @@ export function codeWhitespaceKey(code) {
|
|
|
42
42
|
export function normalizeCode(code) {
|
|
43
43
|
return code.replace(/\r\n?/g, '\n').replace(/\n+$/, '');
|
|
44
44
|
}
|
|
45
|
-
// Terminal control characters (ANSI escape sequences and
|
|
45
|
+
// Terminal control characters (ANSI escape sequences, C0 and C1 controls) and the Unicode bidi controls reach a text report unescaped if a
|
|
46
46
|
// compared page or an argument carries one, while --format json is already safe because JSON.stringify escapes
|
|
47
47
|
// every control character. Tab, newline and carriage return are kept: they are ordinary formatting, and by the
|
|
48
48
|
// time most report text reaches this point strictNormalize has already collapsed them to a single space anyway.
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
// C1 controls (U+0080 to U+009F) include the single-byte CSI (U+009B), which some terminals read as an escape. The bidi
|
|
50
|
+
// controls (U+202A to U+202E and U+2066 to U+2069) reorder the text a reader sees, so a quoted excerpt could read
|
|
51
|
+
// differently in a report than in the page. Both ranges match the hosted validator's stripControls(stripBidi()).
|
|
52
|
+
const CONTROL_CHARS = /[\x00-\x08\x0b\x0c\x0e-\x1f\x7f-\x9f\u202A-\u202E\u2066-\u2069]/g;
|
|
53
|
+
/** Removes ANSI escape sequences, other C0 and C1 controls and the Unicode bidi controls from a value that may come from a compared page or a raw
|
|
51
54
|
* argument, so a plain --format text report cannot replay them at the terminal (0.2.16, found by an outside
|
|
52
55
|
* review 2026-09-28). */
|
|
53
56
|
export function stripControlChars(text) {
|
|
@@ -462,8 +465,15 @@ export function maskHref(href) {
|
|
|
462
465
|
const u = new URL(href);
|
|
463
466
|
u.username = '';
|
|
464
467
|
u.password = '';
|
|
465
|
-
|
|
466
|
-
|
|
468
|
+
// One pass (Tek-560 in the hosted validator): a Set keeps the first-seen key order and merges duplicates, and the
|
|
469
|
+
// masked query is built once with append. Calling searchParams.set for each key re-serializes the whole query
|
|
470
|
+
// every time, which is quadratic in the number of keys (5 000 keys took 2.1 s, 20 000 took 35 s). An empty
|
|
471
|
+
// query is left as it is, so "?" stays "?".
|
|
472
|
+
const maskedQuery = new URLSearchParams();
|
|
473
|
+
for (const key of new Set(u.searchParams.keys()))
|
|
474
|
+
maskedQuery.append(key, '***');
|
|
475
|
+
if (maskedQuery.toString() !== '')
|
|
476
|
+
u.search = maskedQuery.toString();
|
|
467
477
|
u.hash = '';
|
|
468
478
|
return u.href;
|
|
469
479
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { run, type RunOptions, type SourceInput } from './run.js';
|
|
2
|
+
export interface WorkerInput {
|
|
3
|
+
html: SourceInput;
|
|
4
|
+
markdown: SourceInput;
|
|
5
|
+
options: RunOptions;
|
|
6
|
+
}
|
|
7
|
+
export type WorkerOutput = {
|
|
8
|
+
ok: true;
|
|
9
|
+
report: ReturnType<typeof run>;
|
|
10
|
+
} | {
|
|
11
|
+
ok: false;
|
|
12
|
+
runError: boolean;
|
|
13
|
+
message: string;
|
|
14
|
+
value?: string;
|
|
15
|
+
stack?: string;
|
|
16
|
+
};
|
|
17
|
+
/** The first message says the modules are loaded and the deadline may start; the second is the result. */
|
|
18
|
+
export type WorkerMessage = {
|
|
19
|
+
ready: true;
|
|
20
|
+
} | (WorkerOutput & {
|
|
21
|
+
ready?: undefined;
|
|
22
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Worker thread entry used by the command line only (src/deadline.ts starts it). It runs the same
|
|
2
|
+
// run() the library exports, so a hostile document that keeps the parser busy can be stopped by
|
|
3
|
+
// terminating this thread at the deadline. Nothing in the library core imports this file or
|
|
4
|
+
// node:worker_threads; test/core.test.ts walks the core's import graph to keep it that way.
|
|
5
|
+
import { parentPort, workerData } from 'node:worker_threads';
|
|
6
|
+
import { run, RunError } from './run.js';
|
|
7
|
+
function reply(out) {
|
|
8
|
+
parentPort.postMessage(out);
|
|
9
|
+
}
|
|
10
|
+
// Static imports are evaluated before this line, so the parsers are loaded when the main thread
|
|
11
|
+
// starts the deadline. run() begins right after, in the same turn.
|
|
12
|
+
reply({ ready: true });
|
|
13
|
+
try {
|
|
14
|
+
const input = workerData;
|
|
15
|
+
reply({ ok: true, report: run(input.html, input.markdown, input.options) });
|
|
16
|
+
}
|
|
17
|
+
catch (err) {
|
|
18
|
+
if (err instanceof RunError)
|
|
19
|
+
reply({ ok: false, runError: true, message: err.message, value: err.value });
|
|
20
|
+
else
|
|
21
|
+
reply({ ok: false, runError: false, message: err?.message ?? String(err), stack: err?.stack });
|
|
22
|
+
}
|
package/dist/src/run.d.ts
CHANGED
|
@@ -70,7 +70,7 @@ export interface Report {
|
|
|
70
70
|
/** Present when the comparison could not be completed reliably. */
|
|
71
71
|
error?: string;
|
|
72
72
|
/** The specific input value error names, capped and reported in its own field rather than only inside
|
|
73
|
-
* the message sentence (V10-P3-01, the same split
|
|
73
|
+
* the message sentence (V10-P3-01, the same split the hosted validator's diagnostics in src/worker.ts of turva-worker already use). */
|
|
74
74
|
errorValue?: string;
|
|
75
75
|
};
|
|
76
76
|
findings: Finding[];
|
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.30";
|
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.30';
|
package/package.json
CHANGED