markdown-parity-check 0.2.36 → 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.36 on 2026-11-10. 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.36 (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)
@@ -251,10 +251,10 @@ Only after that check does it create the GitHub release with the verified tarbal
251
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.
252
252
 
253
253
  ```sh
254
- mkdir verify-mpc && cd verify-mpc && npm init -y && npm install markdown-parity-check@0.2.36 --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
255
255
  ```
256
256
 
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.36` must point at that same commit, and `gh api repos/erekola/markdown-parity-check/commits/v0.2.36 --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.
258
258
 
259
259
  ## Security
260
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.36\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='))
@@ -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;
@@ -1,2 +1,2 @@
1
1
  export declare const TOOL_NAME = "markdown-parity-check";
2
- export declare const TOOL_VERSION = "0.2.36";
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.36';
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.36",
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",