markdown-parity-check 0.2.3 → 0.2.5

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
@@ -1,75 +1,113 @@
1
1
  # markdown-parity-check
2
2
 
3
- Compare the main content of HTML and Markdown pages from the command line. The report lists changed text, numbers, links and blocks, each with its source location, from two local files or from both representations of one URL.
3
+ Compare the main content of a page's HTML and Markdown versions. The report lists missing, added and changed blocks, numbers and links, each with its source location. It can request both versions of one URL or read two local files.
4
4
 
5
- ## Install
5
+ ## Try it in the browser
6
6
 
7
- Use Node.js 22 or 24. The package is published on npm as `markdown-parity-check`.
7
+ The [hosted Markdown parity check](https://turva.dev/markdown-parity-check) runs this comparison on turva.dev. It currently checks the published pages of turva.dev only, and the page states that limit in its opening paragraph and again at the address field. An address on any other site is refused with a message that points to the command-line tool below. Fill in an example puts turva.dev's own tools page in the address field, and Check runs the comparison as a separate step.
8
+
9
+ ## Check your own site
10
+
11
+ Use Node.js 22 or newer. CI tests Node.js 22 and 24 on Windows and Ubuntu. `npx` runs the published package without a global install:
8
12
 
9
13
  ```sh
10
- npx markdown-parity-check --help
14
+ npx --yes markdown-parity-check --url https://example.com/page
11
15
  ```
12
16
 
13
- To install the command permanently, run `npm install -g markdown-parity-check`. The command name is `markdown-parity-check`.
17
+ Replace the address with your page. The tool requests it twice, with `Accept: text/html` and with `Accept: text/markdown`. If the Markdown has its own address, add `--markdown-url`:
14
18
 
15
- ## Usage
19
+ ```sh
20
+ npx --yes markdown-parity-check --url https://example.com/page --markdown-url https://example.com/page.md
21
+ ```
16
22
 
17
- To compare a website, run the CLI with `--url https://example.com/page`. It requests HTML and Markdown from the same URL using the corresponding Accept headers. Use `--markdown-url` to specify a separate Markdown address.
23
+ In CI, write the JSON report to a file and let warnings fail the step as well:
18
24
 
19
25
  ```sh
20
- markdown-parity-check --url https://example.com/page
21
- markdown-parity-check --url https://example.com/page --format json --output report.json
22
- markdown-parity-check --html-file page.html --markdown-file page.md --base-url https://example.com/page
26
+ npx --yes markdown-parity-check --url https://example.com/page --format json --output report.json --strict
23
27
  ```
24
28
 
25
- Front matter in the Markdown file is kept by default. Add `--front-matter strip` to remove it before the comparison.
29
+ To compare two local files, pass both and a base URL for their relative links:
30
+
31
+ ```sh
32
+ npx --yes markdown-parity-check --html-file page.html --markdown-file page.md --base-url https://example.com/page
33
+ ```
34
+
35
+ ## Exit codes
36
+
37
+ | Code | Meaning |
38
+ | --- | --- |
39
+ | `0` | The comparison completed without a rejecting finding. |
40
+ | `1` | The comparison completed and found rejecting content or delivery differences. |
41
+ | `2` | An input, fetch, parse or report error prevented a reliable comparison. |
42
+
43
+ Exit code 0 means the implemented checks found nothing to reject. It does not prove that the two versions mean the same thing.
26
44
 
27
45
  ## Options
28
46
 
29
47
  | Option | Purpose |
30
48
  | --- | --- |
31
- | `--url URL` | Request both formats from a URL. |
32
- | `--markdown-url URL` | Set a separate Markdown URL. |
33
- | `--html-file PATH --markdown-file PATH` | Compare local files. |
34
- | `--base-url URL` | Resolve relative links in local files. |
49
+ | `--url URL` | Request both versions from one URL. |
50
+ | `--markdown-url URL` | Request the Markdown from a separate address. Needs `--url`. |
51
+ | `--html-file PATH --markdown-file PATH` | Compare two local files instead. |
52
+ | `--base-url URL` | Resolve relative links in local files. Local-file mode only. |
35
53
  | `--selector CSS` | Choose the HTML content container. |
36
- | `--front-matter keep` or `--front-matter strip` | Keep metadata by default or remove it explicitly. |
37
- | `--format json` | Print a structured report. |
38
- | `--output PATH` | Write the report to a file. |
39
- | `--strict` | Treat warnings as failures. |
40
- | `--timeout-ms MS` | Set the request deadline. |
41
- | `--max-bytes N` | Limit the decoded response size. |
54
+ | `--front-matter keep` or `--front-matter strip` | Keep Markdown front matter, which is the default, or remove it before the comparison. |
55
+ | `--format text` or `--format json` | Print a readable report, which is the default, or a structured one. |
56
+ | `--output PATH` | Write the report to a file. An input file is never overwritten. |
57
+ | `--strict` | Treat warnings as rejecting findings. |
58
+ | `--timeout-ms MS` | Deadline per request. The default is 15 000 ms. |
59
+ | `--max-bytes N` | Limit on decoded bytes per response. The default is 5 MiB. |
60
+ | `--help`, `--version` | Print the help or the version. |
42
61
 
43
- ## Exit codes
62
+ ## What is compared
44
63
 
45
- | Code | Meaning |
46
- | --- | --- |
47
- | `0` | Comparison completed without rejecting findings. |
48
- | `1` | Content or Markdown delivery failed the check. |
49
- | `2` | Input or execution prevented a reliable comparison. |
64
+ Without `--selector`, the HTML content comes from `main`, `article` or `[role=main]`. If none of them exists, the page body is used and the report warns that page chrome may leak in. Front matter is kept by default and compared as content. If the HTML does not carry the same text, that alone fails the comparison. The tool also warns when the Markdown starts with a block that looks like YAML front matter, and `--front-matter strip` removes it.
50
65
 
51
- A zero exit code means the implemented checks passed. It does not prove semantic equivalence.
66
+ Headings, paragraphs, list items, tables, code blocks and links are compared block by block. Missing and added blocks are errors. So are changes in text, numbers, tables and links. A change of order, heading level, case or punctuation is a warning. Repeated blocks are reported too.
52
67
 
53
- ## Scope
68
+ 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.
54
69
 
55
- The comparison covers headings, paragraphs, lists, tables, code and links. It detects repeated blocks and reports ordering changes. Formatting differences can produce warnings while changed wording produces errors.
70
+ 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, but excerpts may still contain private page content. Review a report before you share it.
56
71
 
57
- HTML content selection prefers the main content container. A fallback to the page body produces a warning. JavaScript is not executed. Block matching is heuristic and some complex layouts need an explicit selector.
72
+ ## Command line and hosted page
58
73
 
59
- URL fetching blocks non-public network targets and checks redirects. Request deadlines and response size limits bound network work. The comparison itself is bounded too: the product of the HTML and Markdown block counts may not exceed 4 000 000, which is 2 000 blocks on each side. Above that the tool exits with code 2 and an error instead of allocating memory without limit. HTML or Markdown nested deeper than 1 024 levels also ends with code 2, before the extraction can exhaust the call stack. Reports mask URL query values, but content excerpts may still contain private information. Review reports before sharing them.
74
+ Both use the comparison core of this package. They differ in which pages they reach and in their limits:
75
+
76
+ | Topic | Command-line tool | Hosted page |
77
+ | --- | --- | --- |
78
+ | Pages | Any public HTTP or HTTPS address, or two local files. | Published turva.dev pages only. |
79
+ | 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. |
80
+ | Response size | 5 MiB per response by default, adjustable with `--max-bytes`. | HTML up to 512 KiB. Markdown up to 128 KiB. |
81
+ | Comparison size | Up to 4 000 000 block pairs. | Up to 250 000 block pairs. |
82
+ | Rate | Not limited by the tool. | About 10 checks per minute from one IP address at each Cloudflare location. |
83
+
84
+ The hosted page also answers a JSON POST, described on the page. It runs the release of this package pinned in [turva-worker](https://github.com/erekola/turva-worker), which can be older than the latest npm release. The report's `toolVersion` field shows which release produced it.
85
+
86
+ A hosted check can fail on turva.dev's own pages as well. On 2026-09-11 the check of https://turva.dev/tools returned `fail` with five errors. The Markdown carries a Related heading and four links that the HTML page does not repeat as a list, and the report listed each of them. The same four targets are links inside that page's tool cards, so the report found a missing structure and not missing content. [HTML and Markdown can disagree](https://turva.dev/blog/html-and-markdown-can-disagree) reads that result in full.
60
87
 
61
88
  ## Library use
62
89
 
63
- The package has a library entry as well. It runs the same comparison as the command, without the command-line interface, the file reader or the network code. It uses no Node.js built-in modules, so it can also be bundled for Cloudflare Workers.
90
+ The package also exports the comparison without the command-line interface, the file reader or the network code. The library entry imports no Node.js built-in modules, which is how the hosted page bundles it into a Cloudflare Worker.
64
91
 
65
92
  ```js
66
93
  import { run, renderJson } from 'markdown-parity-check';
67
94
 
68
- const report = run(htmlSource, markdownSource, { strict: false, mode: 'url' });
95
+ // htmlText and markdownText are the two documents you already fetched or read.
96
+ const base = 'https://example.com/page';
97
+ const source = (file, body) => ({
98
+ meta: { kind: 'file', file, bytes: new TextEncoder().encode(body).length, baseUrl: base },
99
+ body,
100
+ base,
101
+ });
102
+
103
+ const report = run(source('page.html', htmlText), source('page.md', markdownText), { strict: false, mode: 'offline' });
104
+ console.log(report.summary.result, report.summary.exitCode);
69
105
  console.log(renderJson(report));
70
106
  ```
71
107
 
72
- Each source is an object with the document text, a base URL for links and the source details the report shows. The report is the same object that `--format json` prints. A host with a smaller CPU or memory budget can pass lower limits in the `limits` option, and a run that exceeds one ends with an error. Fetching the pages and deciding which addresses may be fetched stays with the caller. The address policy the command applies is exported as `assertPublicHost` and `isPublicAddress`.
108
+ `run(html, markdown, options)` returns the report object that `--format json` prints. A completed run has the result `pass` with exit code 0 or `fail` with exit code 1. When the comparison cannot finish, for example because the content is empty or a limit is exceeded, `run` throws a `RunError`. `errorReport` builds the error report the command prints in that case.
109
+
110
+ The options are `selector`, `frontMatter`, `strict` and `mode`. The report records `mode` as `url` or `offline`, and it does not switch any check on or off. When the Markdown source has `kind: 'url'` in its `meta`, the delivery check runs first and reads the HTTP `status` and `contentType` from that `meta`. A host with a smaller CPU or memory budget can pass lower `limits`: `maxAlignmentPairs`, `maxSimilarityCandidates`, `maxSimilarityWork` and `maxNestingDepth`. The caller fetches the pages and decides which addresses are allowed. The address policy the command applies is exported as `assertPublicHost` and `isPublicAddress`.
73
111
 
74
112
  ## Run from source
75
113
 
@@ -81,11 +119,11 @@ npm run build
81
119
  node dist/src/cli.js --html-file test/fixtures/same/page.html --markdown-file test/fixtures/same/page.md --base-url https://example.com/page --front-matter strip
82
120
  ```
83
121
 
84
- The bundled example compares matching content. It explicitly removes the Markdown file's front matter.
122
+ The bundled example compares matching content and exits with code 0. It removes the Markdown file's front matter explicitly. Without `--front-matter strip` the same pair fails, because the front matter is compared as content.
85
123
 
86
124
  ## Development
87
125
 
88
- Run `npm run typecheck` and `npm test`. GitHub Actions tests Node.js 22 and 24 on Windows and Ubuntu. After CI passes on the main branch, the release workflow packs the tarball once, publishes it to npm when the version is not there yet, downloads the registry copy and checks its integrity hash and its content against the packed file. Only then does it create the GitHub release with that verified tarball attached. A version that exists on npm with different content stops the release.
126
+ Run `npm run typecheck` and `npm test`. GitHub Actions tests Node.js 22 and 24 on Windows and Ubuntu. After CI passes on the main branch, the release workflow packs the tarball once, publishes it to npm when the version is not there yet, downloads the registry copy and checks its integrity hash and its content against the packed file. Only then does it create the GitHub release with that verified tarball attached. A version that exists on npm with different content stops the release. npm packs this README too, so a change to it reaches the npm page only with a new version.
89
127
 
90
128
  ## Security
91
129
 
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\nCompares the main content of a web page's HTML and Markdown representations and reports concrete\nmissing, added and changed blocks.\n\nUsage:\n markdown-parity-check --url <https://example.com/page> [--markdown-url <url>] [options]\n markdown-parity-check --html-file <page.html> --markdown-file <page.md> [--base-url <url>] [options]\n\nModes:\n --url <url> Fetch <url> twice: with Accept: text/html and with Accept: text/markdown.\n --markdown-url <url> Fetch the Markdown from this explicit address instead (requires --url).\n --html-file <path> Offline: local HTML file (requires --markdown-file).\n --markdown-file <path> Offline: local Markdown file (requires --html-file).\n --base-url <url> Offline: base for resolving relative links on both sides.\n\nOptions:\n --selector <css> CSS selector for the HTML main content (default: main, article, [role=main], then body).\n --front-matter keep|strip\n Markdown front matter. keep (default) removes nothing and warns when the document\n starts with a YAML-looking fenced block; strip removes that leading block.\n --format text|json Report format (default: text).\n --output <path> Write the report to a file instead of stdout. Refuses to overwrite an input file.\n --timeout-ms <n> Per-fetch timeout in milliseconds (default: 15000).\n --max-bytes <n> Cap on decoded response bytes per fetch (default: 5242880).\n --strict Treat warnings as rejecting findings too.\n --help, -h Show this help.\n --version, -V Show the version.\n\nExit codes:\n 0 comparison completed, no rejecting finding\n 1 comparison completed, rejecting content or delivery differences found\n 2 input, fetch, parse or report error prevented a reliable comparison\n\nOnly http(s) URLs to public addresses are fetched; loopback, private, link-local and other non-public\naddresses are refused, also behind DNS and redirects. No JavaScript is executed. Exit 0 does not prove\nsemantic equivalence.\n";
3
+ export declare const HELP = "markdown-parity-check 0.2.5\nCompares the main content of a web page's HTML and Markdown representations and reports concrete\nmissing, added and changed blocks.\n\nUsage:\n markdown-parity-check --url <https://example.com/page> [--markdown-url <url>] [options]\n markdown-parity-check --html-file <page.html> --markdown-file <page.md> [--base-url <url>] [options]\n\nModes:\n --url <url> Fetch <url> twice: with Accept: text/html and with Accept: text/markdown.\n --markdown-url <url> Fetch the Markdown from this explicit address instead (requires --url).\n --html-file <path> Offline: local HTML file (requires --markdown-file).\n --markdown-file <path> Offline: local Markdown file (requires --html-file).\n --base-url <url> Offline: base for resolving relative links on both sides.\n\nOptions:\n --selector <css> CSS selector for the HTML main content (default: main, article, [role=main], then body).\n --front-matter keep|strip\n Markdown front matter. keep (default) removes nothing and warns when the document\n starts with a YAML-looking fenced block; strip removes that leading block.\n --format text|json Report format (default: text).\n --output <path> Write the report to a file instead of stdout. Refuses to overwrite an input file.\n --timeout-ms <n> Per-fetch timeout in milliseconds (default: 15000).\n --max-bytes <n> Cap on decoded response bytes per fetch (default: 5242880).\n --strict Treat warnings as rejecting findings too.\n --help, -h Show this help.\n --version, -V Show the version.\n\nExit codes:\n 0 comparison completed, no rejecting finding\n 1 comparison completed, rejecting content or delivery differences found\n 2 input, fetch, parse or report error prevented a reliable comparison\n\nOnly http(s) URLs to public addresses are fetched; loopback, private, link-local and other non-public\naddresses are refused, also behind DNS and redirects. No JavaScript is executed. Exit 0 does not prove\nsemantic equivalence.\n";
4
4
  export declare class CliError extends Error {
5
5
  }
6
6
  export interface CliArgs {
@@ -1,2 +1,2 @@
1
1
  export declare const TOOL_NAME = "markdown-parity-check";
2
- export declare const TOOL_VERSION = "0.2.3";
2
+ export declare const TOOL_VERSION = "0.2.5";
@@ -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.3';
5
+ export const TOOL_VERSION = '0.2.5';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markdown-parity-check",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
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",