markdown-parity-check 0.2.35 → 0.2.37

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 CHANGED
@@ -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.35 on 2026-11-07. The exact command is in the Development section below. The text report ends with a list of limitations, which is omitted here:
81
+ This is the text report for the matching fixture pair in this repository, run with version 0.2.37 on 2026-11-12. 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.35 (offline mode)
84
+ markdown-parity-check 0.2.37 (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)
@@ -137,7 +137,7 @@ A `<br>` in a code block is a line break. A code block that differs only in whit
137
137
 
138
138
  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. A Markdown response labelled `text/plain` is a warning, and any other content type than `text/markdown` or `text/x-markdown` is an error. A comment, an XML declaration or another declaration before the doctype does not hide an HTML page from this check. If the HTML request itself returns an HTTP error, the run ends with exit code 2.
139
139
 
140
- An HTML response is decoded by its byte order mark first, then by the charset of its Content-Type header, then by a meta charset declaration in its first 1024 bytes, and as UTF-8 when none of them names a known encoding. A Markdown response is decoded by the charset of its header, or as UTF-8.
140
+ A response whose Content-Type header names `text/html` or `application/xhtml+xml` is decoded by its byte order mark first, then by the charset of that header, then by a meta charset declaration in its first 1024 bytes, and as UTF-8 when none of them names a known encoding. The choice follows the type of the response, not the request: any other response, including an HTML page sent with another type or with no Content-Type header, is decoded by the charset of its header or as UTF-8, and its byte order mark and meta declaration do not choose the encoding. A Markdown response is decoded that way too.
141
141
 
142
142
  ### Limits of the method
143
143
 
@@ -222,6 +222,8 @@ The JSON report is the `Report` type. Its top-level fields are:
222
222
  | `findings` | A list of `Finding` objects, each with `code`, `severity`, `direction` and `message`, and where they apply the `html` and `markdown` locations and the `before` and `after` text. |
223
223
  | `limitations` | The fixed list of what the check does not cover. |
224
224
 
225
+ An error report for an argument error is built before the arguments are validated, so the command takes `mode` from the presence of `--url` and `summary.strict` from the presence of `--strict` in the command line. A command line with neither is recorded as `offline` and not strict, and so is one that gives `--markdown-url` without `--url`.
226
+
225
227
  ## Development
226
228
 
227
229
  The sources are TypeScript under `src/`, compiled with `tsc` to `dist/`. Clone the repository, build it and run the bundled example:
@@ -249,10 +251,10 @@ Only after that check does it create the GitHub release with the verified tarbal
249
251
  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.
250
252
 
251
253
  ```sh
252
- mkdir verify-mpc && cd verify-mpc && npm init -y && npm install markdown-parity-check@0.2.35 --ignore-scripts && npm audit signatures
254
+ mkdir verify-mpc && cd verify-mpc && npm init -y && npm install markdown-parity-check@0.2.37 --ignore-scripts && npm audit signatures
253
255
  ```
254
256
 
255
- `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.35` must point at that same commit, and `gh api repos/erekola/markdown-parity-check/commits/v0.2.35 --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.
257
+ `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.37` must point at that same commit, and `gh api repos/erekola/markdown-parity-check/commits/v0.2.37 --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.
256
258
 
257
259
  ## Security
