markdown-parity-check 0.2.7 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/src/cli.d.ts +2 -1
- package/dist/src/cli.js +8 -1
- package/dist/src/html.d.ts +2 -0
- package/dist/src/html.js +119 -10
- package/dist/src/run.d.ts +1 -0
- package/dist/src/run.js +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
|
@@ -51,6 +51,7 @@ Exit code 0 means the implemented checks found nothing to reject. It does not pr
|
|
|
51
51
|
| `--html-file PATH --markdown-file PATH` | Compare two local files instead. |
|
|
52
52
|
| `--base-url URL` | Resolve relative links in local files. Local-file mode only. |
|
|
53
53
|
| `--selector CSS` | Choose the HTML content container. |
|
|
54
|
+
| `--html-profile generic` or `--html-profile starlight` | Use the generic HTML rules, which is the default, or the Starlight rules, which also compare inactive tab panels and keep Expressive Code line breaks. |
|
|
54
55
|
| `--front-matter keep` or `--front-matter strip` | Keep Markdown front matter, which is the default, or remove it before the comparison. |
|
|
55
56
|
| `--format text` or `--format json` | Print a readable report, which is the default, or a structured one. |
|
|
56
57
|
| `--output PATH` | Write the report to a file. An input file is never overwritten. |
|
package/dist/src/cli.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
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.8\nCompares the main content of a web page's HTML and Markdown representations and reports concrete\nmissing, added and changed blocks.\n\nUsage:\n markdown-parity-check --url <https://example.com/page> [--markdown-url <url>] [options]\n markdown-parity-check --html-file <page.html> --markdown-file <page.md> [--base-url <url>] [options]\n\nModes:\n --url <url> Fetch <url> twice: with Accept: text/html and with Accept: text/markdown.\n --markdown-url <url> Fetch the Markdown from this explicit address instead (requires --url).\n --html-file <path> Offline: local HTML file (requires --markdown-file).\n --markdown-file <path> Offline: local Markdown file (requires --html-file).\n --base-url <url> Offline: base for resolving relative links on both sides.\n\nOptions:\n --html-profile generic|starlight\n HTML extraction rules (default: generic). Starlight includes inactive tab panels.\n --selector <css> CSS selector for the HTML main content (default: main, article, [role=main], then body).\n --front-matter keep|strip\n Markdown front matter. keep (default) removes nothing and warns when the document\n starts with a YAML-looking fenced block; strip removes that leading block.\n --format text|json Report format (default: text).\n --output <path> Write the report to a file instead of stdout. Refuses to overwrite an input file.\n --timeout-ms <n> Per-fetch timeout in milliseconds (default: 15000).\n --max-bytes <n> Cap on decoded response bytes per fetch (default: 5242880).\n --strict Treat warnings as rejecting findings too.\n --help, -h Show this help.\n --version, -V Show the version.\n\nExit codes:\n 0 comparison completed, no rejecting finding\n 1 comparison completed, rejecting content or delivery differences found\n 2 input, fetch, parse or report error prevented a reliable comparison\n\nOnly http(s) URLs to public addresses are fetched; loopback, private, link-local and other non-public\naddresses are refused, also behind DNS and redirects. No JavaScript is executed. Exit 0 does not prove\nsemantic equivalence.\n";
|
|
4
4
|
export declare class CliError extends Error {
|
|
5
5
|
}
|
|
6
6
|
export interface CliArgs {
|
|
7
|
+
htmlProfile: 'generic' | 'starlight';
|
|
7
8
|
url?: string;
|
|
8
9
|
markdownUrl?: string;
|
|
9
10
|
htmlFile?: string;
|
package/dist/src/cli.js
CHANGED
|
@@ -26,6 +26,8 @@ Modes:
|
|
|
26
26
|
--base-url <url> Offline: base for resolving relative links on both sides.
|
|
27
27
|
|
|
28
28
|
Options:
|
|
29
|
+
--html-profile generic|starlight
|
|
30
|
+
HTML extraction rules (default: generic). Starlight includes inactive tab panels.
|
|
29
31
|
--selector <css> CSS selector for the HTML main content (default: main, article, [role=main], then body).
|
|
30
32
|
--front-matter keep|strip
|
|
31
33
|
Markdown front matter. keep (default) removes nothing and warns when the document
|
|
@@ -64,6 +66,7 @@ export function parseCliArgs(argv) {
|
|
|
64
66
|
allowPositionals: false,
|
|
65
67
|
strict: true,
|
|
66
68
|
options: {
|
|
69
|
+
'html-profile': { type: 'string', default: 'generic' },
|
|
67
70
|
url: { type: 'string' },
|
|
68
71
|
'markdown-url': { type: 'string' },
|
|
69
72
|
'html-file': { type: 'string' },
|
|
@@ -85,6 +88,9 @@ export function parseCliArgs(argv) {
|
|
|
85
88
|
throw new CliError(err.message);
|
|
86
89
|
}
|
|
87
90
|
const v = parsed.values;
|
|
91
|
+
const htmlProfile = v['html-profile'];
|
|
92
|
+
if (htmlProfile !== 'generic' && htmlProfile !== 'starlight')
|
|
93
|
+
throw new CliError('--html-profile must be generic or starlight.');
|
|
88
94
|
const format = v.format;
|
|
89
95
|
if (format !== 'text' && format !== 'json')
|
|
90
96
|
throw new CliError(`--format must be text or json (got "${format}").`);
|
|
@@ -92,6 +98,7 @@ export function parseCliArgs(argv) {
|
|
|
92
98
|
if (frontMatter !== 'keep' && frontMatter !== 'strip')
|
|
93
99
|
throw new CliError(`--front-matter must be keep or strip (got "${frontMatter}").`);
|
|
94
100
|
const args = {
|
|
101
|
+
htmlProfile,
|
|
95
102
|
url: v.url,
|
|
96
103
|
markdownUrl: v['markdown-url'],
|
|
97
104
|
htmlFile: v['html-file'],
|
|
@@ -215,7 +222,7 @@ export async function main(argv, io = { stdout: (s) => process.stdout.write(s),
|
|
|
215
222
|
io.stdout(`${TOOL_VERSION}\n`);
|
|
216
223
|
return 0;
|
|
217
224
|
}
|
|
218
|
-
const options = { selector: args.selector, frontMatter: args.frontMatter, strict: args.strict, mode: args.url !== undefined ? 'url' : 'offline' };
|
|
225
|
+
const options = { htmlProfile: args.htmlProfile, selector: args.selector, frontMatter: args.frontMatter, strict: args.strict, mode: args.url !== undefined ? 'url' : 'offline' };
|
|
219
226
|
let html = null;
|
|
220
227
|
let markdown = null;
|
|
221
228
|
let report;
|
package/dist/src/html.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { type ParentNode } from 'domhandler';
|
|
2
2
|
import type { Extraction } from './model.js';
|
|
3
3
|
export interface HtmlExtractOptions {
|
|
4
|
+
/** Opt-in component semantics. The default keeps generic HTML visibility rules. */
|
|
5
|
+
profile?: 'generic' | 'starlight';
|
|
4
6
|
/** User supplied CSS selector for the main content. */
|
|
5
7
|
selector?: string;
|
|
6
8
|
/** Base URL for resolving relative links; a <base href> in the document takes precedence. */
|
package/dist/src/html.js
CHANGED
|
@@ -74,13 +74,34 @@ function hasLaterSameNamedSibling(el) {
|
|
|
74
74
|
}
|
|
75
75
|
return false;
|
|
76
76
|
}
|
|
77
|
-
function
|
|
77
|
+
function hasClass(el, name) {
|
|
78
|
+
return (el.attribs.class ?? '').split(/\s+/).includes(name);
|
|
79
|
+
}
|
|
80
|
+
function ancestor(el, predicate) {
|
|
81
|
+
let parent = el.parent;
|
|
82
|
+
while (parent instanceof Element) {
|
|
83
|
+
if (predicate(parent))
|
|
84
|
+
return parent;
|
|
85
|
+
parent = parent.parent;
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
function isSkipped(el, root, profile = 'generic', ignoreHidden = false) {
|
|
78
90
|
if (SKIP_TAGS.has(el.name))
|
|
79
91
|
return true;
|
|
80
92
|
const role = (el.attribs['role'] ?? '').toLowerCase();
|
|
81
93
|
if (SKIP_ROLES.has(role))
|
|
82
94
|
return true;
|
|
83
|
-
if (el.attribs['hidden'] !== undefined
|
|
95
|
+
if (el.attribs['hidden'] !== undefined && !ignoreHidden)
|
|
96
|
+
return true;
|
|
97
|
+
const asideTitle = profile === 'starlight' && el.name === 'p' && hasClass(el, 'starlight-aside__title')
|
|
98
|
+
&& el.parent instanceof Element && el.parent.name === 'aside' && hasClass(el.parent, 'starlight-aside');
|
|
99
|
+
if (el.attribs['aria-hidden'] === 'true' && !asideTitle)
|
|
100
|
+
return true;
|
|
101
|
+
// Expressive Code's terminal-frame label is UI text, not source code or a filename.
|
|
102
|
+
if (profile === 'starlight' && el.name === 'span' && hasClass(el, 'sr-only')
|
|
103
|
+
&& el.parent instanceof Element && el.parent.name === 'figcaption'
|
|
104
|
+
&& ancestor(el, (node) => hasClass(node, 'expressive-code')))
|
|
84
105
|
return true;
|
|
85
106
|
// header/footer are page chrome only when they sit directly under body (or the html root), not inside an
|
|
86
107
|
// article, where they usually carry metadata that belongs to the content.
|
|
@@ -102,7 +123,7 @@ function inlineText(ctx, node, run) {
|
|
|
102
123
|
}
|
|
103
124
|
if (!(node instanceof Element))
|
|
104
125
|
return;
|
|
105
|
-
if (isSkipped(node, ctx.root))
|
|
126
|
+
if (isSkipped(node, ctx.root, ctx.profile))
|
|
106
127
|
return;
|
|
107
128
|
if (run.firstNode === null)
|
|
108
129
|
run.firstNode = node;
|
|
@@ -156,9 +177,9 @@ function walk(ctx, el) {
|
|
|
156
177
|
// A container: inline runs between block children become paragraphs; block children recurse.
|
|
157
178
|
let run = newRun();
|
|
158
179
|
for (const child of el.children) {
|
|
159
|
-
if (child instanceof Element && isSkipped(child, ctx.root))
|
|
180
|
+
if (child instanceof Element && isSkipped(child, ctx.root, ctx.profile))
|
|
160
181
|
continue;
|
|
161
|
-
if (child instanceof Element && BLOCK_TAGS.has(child.name)) {
|
|
182
|
+
if (child instanceof Element && (BLOCK_TAGS.has(child.name) || (ctx.profile === 'starlight' && child.name === 'starlight-tabs'))) {
|
|
162
183
|
flushRun(ctx, run, el);
|
|
163
184
|
run = newRun();
|
|
164
185
|
handleBlock(ctx, child);
|
|
@@ -170,6 +191,10 @@ function walk(ctx, el) {
|
|
|
170
191
|
flushRun(ctx, run, el);
|
|
171
192
|
}
|
|
172
193
|
function handleBlock(ctx, el) {
|
|
194
|
+
if (ctx.profile === 'starlight' && el.name === 'starlight-tabs') {
|
|
195
|
+
handleStarlightTabs(ctx, el);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
173
198
|
const m = HEADING_RE.exec(el.name);
|
|
174
199
|
if (m) {
|
|
175
200
|
const run = newRun();
|
|
@@ -192,7 +217,7 @@ function handleBlock(ctx, el) {
|
|
|
192
217
|
return;
|
|
193
218
|
}
|
|
194
219
|
if (el.name === 'pre') {
|
|
195
|
-
const code = normalizeCode(textContent(el));
|
|
220
|
+
const code = normalizeCode(ctx.profile === 'starlight' ? starlightCode(el) : textContent(el));
|
|
196
221
|
if (code.trim() !== '')
|
|
197
222
|
pushBlock(ctx, { type: 'code', text: strictNormalize(code), code, links: [] }, el, el);
|
|
198
223
|
return;
|
|
@@ -225,9 +250,9 @@ function handleListItem(ctx, li) {
|
|
|
225
250
|
let run = newRun();
|
|
226
251
|
let ownFlushed = false;
|
|
227
252
|
for (const child of li.children) {
|
|
228
|
-
if (child instanceof Element && isSkipped(child, ctx.root))
|
|
253
|
+
if (child instanceof Element && isSkipped(child, ctx.root, ctx.profile))
|
|
229
254
|
continue;
|
|
230
|
-
if (child instanceof Element && BLOCK_TAGS.has(child.name)) {
|
|
255
|
+
if (child instanceof Element && (BLOCK_TAGS.has(child.name) || (ctx.profile === 'starlight' && child.name === 'starlight-tabs'))) {
|
|
231
256
|
if (!ownFlushed && child.name === 'p' && !hasBlockChild(child) && strictNormalize(run.text) === '') {
|
|
232
257
|
for (const c of child.children)
|
|
233
258
|
inlineText(ctx, c, run);
|
|
@@ -252,6 +277,85 @@ function handleListItem(ctx, li) {
|
|
|
252
277
|
}
|
|
253
278
|
flushRun(ctx, run, li, ownFlushed ? 'paragraph' : 'listItem');
|
|
254
279
|
}
|
|
280
|
+
/** Read only recognized direct line wrappers; never discard extra non-whitespace code children. */
|
|
281
|
+
function starlightCode(pre) {
|
|
282
|
+
if (!ancestor(pre, (node) => hasClass(node, 'expressive-code')))
|
|
283
|
+
return textContent(pre);
|
|
284
|
+
const meaningful = pre.children.filter((node) => !(node instanceof Text && !node.data.trim()));
|
|
285
|
+
const code = meaningful.length === 1 ? meaningful[0] : null;
|
|
286
|
+
if (!(code instanceof Element) || code.name !== 'code')
|
|
287
|
+
return textContent(pre);
|
|
288
|
+
const lines = code.children.filter((node) => !(node instanceof Text && !node.data.trim()));
|
|
289
|
+
if (lines.length === 0 || !lines.every((node) => node instanceof Element && node.name === 'div' && hasClass(node, 'ec-line')))
|
|
290
|
+
return textContent(pre);
|
|
291
|
+
// A gutter (line numbers from a plugin) sits beside the code as a direct child of the line; it is not code text.
|
|
292
|
+
const gutter = (node) => node instanceof Element && node.name === 'div' && hasClass(node, 'gutter');
|
|
293
|
+
return lines.map((line) => textContent(line.children.filter((node) => !gutter(node)))).join('\n');
|
|
294
|
+
}
|
|
295
|
+
/** Starlight's Markdown exporter represents every tab as a labelled list item, including inactive panels. */
|
|
296
|
+
function handleStarlightTabs(ctx, component) {
|
|
297
|
+
// A tab counts only when nothing between it and the component hides it. A panel counts only as a direct child of
|
|
298
|
+
// the component, the structure Starlight itself queries (':scope > [role="tabpanel"]'). A tab or panel inside a
|
|
299
|
+
// hidden, aria-hidden or otherwise skipped wrapper stays hidden like any other content.
|
|
300
|
+
const shown = (node) => {
|
|
301
|
+
for (let cur = node; cur instanceof Element && cur !== component; cur = cur.parent) {
|
|
302
|
+
if (isSkipped(cur, ctx.root, ctx.profile))
|
|
303
|
+
return false;
|
|
304
|
+
}
|
|
305
|
+
return true;
|
|
306
|
+
};
|
|
307
|
+
const own = (node) => ancestor(node, (parent) => parent.name === 'starlight-tabs') === component;
|
|
308
|
+
const tabs = selectAll('[role="tab"]', component).filter((node) => own(node) && shown(node));
|
|
309
|
+
const panels = component.children.filter((node) => node instanceof Element && node.attribs.role === 'tabpanel'
|
|
310
|
+
&& !isSkipped(node, ctx.root, ctx.profile, true));
|
|
311
|
+
if (!tabs.length || tabs.length !== panels.length)
|
|
312
|
+
throw new HtmlExtractError('Starlight tabs need one panel per tab.');
|
|
313
|
+
const panelById = new Map();
|
|
314
|
+
for (const panel of panels) {
|
|
315
|
+
const id = panel.attribs.id;
|
|
316
|
+
if (!id || panelById.has(id))
|
|
317
|
+
throw new HtmlExtractError('Starlight panel identifiers are missing or ambiguous.');
|
|
318
|
+
panelById.set(id, panel);
|
|
319
|
+
}
|
|
320
|
+
const controlNodes = new Set([...tabs, ...panels]);
|
|
321
|
+
// Unknown content beside the tab controls/panels must not disappear from the comparison.
|
|
322
|
+
const validateWrapper = (node) => {
|
|
323
|
+
if (node instanceof Text) {
|
|
324
|
+
if (node.data.trim())
|
|
325
|
+
throw new HtmlExtractError('Unexpected text outside Starlight tab labels and panels.');
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
if (!(node instanceof Element) || controlNodes.has(node))
|
|
329
|
+
return;
|
|
330
|
+
if (isSkipped(node, ctx.root, ctx.profile))
|
|
331
|
+
return;
|
|
332
|
+
for (const child of node.children)
|
|
333
|
+
validateWrapper(child);
|
|
334
|
+
};
|
|
335
|
+
for (const child of component.children)
|
|
336
|
+
validateWrapper(child);
|
|
337
|
+
const used = new Set();
|
|
338
|
+
const ids = new Set();
|
|
339
|
+
for (const tab of tabs) {
|
|
340
|
+
const id = tab.attribs.id;
|
|
341
|
+
const target = tab.attribs['aria-controls'] ?? (tab.attribs.href?.startsWith('#') ? tab.attribs.href.slice(1) : undefined);
|
|
342
|
+
if (!id || ids.has(id) || !target)
|
|
343
|
+
throw new HtmlExtractError('Starlight tab identifiers are missing or ambiguous.');
|
|
344
|
+
ids.add(id);
|
|
345
|
+
const panel = panelById.get(target);
|
|
346
|
+
if (!panel || panel.attribs['aria-labelledby'] !== id || used.has(panel))
|
|
347
|
+
throw new HtmlExtractError('Starlight tab/panel association is missing or ambiguous.');
|
|
348
|
+
used.add(panel);
|
|
349
|
+
// Only the associated panel's initial visibility is bypassed. Hidden descendants remain hidden.
|
|
350
|
+
const label = newRun();
|
|
351
|
+
for (const child of tab.children)
|
|
352
|
+
inlineText(ctx, child, label);
|
|
353
|
+
if (!strictNormalize(label.text))
|
|
354
|
+
throw new HtmlExtractError('Starlight tab label is empty.');
|
|
355
|
+
flushRun(ctx, label, tab, 'listItem');
|
|
356
|
+
walk(ctx, panel);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
255
359
|
function handleTable(ctx, table) {
|
|
256
360
|
const rows = selectAll('tr', table).filter((tr) => closestTable(tr) === table);
|
|
257
361
|
const cells = [];
|
|
@@ -315,6 +419,9 @@ function pickRoot(doc, selector, notes) {
|
|
|
315
419
|
throw new HtmlExtractError('Document has no <body> element.');
|
|
316
420
|
}
|
|
317
421
|
export function extractHtml(source, options = {}) {
|
|
422
|
+
const profile = options.profile ?? 'generic';
|
|
423
|
+
if (profile !== 'generic' && profile !== 'starlight')
|
|
424
|
+
throw new HtmlExtractError('Unknown HTML profile.');
|
|
318
425
|
const doc = parseDocument(source, { withStartIndices: true, withEndIndices: true, decodeEntities: true });
|
|
319
426
|
// Before any selector runs: the selector engine and the extraction below both recurse over the tree.
|
|
320
427
|
const maxDepth = options.maxDepth ?? MAX_NESTING_DEPTH;
|
|
@@ -334,7 +441,9 @@ export function extractHtml(source, options = {}) {
|
|
|
334
441
|
for (let i = 0; i < source.length; i++)
|
|
335
442
|
if (source.charCodeAt(i) === 10)
|
|
336
443
|
lineStarts.push(i + 1);
|
|
337
|
-
|
|
444
|
+
if (profile === 'starlight')
|
|
445
|
+
notes.push('Starlight profile: all associated tab panels are compared, including inactive panels; Expressive Code line boundaries and aside titles are retained.');
|
|
446
|
+
const ctx = { profile, base, source, lineStarts, blocks: [], notes, root };
|
|
338
447
|
walk(ctx, root);
|
|
339
|
-
return { blocks: ctx.blocks, strategy
|
|
448
|
+
return { blocks: ctx.blocks, strategy: profile === 'generic' ? strategy : `${strategy};profile:starlight`, confidence, notes, issues: [] };
|
|
340
449
|
}
|
package/dist/src/run.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ export interface SourceInput {
|
|
|
24
24
|
base: string | null;
|
|
25
25
|
}
|
|
26
26
|
export interface RunOptions {
|
|
27
|
+
htmlProfile?: 'generic' | 'starlight';
|
|
27
28
|
selector?: string;
|
|
28
29
|
/** Markdown front matter handling; 'keep' by default (nothing removed). */
|
|
29
30
|
frontMatter?: 'keep' | 'strip';
|
package/dist/src/run.js
CHANGED
|
@@ -96,7 +96,7 @@ export function run(html, markdown, options) {
|
|
|
96
96
|
throw new TypeError(`Limit maxNestingDepth must be a positive number (got ${String(maxDepth)}).`);
|
|
97
97
|
let h;
|
|
98
98
|
try {
|
|
99
|
-
h = extractHtml(html.body, { selector: options.selector, baseUrl: html.base, maxDepth });
|
|
99
|
+
h = extractHtml(html.body, { profile: options.htmlProfile, selector: options.selector, baseUrl: html.base, maxDepth });
|
|
100
100
|
}
|
|
101
101
|
catch (err) {
|
|
102
102
|
throw extractionError('HTML', err) ?? err;
|
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.8";
|
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.8';
|
package/package.json
CHANGED