markdown-parity-check 0.2.8 → 0.2.9

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/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.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";
3
+ export declare const HELP = "markdown-parity-check 0.2.9\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 {
package/dist/src/html.js CHANGED
@@ -86,8 +86,15 @@ function ancestor(el, predicate) {
86
86
  }
87
87
  return null;
88
88
  }
89
+ /** The link starlight-llms-txt writes for an iframe. hast-util-to-mdast keeps an iframe only when it has both a
90
+ * source and a title, as a link whose text is the title; any other iframe produces nothing. */
91
+ function iframeLink(el) {
92
+ const src = el.attribs['src'] ?? '';
93
+ const title = el.attribs['title'] ?? '';
94
+ return src && title ? { src, title } : null;
95
+ }
89
96
  function isSkipped(el, root, profile = 'generic', ignoreHidden = false) {
90
- if (SKIP_TAGS.has(el.name))
97
+ if (SKIP_TAGS.has(el.name) && !(profile === 'starlight' && el.name === 'iframe' && iframeLink(el)))
91
98
  return true;
92
99
  const role = (el.attribs['role'] ?? '').toLowerCase();
93
100
  if (SKIP_ROLES.has(role))
@@ -137,6 +144,14 @@ function inlineText(ctx, node, run) {
137
144
  run.text += ` ${alt} `;
138
145
  return;
139
146
  }
147
+ if (ctx.profile === 'starlight' && node.name === 'iframe') {
148
+ const link = iframeLink(node);
149
+ if (link) {
150
+ run.links.push({ text: strictNormalize(link.title), rawHref: link.src, resolved: resolveHref(link.src, ctx.base) });
151
+ run.text += link.title;
152
+ }
153
+ return;
154
+ }
140
155
  if (node.name === 'a' && node.attribs['href'] !== undefined) {
141
156
  const inner = newRun();
142
157
  for (const child of node.children)
@@ -290,7 +305,47 @@ function starlightCode(pre) {
290
305
  return textContent(pre);
291
306
  // A gutter (line numbers from a plugin) sits beside the code as a direct child of the line; it is not code text.
292
307
  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');
308
+ // starlight-llms-txt prefixes + or - to ins and del lines when the block has a language other than diff. The page
309
+ // shows those lines only through styling, so the marker is in the export and not in the HTML text.
310
+ const language = pre.attribs['data-language'];
311
+ const diffMarkers = Boolean(language) && language !== 'diff'
312
+ && lines.some((line) => line instanceof Element && (hasClass(line, 'ins') || hasClass(line, 'del')));
313
+ return lines.map((line) => starlightLineText(line.children.filter((node) => !gutter(node)), line, diffMarkers)).join('\n');
314
+ }
315
+ /** One Expressive Code line as starlight-llms-txt exports it. The marker goes before the first text of the first
316
+ * span that is not an indent span; a line whose first such span does not start with text gets no marker. */
317
+ function starlightLineText(children, line, diffMarkers) {
318
+ const inserted = hasClass(line, 'ins');
319
+ if (!diffMarkers || !(inserted || hasClass(line, 'del')))
320
+ return textContent(children);
321
+ const target = firstNonIndentSpan(children)?.children[0];
322
+ if (!(target instanceof Text))
323
+ return textContent(children);
324
+ let out = '';
325
+ const collect = (nodes) => {
326
+ for (const node of nodes) {
327
+ if (node instanceof Text)
328
+ out += (node === target ? (inserted ? '+' : '-') : '') + node.data;
329
+ else if (node instanceof Element)
330
+ collect(node.children);
331
+ }
332
+ };
333
+ collect(children);
334
+ return out;
335
+ }
336
+ /** The first span without the indent class in document order, the element hast-util-select finds for
337
+ * `span:not(.indent)` inside a line. */
338
+ function firstNonIndentSpan(nodes) {
339
+ for (const node of nodes) {
340
+ if (!(node instanceof Element))
341
+ continue;
342
+ if (node.name === 'span' && !hasClass(node, 'indent'))
343
+ return node;
344
+ const inner = firstNonIndentSpan(node.children);
345
+ if (inner)
346
+ return inner;
347
+ }
348
+ return null;
294
349
  }
295
350
  /** Starlight's Markdown exporter represents every tab as a labelled list item, including inactive panels. */
296
351
  function handleStarlightTabs(ctx, component) {
@@ -329,6 +384,8 @@ function handleStarlightTabs(ctx, component) {
329
384
  return;
330
385
  if (isSkipped(node, ctx.root, ctx.profile))
331
386
  return;
387
+ if (node.name === 'iframe')
388
+ throw new HtmlExtractError('Unexpected content outside Starlight tab labels and panels.');
332
389
  for (const child of node.children)
333
390
  validateWrapper(child);
334
391
  };
@@ -1,2 +1,2 @@
1
1
  export declare const TOOL_NAME = "markdown-parity-check";
2
- export declare const TOOL_VERSION = "0.2.8";
2
+ export declare const TOOL_VERSION = "0.2.9";
@@ -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.8';
5
+ export const TOOL_VERSION = '0.2.9';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markdown-parity-check",
3
- "version": "0.2.8",
3
+ "version": "0.2.9",
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",