258
260
 
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.35\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";
3
+ export declare const HELP = "markdown-parity-check 0.2.37\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
@@ -62,8 +62,8 @@ function rawWantsJson(argv) {
62
62
  let wants = false;
63
63
  for (let i = 0; i < argv.length; i++) {
64
64
  const a = argv[i];
65
- if (a === undefined)
66
- continue;
65
+ if (a === undefined || a === '--')
66
+ break;
67
67
  if (a === '--format')
68
68
  wants = argv[i + 1] === 'json';
69
69
  else if (a.startsWith('--format='))
@@ -71,6 +71,26 @@ function rawWantsJson(argv) {
71
71
  }
72
72
  return wants;
73
73
  }
74
+ /**
75
+ * What the invocation asked for, read from the raw argv for the same reason as rawWantsJson: an argument error is
76
+ * thrown before parseCliArgs has produced a validated CliArgs. URL mode is the presence of --url, as in the normal
77
+ * path (`args.url !== undefined`), and strict is the presence of --strict. Both are read until a bare `--`, after
78
+ * which every token is a positional argument. An invocation that gives neither stays offline and not strict, which
79
+ * is the only answer the arguments leave open (for example --markdown-url without --url).
80
+ */
81
+ function rawInvocation(argv) {
82
+ let mode = 'offline';
83
+ let strict = false;
84
+ for (const a of argv) {
85
+ if (a === '--')
86
+ break;
87
+ if (a === '--url' || a.startsWith('--url='))
88
+ mode = 'url';
89
+ else if (a === '--strict')
90
+ strict = true;
91
+ }
92
+ return { mode, strict };
93
+ }
74
94
  // The largest delay Node's own timer accepts (2^31 - 1 ms, about 24.8 days). A larger value is not
75
95
  // rejected by Node: it becomes a roughly 1 ms timeout instead, with a TimeoutOverflowWarning, so an
76
96
  // error built from the value the caller gave would misreport what is actually going to happen
@@ -315,8 +335,9 @@ export async function main(argv, io = { stdout: (s) => process.stdout.write(s),
315
335
  // stdout carries the report on top of, not instead of, the plain-text stderr line every
316
336
  // argument error writes, since --output cannot be trusted without validated args and callers
317
337
  // already rely on the stderr line regardless of format (test/review-0212.test.ts, test/secrets.test.ts).
338
+ // The report records the mode and strictness the arguments asked for where they say so (rawInvocation).
318
339
  if (rawWantsJson(argv)) {
319
- const report = errorReport({ strict: false, mode: 'offline' }, null, null, message);
340
+ const report = errorReport(rawInvocation(argv), null, null, message);
320
341
  io.stdout(renderJson(report));
321
342
  }
322
343
  io.stderr(`Error: ${message}\n`);
@@ -164,12 +164,6 @@ export function pairLinks(hLinks, mLinks, maxWork = Number.POSITIVE_INFINITY) {
164
164
  else
165
165
  looseLists.set(k, [i]);
166
166
  });
167
- const looseMissing = new Map();
168
- for (const hi of missing) {
169
- const k = looseNormalize(hLinks[hi].text);
170
- if (k !== '')
171
- looseMissing.set(k, (looseMissing.get(k) ?? 0) + 1);
172
- }
173
167
  const looseHeads = new Map();
174
168
  const stillMissing = [];
175
169
  for (const hi of missing) {
package/dist/src/fetch.js CHANGED
@@ -88,16 +88,74 @@ function headerCharset(contentType) {
88
88
  * UTF-16. */
89
89
  function metaCharset(buf) {
90
90
  const head = buf.subarray(0, 1024).toString('latin1').replace(/<!--[\s\S]*?(?:-->|$)/g, '');
91
- for (const tag of head.matchAll(/<meta\b[^>]*>?/gi)) {
92
- const m = /charset\s*=\s*["']?\s*([^\s"'>;/]+)/i.exec(tag[0]);
93
- if (!m)
94
- continue;
95
- const label = m[1].toLowerCase();
96
- if (decoderFor(label))
91
+ const start = /<meta(?=[\s/>])/gi;
92
+ for (let s = start.exec(head); s !== null; s = start.exec(head)) {
93
+ const { attrs, end } = metaAttributes(head, s.index + s[0].length);
94
+ start.lastIndex = end;
95
+ let label = null;
96
+ const direct = attrs.get('charset');
97
+ if (direct !== undefined)
98
+ label = direct.trim().toLowerCase();
99
+ else if (attrs.get('http-equiv')?.trim().toLowerCase() === 'content-type') {
100
+ const m = /charset\s*=\s*["']?\s*([^\s"'>;/]+)/i.exec(attrs.get('content') ?? '');
101
+ if (m)
102
+ label = m[1].toLowerCase();
103
+ }
104
+ if (label && decoderFor(label))
97
105
  return label.startsWith('utf-16') ? 'utf-8' : label;
98
106
  }
99
107
  return null;
100
108
  }
109
+ /** The attributes of one meta start tag, read the way the HTML standard's prescan reads them: a tag ends at a ">" that
110
+ * is outside quotes, a name is matched exactly (so data-charset is not charset), and the first occurrence of a name
111
+ * wins. A value whose closing quote is missing is dropped. `from` is the position right after "<meta". */
112
+ function metaAttributes(head, from) {
113
+ const attrs = new Map();
114
+ const n = head.length;
115
+ let i = from;
116
+ for (;;) {
117
+ while (i < n && /[\s/]/.test(head[i]))
118
+ i++;
119
+ if (i >= n)
120
+ return { attrs, end: n };
121
+ if (head[i] === '>')
122
+ return { attrs, end: i + 1 };
123
+ let name = '';
124
+ if (head[i] === '=')
125
+ name += head[i++];
126
+ while (i < n && !/[\s/>=]/.test(head[i]))
127
+ name += head[i++];
128
+ while (i < n && /\s/.test(head[i]))
129
+ i++;
130
+ let value = '';
131
+ let complete = true;
132
+ if (head[i] === '=') {
133
+ i++;
134
+ while (i < n && /\s/.test(head[i]))
135
+ i++;
136
+ const q = head[i];
137
+ if (q === '"' || q === "'") {
138
+ const close = head.indexOf(q, i + 1);
139
+ if (close < 0) {
140
+ value = head.slice(i + 1);
141
+ complete = false;
142
+ i = n;
143
+ }
144
+ else {
145
+ value = head.slice(i + 1, close);
146
+ i = close + 1;
147
+ }
148
+ }
149
+ else {
150
+ while (i < n && !/[\s>]/.test(head[i]))
151
+ value += head[i++];
152
+ }
153
+ }
154
+ const key = name.toLowerCase();
155
+ if (complete && !attrs.has(key))
156
+ attrs.set(key, value);
157
+ }
158
+ }
101
159
  /** HTML is decoded the way the HTML standard orders the evidence: a byte order mark, then the charset of the
102
160
  * Content-Type header, then the meta declaration, and UTF-8 when none of them names an encoding the runtime knows
103
161
  * (MP-18). The standard's own default is windows-1252; UTF-8 is this tool's default for pages that say nothing. */
@@ -517,7 +517,7 @@ function visibleText(fragment) {
517
517
  return strictNormalize(parts.join(' '));
518
518
  }
519
519
  const YAML_LINE = /^(?:[A-Za-z0-9_.-]+\s*:(?:\s|$)|\s+\S|-\s|#)/;
520
- const FENCE_RE = /^(?:\ufeff)?---[ \t]*\r?\n([\s\S]*?)\r?\n(?:---|\.\.\.)[ \t]*(?:\r?\n|$)/;
520
+ const FENCE_RE = /^(?:\ufeff)?---[ \t]*(?:\r\n|\r(?!\n)|\n)([\s\S]*?)(?:\r\n|\r(?!\n)|\n)(?:---|\.\.\.)[ \t]*(?:\r\n|\r(?!\n)|\n|$)/;
521
521
  /**
522
522
  * Front matter is never removed on guesswork. With 'keep' the source is parsed as written and a leading
523
523
  * fenced block that looks like YAML only raises a warning (strict fails). With 'strip' the user has
@@ -528,11 +528,11 @@ function scanFrontMatter(source, mode) {
528
528
  if (!m)
529
529
  return { text: source, skippedLines: 0, looksLikeYaml: false, body: '' };
530
530
  const body = m[1] ?? '';
531
- const nonEmpty = body.split(/\r?\n/).filter((l) => l.trim() !== '');
531
+ const nonEmpty = body.split(/\r\n|\r|\n/).filter((l) => l.trim() !== '');
532
532
  const looksLikeYaml = nonEmpty.length > 0 && nonEmpty.every((l) => YAML_LINE.test(l));
533
533
  if (mode === 'keep')
534
534
  return { text: source, skippedLines: 0, looksLikeYaml, body };
535
- const skippedLines = m[0].split(/\r?\n/).length - (m[0].endsWith('\n') ? 1 : 0);
535
+ const skippedLines = m[0].split(/\r\n|\r|\n/).length - (/[\r\n]$/.test(m[0]) ? 1 : 0);
536
536
  return { text: source.slice(m[0].length), skippedLines, looksLikeYaml, body };
537
537
  }
538
538
  function collectDefinitions(tree) {
@@ -121,12 +121,14 @@ export function expandIPv6(ip) {
121
121
  const head = halves[0] ? halves[0].split(':') : [];
122
122
  const tail = halves.length === 2 && halves[1] ? halves[1].split(':') : [];
123
123
  const fill = 8 - head.length - tail.length;
124
- if (fill < 0 || (halves.length === 1 && fill !== 0))
124
+ // "::" stands for at least one group of zeros, so a full eight groups next to "::" is not an address.
125
+ if (fill < 0 || (halves.length === 1 && fill !== 0) || (halves.length === 2 && fill < 1))
125
126
  return null;
126
- const groups = [...head, ...Array(fill).fill('0'), ...tail].map((g) => parseInt(g, 16));
127
- if (groups.length !== 8 || groups.some((g) => Number.isNaN(g) || g < 0 || g > 0xffff))
127
+ const parts = [...head, ...Array(fill).fill('0'), ...tail];
128
+ // Every group is one to four hexadecimal digits, matched in full; parseInt alone would take a valid prefix.
129
+ if (parts.length !== 8 || parts.some((g) => !/^[0-9a-f]{1,4}$/.test(g)))
128
130
  return null;
129
- return groups;
131
+ return parts.map((g) => parseInt(g, 16));
130
132
  }
131
133
  export function isPublicIPv6(ip) {
132
134
  const g = expandIPv6(ip);
@@ -343,7 +343,19 @@ function nextParenUserinfo(text, from) {
343
343
  const nameWindow = text.slice(nameStart, nameWindowEnd);
344
344
  const close = nameWindow.indexOf(')');
345
345
  const stop = nameWindow.search(/[\s(]/);
346
- if (close < 0 || (stop >= 0 && stop < close) || nameWindow[close + 1] !== ':') {
346
+ if (close < 0 && stop < 0 && nameWindowEnd - nameStart === PAREN_USERINFO_SCAN) {
347
+ // The name is longer than the window and has no ")" and no stopping character in it, so its end cannot be
348
+ // found. A secret may follow it, so this is masked fail-closed too: from the "(" through the next "@", or
349
+ // through the end of the token (the next whitespace, angle bracket or quote, else the end of the text) when
350
+ // there is no "@". The match is consumed, so the scan stays linear (0.2.37).
351
+ const stopRe = /[@\s<>"']/g;
352
+ stopRe.lastIndex = nameWindowEnd;
353
+ const tailMatch = stopRe.exec(text);
354
+ const atTail = tailMatch !== null && tailMatch[0] === '@';
355
+ const secretEnd = tailMatch === null ? text.length : tailMatch.index;
356
+ return { start: m.index, scheme: m[1], nameStart, secretStart: nameWindowEnd, secretEnd, end: atTail ? secretEnd + 1 : secretEnd };
357
+ }
358
+ if (close < 0 || (stop >= 0 && stop < close) || text[nameStart + close + 1] !== ':') {
347
359
  // No well-formed "):" landmark within the window: this "(" is not the shape we mask, so it is left as it is
348
360
  // and the search resumes right after it, not from the start again.
349
361
  re.lastIndex = nameStart;
@@ -515,7 +527,7 @@ export function maskHref(href) {
515
527
  const u = new URL(href);
516
528
  u.username = '';
517
529
  u.password = '';
518
- // One pass (Tek-560 in the hosted validator): a Set keeps the first-seen key order and merges duplicates, and the
530
+ // One pass: a Set keeps the first-seen key order and merges duplicates, and the
519
531
  // masked query is built once with append. Calling searchParams.set for each key re-serializes the whole query
520
532
  // every time, which is quadratic in the number of keys (5 000 keys took 2.1 s, 20 000 took 35 s). An empty
521
533
  // query is left as it is, so "?" stays "?".
@@ -1,2 +1,2 @@
1
1
  export declare const TOOL_NAME = "markdown-parity-check";
2
- export declare const TOOL_VERSION = "0.2.35";
2
+ export declare const TOOL_VERSION = "0.2.37";
@@ -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.35';
5
+ export const TOOL_VERSION = '0.2.37';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markdown-parity-check",
3
- "version": "0.2.35",
3
+ "version": "0.2.37",
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",