markdown-parity-check 0.2.12 → 0.2.13
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 +2 -2
- package/dist/src/cli.d.ts +1 -1
- package/dist/src/compare.d.ts +12 -6
- package/dist/src/compare.js +91 -9
- package/dist/src/html.js +173 -41
- package/dist/src/markdown.js +72 -8
- package/dist/src/model.d.ts +12 -0
- package/dist/src/normalize.js +7 -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
|
@@ -62,9 +62,9 @@ Exit code 0 means the implemented checks found nothing to reject. It does not pr
|
|
|
62
62
|
|
|
63
63
|
## What is compared
|
|
64
64
|
|
|
65
|
-
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.
|
|
65
|
+
Without `--selector`, the HTML content comes from the first visible `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. Two visible elements of the same kind that do not contain one another also give a warning, because only the first is compared. 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.
|
|
66
66
|
|
|
67
|
-
Headings, paragraphs, list items, tables, code blocks and links are compared block by block. Missing and added blocks are errors.
|
|
67
|
+
Headings, paragraphs, list items, tables, code blocks and links are compared block by block. Content marked `hidden` or `aria-hidden` is left out on both sides, and a table caption counts as a paragraph before the table. Missing and added blocks are errors. A change in text or numbers is an error too, as is a changed table or link, and a list item that shows another number or task state. A difference in order, heading level, case, punctuation, list kind or nesting level is a warning. Footnotes in the Markdown are not compared. Each one is reported as a warning, and repeated blocks are reported too.
|
|
68
68
|
|
|
69
69
|
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.
|
|
70
70
|
|
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
|
+
export declare const HELP = "markdown-parity-check 0.2.13\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/compare.d.ts
CHANGED
|
@@ -25,12 +25,18 @@ export declare function diffNumbers(a: string[], b: string[]): {
|
|
|
25
25
|
after: string[];
|
|
26
26
|
} | null;
|
|
27
27
|
/**
|
|
28
|
-
* Pairs the HTML block's links with the Markdown block's
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
28
|
+
* Pairs the HTML block's links with the Markdown block's, in three steps.
|
|
29
|
+
*
|
|
30
|
+
* 1. Links whose text occurs equally often on both sides pair in document order: the first "download" with the
|
|
31
|
+
* first "download". Up to 0.2.12 every link took any unused link with the same text and target, so two links with
|
|
32
|
+
* the same text and swapped targets passed with no finding (0.2.13, found by an outside review 2026-09-26).
|
|
33
|
+
* 2. Every other link takes the first unused Markdown link, in document order, that has the same text and the same
|
|
34
|
+
* target, or else the first unused one with the same text. The Markdown links are indexed by text and, for a
|
|
35
|
+
* resolved HTML link, by text and target; an unresolved HTML link scans the links that share its text, because
|
|
36
|
+
* relativeHrefRelation compares two references and has no key of its own (0.2.12, where the old scans of the
|
|
37
|
+
* whole list made one block with 20 000 links take more than a second).
|
|
38
|
+
* 3. What is still unpaired pairs by loosely normalized text, the same way as step 1 and then in order, so a link
|
|
39
|
+
* whose text differs only in case or punctuation is one changed text and not a missing and an added link (0.2.13).
|
|
34
40
|
* @internal Exported for test/compare-links.test.ts.
|
|
35
41
|
*/
|
|
36
42
|
export declare function pairLinks(hLinks: Link[], mLinks: Link[]): {
|
package/dist/src/compare.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// The comparison core: aligns blocks and turns the alignment into findings. Pure and network-free.
|
|
2
2
|
import { align, UNCERTAIN_THRESHOLD } from './align.js';
|
|
3
|
-
import { excerpt, hrefDifference, maskHref, redactText, relativeHrefRelation, visibleNumbers } from './normalize.js';
|
|
3
|
+
import { excerpt, hrefDifference, looseNormalize, maskHref, redactText, relativeHrefRelation, visibleNumbers } from './normalize.js';
|
|
4
4
|
// The excerpt masks the whole block text before it cuts it, so it is computed once per block. Up to 0.2.11 every
|
|
5
5
|
// finding computed it again, and a block with thousands of link findings did that thousands of times (0.2.12).
|
|
6
6
|
const sides = new WeakMap();
|
|
@@ -59,12 +59,18 @@ export function diffNumbers(a, b) {
|
|
|
59
59
|
const linkText = (l, other) => (l.masked || other?.masked ? '***' : redactText(l.text));
|
|
60
60
|
const linkHref = (l, href) => (l.masked ? '***' : maskHref(href));
|
|
61
61
|
/**
|
|
62
|
-
* Pairs the HTML block's links with the Markdown block's
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
62
|
+
* Pairs the HTML block's links with the Markdown block's, in three steps.
|
|
63
|
+
*
|
|
64
|
+
* 1. Links whose text occurs equally often on both sides pair in document order: the first "download" with the
|
|
65
|
+
* first "download". Up to 0.2.12 every link took any unused link with the same text and target, so two links with
|
|
66
|
+
* the same text and swapped targets passed with no finding (0.2.13, found by an outside review 2026-09-26).
|
|
67
|
+
* 2. Every other link takes the first unused Markdown link, in document order, that has the same text and the same
|
|
68
|
+
* target, or else the first unused one with the same text. The Markdown links are indexed by text and, for a
|
|
69
|
+
* resolved HTML link, by text and target; an unresolved HTML link scans the links that share its text, because
|
|
70
|
+
* relativeHrefRelation compares two references and has no key of its own (0.2.12, where the old scans of the
|
|
71
|
+
* whole list made one block with 20 000 links take more than a second).
|
|
72
|
+
* 3. What is still unpaired pairs by loosely normalized text, the same way as step 1 and then in order, so a link
|
|
73
|
+
* whose text differs only in case or punctuation is one changed text and not a missing and an added link (0.2.13).
|
|
68
74
|
* @internal Exported for test/compare-links.test.ts.
|
|
69
75
|
*/
|
|
70
76
|
export function pairLinks(hLinks, mLinks) {
|
|
@@ -96,11 +102,25 @@ export function pairLinks(hLinks, mLinks) {
|
|
|
96
102
|
else
|
|
97
103
|
add(key('raw-unresolved', l.text, l.rawHref.trim()), i);
|
|
98
104
|
});
|
|
105
|
+
const count = (links) => {
|
|
106
|
+
const m = new Map();
|
|
107
|
+
for (const l of links)
|
|
108
|
+
m.set(l.text, (m.get(l.text) ?? 0) + 1);
|
|
109
|
+
return m;
|
|
110
|
+
};
|
|
111
|
+
const hCount = count(hLinks);
|
|
112
|
+
const mCount = count(mLinks);
|
|
113
|
+
const seenInH = new Map();
|
|
99
114
|
const pairs = [];
|
|
100
|
-
|
|
115
|
+
let missing = [];
|
|
101
116
|
hLinks.forEach((hl, hi) => {
|
|
102
117
|
let idx = -1;
|
|
103
|
-
|
|
118
|
+
const k = seenInH.get(hl.text) ?? 0;
|
|
119
|
+
seenInH.set(hl.text, k + 1);
|
|
120
|
+
if (hCount.get(hl.text) === mCount.get(hl.text)) {
|
|
121
|
+
idx = lists.get(key('text', hl.text))[k];
|
|
122
|
+
}
|
|
123
|
+
else if (hl.resolved !== null) {
|
|
104
124
|
// sameTarget: a resolved Markdown link with the same resolved href, or an unresolved one with the same raw href.
|
|
105
125
|
const a = first(key('resolved', hl.text, hl.resolved));
|
|
106
126
|
const b = first(key('raw-unresolved', hl.text, hl.rawHref.trim()));
|
|
@@ -124,6 +144,41 @@ export function pairLinks(hLinks, mLinks) {
|
|
|
124
144
|
used[idx] = true;
|
|
125
145
|
pairs.push([hi, idx]);
|
|
126
146
|
});
|
|
147
|
+
// Step 3: the links still unpaired, by loosely normalized text.
|
|
148
|
+
const looseLists = new Map();
|
|
149
|
+
used.forEach((u, i) => {
|
|
150
|
+
const k = u ? '' : looseNormalize(mLinks[i].text);
|
|
151
|
+
if (k === '')
|
|
152
|
+
return;
|
|
153
|
+
const list = looseLists.get(k);
|
|
154
|
+
if (list)
|
|
155
|
+
list.push(i);
|
|
156
|
+
else
|
|
157
|
+
looseLists.set(k, [i]);
|
|
158
|
+
});
|
|
159
|
+
const looseMissing = new Map();
|
|
160
|
+
for (const hi of missing) {
|
|
161
|
+
const k = looseNormalize(hLinks[hi].text);
|
|
162
|
+
if (k !== '')
|
|
163
|
+
looseMissing.set(k, (looseMissing.get(k) ?? 0) + 1);
|
|
164
|
+
}
|
|
165
|
+
const looseHeads = new Map();
|
|
166
|
+
const stillMissing = [];
|
|
167
|
+
for (const hi of missing) {
|
|
168
|
+
const k = looseNormalize(hLinks[hi].text);
|
|
169
|
+
const list = k === '' ? undefined : looseLists.get(k);
|
|
170
|
+
const n = looseHeads.get(k) ?? 0;
|
|
171
|
+
if (!list || n >= list.length) {
|
|
172
|
+
stillMissing.push(hi);
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
// Equal counts pair in order and unequal counts take the next in order, so both are the next unused link.
|
|
176
|
+
looseHeads.set(k, n + 1);
|
|
177
|
+
used[list[n]] = true;
|
|
178
|
+
pairs.push([hi, list[n]]);
|
|
179
|
+
}
|
|
180
|
+
missing = stillMissing;
|
|
181
|
+
pairs.sort((x, y) => x[0] - y[0]);
|
|
127
182
|
const added = [];
|
|
128
183
|
used.forEach((u, i) => {
|
|
129
184
|
if (!u)
|
|
@@ -175,6 +230,31 @@ function sameTarget(a, b) {
|
|
|
175
230
|
return relativeHrefRelation(a.rawHref, b.rawHref) === 'same';
|
|
176
231
|
return a.rawHref.trim() === b.rawHref.trim();
|
|
177
232
|
}
|
|
233
|
+
/**
|
|
234
|
+
* Where a list item sits in its list (0.2.13): the list kind and the nesting level are warnings, a changed item
|
|
235
|
+
* number and a changed task state are errors, because the reader sees a different number or a different state.
|
|
236
|
+
*/
|
|
237
|
+
function compareListItems(out, h, m) {
|
|
238
|
+
const a = h.list;
|
|
239
|
+
const b = m.list;
|
|
240
|
+
if (!a || !b)
|
|
241
|
+
return;
|
|
242
|
+
const kind = (o) => (o ? 'numbered' : 'bulleted');
|
|
243
|
+
if (a.ordered !== b.ordered) {
|
|
244
|
+
out.push({ code: 'LIST_KIND_CHANGED', severity: 'warning', direction: 'both', message: `The list item is in a ${kind(a.ordered)} list in the HTML and a ${kind(b.ordered)} list in the Markdown.`, html: side(h), markdown: side(m), before: kind(a.ordered), after: kind(b.ordered) });
|
|
245
|
+
}
|
|
246
|
+
else if (a.ordinal !== undefined && b.ordinal !== undefined && a.ordinal !== b.ordinal) {
|
|
247
|
+
out.push({ code: 'LIST_NUMBER_CHANGED', severity: 'error', direction: 'both', message: `List item number differs: ${a.ordinal} in the HTML, ${b.ordinal} in the Markdown.`, html: side(h), markdown: side(m), before: String(a.ordinal), after: String(b.ordinal) });
|
|
248
|
+
}
|
|
249
|
+
if (a.depth !== b.depth) {
|
|
250
|
+
out.push({ code: 'LIST_NESTING_CHANGED', severity: 'warning', direction: 'both', message: `List nesting level differs: level ${a.depth + 1} in the HTML, level ${b.depth + 1} in the Markdown.`, html: side(h), markdown: side(m), before: String(a.depth + 1), after: String(b.depth + 1) });
|
|
251
|
+
}
|
|
252
|
+
if (a.checked !== b.checked) {
|
|
253
|
+
const state = (c) => (c === null ? 'no checkbox' : c ? 'checked' : 'unchecked');
|
|
254
|
+
const one = a.checked === null || b.checked === null;
|
|
255
|
+
out.push({ code: 'LIST_TASK_CHANGED', severity: one ? 'warning' : 'error', direction: 'both', message: `Task state differs: ${state(a.checked)} in the HTML, ${state(b.checked)} in the Markdown.`, html: side(h), markdown: side(m), before: state(a.checked), after: state(b.checked) });
|
|
256
|
+
}
|
|
257
|
+
}
|
|
178
258
|
function compareTables(out, h, m) {
|
|
179
259
|
const hc = h.cells ?? [];
|
|
180
260
|
const mc = m.cells ?? [];
|
|
@@ -243,6 +323,8 @@ function comparePair(out, p, h, m, bothBases) {
|
|
|
243
323
|
out.push({ code: 'TEXT_CHANGED', severity: 'error', direction: 'both', message: `The ${label(h)} text differs.`, html: side(h), markdown: side(m), before: excerpt(h.text), after: excerpt(m.text) });
|
|
244
324
|
}
|
|
245
325
|
}
|
|
326
|
+
if (h.type === 'listItem' && m.type === 'listItem')
|
|
327
|
+
compareListItems(out, h, m);
|
|
246
328
|
compareLinks(out, h, m, bothBases);
|
|
247
329
|
}
|
|
248
330
|
const SEVERITY_ORDER = { error: 0, warning: 1, info: 2 };
|
package/dist/src/html.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
import { parseDocument } from 'htmlparser2';
|
|
4
4
|
import { selectAll, selectOne } from 'css-select';
|
|
5
5
|
import { Element, Text } from 'domhandler';
|
|
6
|
-
import { textContent } from 'domutils';
|
|
7
6
|
import { extractNumbers, looseNormalize, normalizeCode, resolveHref, strictNormalize } from './normalize.js';
|
|
8
7
|
export class HtmlExtractError extends Error {
|
|
9
8
|
}
|
|
@@ -51,28 +50,27 @@ function pathOf(ctx, el) {
|
|
|
51
50
|
const parts = [];
|
|
52
51
|
let cur = el;
|
|
53
52
|
while (cur) {
|
|
54
|
-
|
|
55
|
-
let sib = cur.prev;
|
|
56
|
-
while (sib) {
|
|
57
|
-
if (sib instanceof Element && sib.name === cur.name)
|
|
58
|
-
index++;
|
|
59
|
-
sib = sib.prev;
|
|
60
|
-
}
|
|
61
|
-
parts.unshift(index > 1 || hasLaterSameNamedSibling(cur) ? `${cur.name}:nth-of-type(${index})` : cur.name);
|
|
53
|
+
parts.unshift(segment(ctx, cur));
|
|
62
54
|
if (cur === ctx.root)
|
|
63
55
|
break;
|
|
64
56
|
cur = cur.parent instanceof Element ? cur.parent : null;
|
|
65
57
|
}
|
|
66
58
|
return parts.join(' > ');
|
|
67
59
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
60
|
+
/**
|
|
61
|
+
* The element's own part of a path: its tag name, with :nth-of-type(n) when the parent has more than one child of
|
|
62
|
+
* that name. The positions of all same-named siblings are computed at once and kept in ctx. Up to 0.2.12 every
|
|
63
|
+
* block counted its siblings again, so a list of 20 000 items took time quadratic in its length (found by an
|
|
64
|
+
* independent review before 0.2.13 was released).
|
|
65
|
+
*/
|
|
66
|
+
function segment(ctx, el) {
|
|
67
|
+
const known = ctx.segments.get(el);
|
|
68
|
+
if (known !== undefined)
|
|
69
|
+
return known;
|
|
70
|
+
const siblings = el.parent ? el.parent.children : [el];
|
|
71
|
+
const same = siblings.filter((c) => c instanceof Element && c.name === el.name);
|
|
72
|
+
same.forEach((c, i) => ctx.segments.set(c, same.length > 1 ? `${c.name}:nth-of-type(${i + 1})` : c.name));
|
|
73
|
+
return ctx.segments.get(el) ?? el.name;
|
|
76
74
|
}
|
|
77
75
|
function hasClass(el, name) {
|
|
78
76
|
return (el.attribs.class ?? '').split(/\s+/).includes(name);
|
|
@@ -93,6 +91,25 @@ function iframeLink(el) {
|
|
|
93
91
|
const title = el.attribs['title'] ?? '';
|
|
94
92
|
return src && title ? { src, title } : null;
|
|
95
93
|
}
|
|
94
|
+
/** The hidden and aria-hidden attributes alone, without the tag, role and page chrome rules of isSkipped. */
|
|
95
|
+
function hiddenAttr(el) {
|
|
96
|
+
return el.attribs['hidden'] !== undefined || el.attribs['aria-hidden'] === 'true';
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Text of code as the page shows it: every text node with its whitespace, except under a hidden or aria-hidden
|
|
100
|
+
* element. Up to 0.2.12 code used textContent, which also returns hidden descendants, so a hidden span inside a
|
|
101
|
+
* code block counted as code while the same span in a paragraph did not (found by an outside review 2026-09-26).
|
|
102
|
+
*/
|
|
103
|
+
function visibleCode(nodes) {
|
|
104
|
+
let out = '';
|
|
105
|
+
for (const node of nodes) {
|
|
106
|
+
if (node instanceof Text)
|
|
107
|
+
out += node.data;
|
|
108
|
+
else if (node instanceof Element && !hiddenAttr(node))
|
|
109
|
+
out += visibleCode(node.children);
|
|
110
|
+
}
|
|
111
|
+
return out;
|
|
112
|
+
}
|
|
96
113
|
function isSkipped(el, root, profile = 'generic', ignoreHidden = false) {
|
|
97
114
|
if (SKIP_TAGS.has(el.name) && !(profile === 'starlight' && el.name === 'iframe' && iframeLink(el)))
|
|
98
115
|
return true;
|
|
@@ -178,12 +195,12 @@ function pushBlock(ctx, partial, node, pathEl) {
|
|
|
178
195
|
};
|
|
179
196
|
ctx.blocks.push(block);
|
|
180
197
|
}
|
|
181
|
-
function flushRun(ctx, run, container, type = 'paragraph') {
|
|
198
|
+
function flushRun(ctx, run, container, type = 'paragraph', list) {
|
|
182
199
|
const text = strictNormalize(run.text);
|
|
183
200
|
if (text === '')
|
|
184
201
|
return;
|
|
185
202
|
const node = run.firstNode ?? container;
|
|
186
|
-
pushBlock(ctx, { type, text, links: run.links }, node, container);
|
|
203
|
+
pushBlock(ctx, { type, text, links: run.links, ...(type === 'listItem' && list ? { list } : {}) }, node, container);
|
|
187
204
|
}
|
|
188
205
|
function hasBlockChild(el) {
|
|
189
206
|
return el.children.some((c) => c instanceof Element && BLOCK_TAGS.has(c.name) && !SKIP_TAGS.has(c.name));
|
|
@@ -232,7 +249,7 @@ function handleBlock(ctx, el) {
|
|
|
232
249
|
return;
|
|
233
250
|
}
|
|
234
251
|
if (el.name === 'pre') {
|
|
235
|
-
const code = normalizeCode(ctx.profile === 'starlight' ? starlightCode(el) :
|
|
252
|
+
const code = normalizeCode(ctx.profile === 'starlight' ? starlightCode(el) : visibleCode(el.children));
|
|
236
253
|
if (code.trim() !== '')
|
|
237
254
|
pushBlock(ctx, { type: 'code', text: strictNormalize(code), code, links: [] }, el, el);
|
|
238
255
|
return;
|
|
@@ -242,10 +259,13 @@ function handleBlock(ctx, el) {
|
|
|
242
259
|
return;
|
|
243
260
|
}
|
|
244
261
|
if (el.name === 'ul' || el.name === 'ol') {
|
|
262
|
+
// A hidden item or list is skipped like any other hidden element (0.2.13; up to 0.2.12 it was read).
|
|
245
263
|
for (const c of el.children) {
|
|
246
|
-
if (c instanceof Element
|
|
264
|
+
if (!(c instanceof Element) || isSkipped(c, ctx.root, ctx.profile))
|
|
265
|
+
continue;
|
|
266
|
+
if (c.name === 'li')
|
|
247
267
|
handleListItem(ctx, c);
|
|
248
|
-
else if (c
|
|
268
|
+
else if (c.name === 'ul' || c.name === 'ol')
|
|
249
269
|
handleBlock(ctx, c);
|
|
250
270
|
}
|
|
251
271
|
return;
|
|
@@ -259,9 +279,74 @@ function handleBlock(ctx, el) {
|
|
|
259
279
|
// Generic container (div, section, article, blockquote, figure, details, header, footer, ...).
|
|
260
280
|
walk(ctx, el);
|
|
261
281
|
}
|
|
282
|
+
/**
|
|
283
|
+
* Where an item sits in its list (0.2.13). Up to 0.2.12 a list item carried its text only, so a changed start
|
|
284
|
+
* number, nesting level or task state passed unreported (found by an outside review 2026-09-26).
|
|
285
|
+
*/
|
|
286
|
+
function listInfo(ctx, li) {
|
|
287
|
+
const parent = li.parent instanceof Element ? li.parent : null;
|
|
288
|
+
const ordered = parent?.name === 'ol';
|
|
289
|
+
let lists = 0;
|
|
290
|
+
for (let p = li.parent; p instanceof Element; p = p.parent) {
|
|
291
|
+
if (p.name === 'ul' || p.name === 'ol')
|
|
292
|
+
lists++;
|
|
293
|
+
if (p === ctx.root)
|
|
294
|
+
break;
|
|
295
|
+
}
|
|
296
|
+
const info = { ordered, depth: ctx.listBase + Math.max(0, lists - 1), checked: taskState(li) };
|
|
297
|
+
if (ordered && parent) {
|
|
298
|
+
const ordinal = listOrdinals(ctx, parent).get(li);
|
|
299
|
+
if (ordinal !== undefined)
|
|
300
|
+
info.ordinal = ordinal;
|
|
301
|
+
}
|
|
302
|
+
return info;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* The numbers the visible items of a numbered list show, the way a browser's list counter counts them: from the
|
|
306
|
+
* list's start, or from the item count for a reversed list without one, and an item's value attribute sets the
|
|
307
|
+
* number from that item on. One pass per list, kept in ctx; the first version counted again for every item, and
|
|
308
|
+
* a list of 20 000 items took ten seconds (found by an independent review before 0.2.13 was released). A reversed
|
|
309
|
+
* list gives only its first item a number: Markdown has no reversed list and numbers every item from the first,
|
|
310
|
+
* so the later numbers of a faithful Markdown copy can never match.
|
|
311
|
+
*/
|
|
312
|
+
function listOrdinals(ctx, ol) {
|
|
313
|
+
const cached = ctx.ordinals.get(ol);
|
|
314
|
+
if (cached)
|
|
315
|
+
return cached;
|
|
316
|
+
const out = new Map();
|
|
317
|
+
const items = ol.children.filter((c) => c instanceof Element && c.name === 'li' && !isSkipped(c, ctx.root, ctx.profile));
|
|
318
|
+
const reversed = ol.attribs['reversed'] !== undefined;
|
|
319
|
+
const start = Number.parseInt(ol.attribs['start'] ?? '', 10);
|
|
320
|
+
let n = Number.isFinite(start) ? start : reversed ? items.length : 1;
|
|
321
|
+
items.forEach((item, i) => {
|
|
322
|
+
const value = Number.parseInt(item.attribs['value'] ?? '', 10);
|
|
323
|
+
if (Number.isFinite(value))
|
|
324
|
+
n = value;
|
|
325
|
+
if (!reversed || i === 0)
|
|
326
|
+
out.set(item, n);
|
|
327
|
+
n += reversed ? -1 : 1;
|
|
328
|
+
});
|
|
329
|
+
ctx.ordinals.set(ol, out);
|
|
330
|
+
return out;
|
|
331
|
+
}
|
|
332
|
+
/** The state of the item's own checkbox, not one inside a nested list: true, false, or null without one. */
|
|
333
|
+
function taskState(li) {
|
|
334
|
+
const stack = [...li.children].reverse();
|
|
335
|
+
while (stack.length > 0) {
|
|
336
|
+
const node = stack.pop();
|
|
337
|
+
if (!(node instanceof Element) || node.name === 'ul' || node.name === 'ol')
|
|
338
|
+
continue;
|
|
339
|
+
if (node.name === 'input' && (node.attribs['type'] ?? '').toLowerCase() === 'checkbox')
|
|
340
|
+
return node.attribs['checked'] !== undefined;
|
|
341
|
+
for (let i = node.children.length - 1; i >= 0; i--)
|
|
342
|
+
stack.push(node.children[i]);
|
|
343
|
+
}
|
|
344
|
+
return null;
|
|
345
|
+
}
|
|
262
346
|
function handleListItem(ctx, li) {
|
|
263
347
|
// The item's own inline text (and inline text of a leading <p>) becomes one listItem block; nested lists
|
|
264
348
|
// and other block children recurse.
|
|
349
|
+
const info = listInfo(ctx, li);
|
|
265
350
|
let run = newRun();
|
|
266
351
|
let ownFlushed = false;
|
|
267
352
|
for (const child of li.children) {
|
|
@@ -276,7 +361,7 @@ function handleListItem(ctx, li) {
|
|
|
276
361
|
continue;
|
|
277
362
|
}
|
|
278
363
|
if (!ownFlushed) {
|
|
279
|
-
flushRun(ctx, run, li, 'listItem');
|
|
364
|
+
flushRun(ctx, run, li, 'listItem', info);
|
|
280
365
|
ownFlushed = true;
|
|
281
366
|
run = newRun();
|
|
282
367
|
}
|
|
@@ -290,19 +375,19 @@ function handleListItem(ctx, li) {
|
|
|
290
375
|
inlineText(ctx, child, run);
|
|
291
376
|
}
|
|
292
377
|
}
|
|
293
|
-
flushRun(ctx, run, li, ownFlushed ? 'paragraph' : 'listItem');
|
|
378
|
+
flushRun(ctx, run, li, ownFlushed ? 'paragraph' : 'listItem', info);
|
|
294
379
|
}
|
|
295
380
|
/** Read only recognized direct line wrappers; never discard extra non-whitespace code children. */
|
|
296
381
|
function starlightCode(pre) {
|
|
297
382
|
if (!ancestor(pre, (node) => hasClass(node, 'expressive-code')))
|
|
298
|
-
return
|
|
383
|
+
return visibleCode(pre.children);
|
|
299
384
|
const meaningful = pre.children.filter((node) => !(node instanceof Text && !node.data.trim()));
|
|
300
385
|
const code = meaningful.length === 1 ? meaningful[0] : null;
|
|
301
386
|
if (!(code instanceof Element) || code.name !== 'code')
|
|
302
|
-
return
|
|
387
|
+
return visibleCode(pre.children);
|
|
303
388
|
const lines = code.children.filter((node) => !(node instanceof Text && !node.data.trim()));
|
|
304
389
|
if (lines.length === 0 || !lines.every((node) => node instanceof Element && node.name === 'div' && hasClass(node, 'ec-line')))
|
|
305
|
-
return
|
|
390
|
+
return visibleCode(pre.children);
|
|
306
391
|
// A gutter (line numbers from a plugin) sits beside the code as a direct child of the line; it is not code text.
|
|
307
392
|
const gutter = (node) => node instanceof Element && node.name === 'div' && hasClass(node, 'gutter');
|
|
308
393
|
// starlight-llms-txt prefixes + or - to ins and del lines when the block has a language other than diff. The page
|
|
@@ -317,16 +402,16 @@ function starlightCode(pre) {
|
|
|
317
402
|
function starlightLineText(children, line, diffMarkers) {
|
|
318
403
|
const inserted = hasClass(line, 'ins');
|
|
319
404
|
if (!diffMarkers || !(inserted || hasClass(line, 'del')))
|
|
320
|
-
return
|
|
405
|
+
return visibleCode(children);
|
|
321
406
|
const target = firstNonIndentSpan(children)?.children[0];
|
|
322
407
|
if (!(target instanceof Text))
|
|
323
|
-
return
|
|
408
|
+
return visibleCode(children);
|
|
324
409
|
let out = '';
|
|
325
410
|
const collect = (nodes) => {
|
|
326
411
|
for (const node of nodes) {
|
|
327
412
|
if (node instanceof Text)
|
|
328
413
|
out += (node === target ? (inserted ? '+' : '-') : '') + node.data;
|
|
329
|
-
else if (node instanceof Element)
|
|
414
|
+
else if (node instanceof Element && !hiddenAttr(node))
|
|
330
415
|
collect(node.children);
|
|
331
416
|
}
|
|
332
417
|
};
|
|
@@ -409,18 +494,38 @@ function handleStarlightTabs(ctx, component) {
|
|
|
409
494
|
inlineText(ctx, child, label);
|
|
410
495
|
if (!strictNormalize(label.text))
|
|
411
496
|
throw new HtmlExtractError('Starlight tab label is empty.');
|
|
412
|
-
flushRun(ctx, label, tab, 'listItem');
|
|
497
|
+
flushRun(ctx, label, tab, 'listItem', { ordered: false, depth: ctx.listBase, checked: null });
|
|
498
|
+
ctx.listBase++;
|
|
413
499
|
walk(ctx, panel);
|
|
500
|
+
ctx.listBase--;
|
|
414
501
|
}
|
|
415
502
|
}
|
|
416
503
|
function handleTable(ctx, table) {
|
|
417
|
-
|
|
504
|
+
// The caption is content: a paragraph before the table, the way a Markdown table's title has to be written. Up to
|
|
505
|
+
// 0.2.12 it was dropped with its text, numbers and links (found by an outside review 2026-09-26).
|
|
506
|
+
for (const child of table.children) {
|
|
507
|
+
if (child instanceof Element && child.name === 'caption' && !isSkipped(child, ctx.root, ctx.profile)) {
|
|
508
|
+
const run = newRun();
|
|
509
|
+
for (const c of child.children)
|
|
510
|
+
inlineText(ctx, c, run);
|
|
511
|
+
flushRun(ctx, run, child);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
// Hidden rows, row groups and cells are skipped like any other hidden element (0.2.13; up to 0.2.12 they were read).
|
|
515
|
+
const shown = (tr) => {
|
|
516
|
+
for (let cur = tr; cur instanceof Element && cur !== table; cur = cur.parent) {
|
|
517
|
+
if (isSkipped(cur, ctx.root, ctx.profile))
|
|
518
|
+
return false;
|
|
519
|
+
}
|
|
520
|
+
return true;
|
|
521
|
+
};
|
|
522
|
+
const rows = selectAll('tr', table).filter((tr) => closestTable(tr) === table && shown(tr));
|
|
418
523
|
const cells = [];
|
|
419
524
|
const links = [];
|
|
420
525
|
for (const tr of rows) {
|
|
421
526
|
const row = [];
|
|
422
527
|
for (const cell of tr.children) {
|
|
423
|
-
if (cell instanceof Element && (cell.name === 'td' || cell.name === 'th')) {
|
|
528
|
+
if (cell instanceof Element && (cell.name === 'td' || cell.name === 'th') && !isSkipped(cell, ctx.root, ctx.profile)) {
|
|
424
529
|
const run = newRun();
|
|
425
530
|
for (const c of cell.children)
|
|
426
531
|
inlineText(ctx, c, run);
|
|
@@ -445,7 +550,15 @@ function closestTable(el) {
|
|
|
445
550
|
}
|
|
446
551
|
return null;
|
|
447
552
|
}
|
|
448
|
-
|
|
553
|
+
/** Whether the page hides an element: it or an ancestor carries hidden or aria-hidden, or sits in a template. */
|
|
554
|
+
function hiddenInPage(el) {
|
|
555
|
+
for (let cur = el; cur instanceof Element; cur = cur.parent) {
|
|
556
|
+
if (hiddenAttr(cur) || cur.name === 'template')
|
|
557
|
+
return true;
|
|
558
|
+
}
|
|
559
|
+
return false;
|
|
560
|
+
}
|
|
561
|
+
function pickRoot(doc, selector, notes, issues) {
|
|
449
562
|
if (selector) {
|
|
450
563
|
let matches;
|
|
451
564
|
try {
|
|
@@ -460,12 +573,30 @@ function pickRoot(doc, selector, notes) {
|
|
|
460
573
|
notes.push(`Selector "${selector}" matched ${matches.length} elements; the first in document order was used.`);
|
|
461
574
|
return { root: matches[0], strategy: `selector:${selector}`, confidence: 'high' };
|
|
462
575
|
}
|
|
576
|
+
// A candidate the page hides is not its main content. Up to 0.2.12 the first candidate was taken as it was, so a
|
|
577
|
+
// hidden <main> before the visible one was compared in its place and the visible content not at all. Candidates
|
|
578
|
+
// that do not sit inside one another are separate content, and only the first is compared, so that is a warning;
|
|
579
|
+
// one nested inside another (an <article> inside an <article>) is part of it (found by an outside review 2026-09-26).
|
|
463
580
|
for (const tag of ['main', 'article', '[role=main]']) {
|
|
464
581
|
const matches = selectAll(tag, doc.children).filter((n) => n instanceof Element);
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
582
|
+
const visible = matches.filter((el) => !hiddenInPage(el));
|
|
583
|
+
if (matches.length > visible.length)
|
|
584
|
+
notes.push(`${matches.length - visible.length} hidden <${tag}> element(s) were not used as the main content.`);
|
|
585
|
+
if (visible.length >= 1) {
|
|
586
|
+
const set = new Set(visible);
|
|
587
|
+
const outer = visible.filter((el) => {
|
|
588
|
+
for (let cur = el.parent; cur instanceof Element; cur = cur.parent)
|
|
589
|
+
if (set.has(cur))
|
|
590
|
+
return false;
|
|
591
|
+
return true;
|
|
592
|
+
});
|
|
593
|
+
if (outer.length > 1) {
|
|
594
|
+
issues.push({ code: 'EXTRACTION_MULTIPLE_ROOTS', severity: 'warning', message: `${outer.length} visible <${tag}> elements that do not contain one another were found; only the first in document order was compared. Use --selector to choose the content.` });
|
|
595
|
+
}
|
|
596
|
+
else if (visible.length > 1) {
|
|
597
|
+
notes.push(`${visible.length} <${tag}> elements found, nested inside the first; the first was used.`);
|
|
598
|
+
}
|
|
599
|
+
return { root: outer[0], strategy: tag, confidence: 'high' };
|
|
469
600
|
}
|
|
470
601
|
}
|
|
471
602
|
const body = selectOne('body', doc.children);
|
|
@@ -486,6 +617,7 @@ export function extractHtml(source, options = {}) {
|
|
|
486
617
|
if (depth > maxDepth)
|
|
487
618
|
throw new HtmlExtractError(`HTML nesting depth ${depth} exceeds the limit of ${maxDepth} levels; the comparison was not run.`);
|
|
488
619
|
const notes = [];
|
|
620
|
+
const issues = [];
|
|
489
621
|
const baseEl = selectOne('base[href]', doc.children);
|
|
490
622
|
let base = options.baseUrl ?? null;
|
|
491
623
|
if (baseEl instanceof Element && baseEl.attribs['href']) {
|
|
@@ -493,14 +625,14 @@ export function extractHtml(source, options = {}) {
|
|
|
493
625
|
if (resolved)
|
|
494
626
|
base = resolved;
|
|
495
627
|
}
|
|
496
|
-
const { root, strategy, confidence } = pickRoot(doc, options.selector, notes);
|
|
628
|
+
const { root, strategy, confidence } = pickRoot(doc, options.selector, notes, issues);
|
|
497
629
|
const lineStarts = [0];
|
|
498
630
|
for (let i = 0; i < source.length; i++)
|
|
499
631
|
if (source.charCodeAt(i) === 10)
|
|
500
632
|
lineStarts.push(i + 1);
|
|
501
633
|
if (profile === 'starlight')
|
|
502
634
|
notes.push('Starlight profile: all associated tab panels are compared, including inactive panels; Expressive Code line boundaries and aside titles are retained.');
|
|
503
|
-
const ctx = { profile, base, source, lineStarts, blocks: [], notes, root };
|
|
635
|
+
const ctx = { profile, base, source, lineStarts, blocks: [], notes, root, listBase: 0, ordinals: new Map(), segments: new Map() };
|
|
504
636
|
// A selector that picks a heading, list item, table or pre keeps that block type, so the root goes
|
|
505
637
|
// through handleBlock. Every other root is read as a container, a list included: handleBlock's list
|
|
506
638
|
// branch reads only <li> children, and a root list would lose any other content it holds.
|
|
@@ -508,5 +640,5 @@ export function extractHtml(source, options = {}) {
|
|
|
508
640
|
handleBlock(ctx, root);
|
|
509
641
|
else
|
|
510
642
|
walk(ctx, root);
|
|
511
|
-
return { blocks: ctx.blocks, strategy: profile === 'generic' ? strategy : `${strategy};profile:starlight`, confidence, notes, issues
|
|
643
|
+
return { blocks: ctx.blocks, strategy: profile === 'generic' ? strategy : `${strategy};profile:starlight`, confidence, notes, issues };
|
|
512
644
|
}
|
package/dist/src/markdown.js
CHANGED
|
@@ -45,6 +45,7 @@ function parseInlineTag(value) {
|
|
|
45
45
|
* text, <br> a space, everything else is dropped while the text between tags stays.
|
|
46
46
|
*/
|
|
47
47
|
function inlineChildren(ctx, children, run, line) {
|
|
48
|
+
let closes = null;
|
|
48
49
|
for (let i = 0; i < children.length; i++) {
|
|
49
50
|
const node = children[i];
|
|
50
51
|
if (node.type !== 'html') {
|
|
@@ -54,6 +55,21 @@ function inlineChildren(ctx, children, run, line) {
|
|
|
54
55
|
const tag = parseInlineTag(node.value);
|
|
55
56
|
if (!tag)
|
|
56
57
|
continue; // comment or unparsable fragment: no visible content
|
|
58
|
+
// A hidden inline element hides its text in a reader that renders the HTML, as the same attribute does on the
|
|
59
|
+
// HTML side. Up to 0.2.12 only the tags were dropped and the text between them stayed (found by an outside review
|
|
60
|
+
// 2026-09-26). Its content up to the matching closing tag is left out; without one the tag is reported.
|
|
61
|
+
if (!tag.closing && (tag.attribs['hidden'] !== undefined || tag.attribs['aria-hidden'] === 'true')) {
|
|
62
|
+
if (VOID_TAGS.has(tag.name) || /\/>\s*$/.test(node.value))
|
|
63
|
+
continue;
|
|
64
|
+
closes ??= closingTags(children);
|
|
65
|
+
const end = closes.get(i) ?? -1;
|
|
66
|
+
if (end < 0) {
|
|
67
|
+
ctx.issues.push({ code: 'MARKDOWN_INLINE_HTML_UNSUPPORTED', severity: 'warning', message: `A hidden inline <${tag.name}> has no matching </${tag.name}> in the same paragraph; its text was compared as visible.`, line: node.position?.start.line ?? line, excerpt: excerpt(node.value) });
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
i = end;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
57
73
|
if (tag.closing) {
|
|
58
74
|
if (tag.name === 'a')
|
|
59
75
|
ctx.issues.push({ code: 'MARKDOWN_INLINE_HTML_UNSUPPORTED', severity: 'warning', message: 'A closing </a> without an opening <a> in the same paragraph; the inline HTML structure could not be resolved reliably.', line: node.position?.start.line ?? line, excerpt: excerpt(node.value) });
|
|
@@ -100,6 +116,33 @@ function inlineChildren(ctx, children, run, line) {
|
|
|
100
116
|
i = end;
|
|
101
117
|
}
|
|
102
118
|
}
|
|
119
|
+
const VOID_TAGS = new Set(['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'source', 'track', 'wbr']);
|
|
120
|
+
/**
|
|
121
|
+
* For every opening tag among the inline nodes of a paragraph, the index of its matching closing tag, counting
|
|
122
|
+
* nested tags of the same name; an opening tag without one is absent. One pass with a stack per tag name, computed
|
|
123
|
+
* once per paragraph. The first version scanned forward from each hidden tag, so a paragraph with 20 000 unclosed
|
|
124
|
+
* hidden tags took two minutes (found by an independent review before 0.2.13 was released).
|
|
125
|
+
*/
|
|
126
|
+
function closingTags(children) {
|
|
127
|
+
const out = new Map();
|
|
128
|
+
const open = new Map();
|
|
129
|
+
children.forEach((c, j) => {
|
|
130
|
+
if (c.type !== 'html')
|
|
131
|
+
return;
|
|
132
|
+
const t = parseInlineTag(c.value);
|
|
133
|
+
if (!t)
|
|
134
|
+
return;
|
|
135
|
+
const stack = open.get(t.name) ?? [];
|
|
136
|
+
if (!t.closing) {
|
|
137
|
+
stack.push(j);
|
|
138
|
+
open.set(t.name, stack);
|
|
139
|
+
}
|
|
140
|
+
else if (stack.length > 0) {
|
|
141
|
+
out.set(stack.pop(), j);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
return out;
|
|
145
|
+
}
|
|
103
146
|
function inline(ctx, node, run) {
|
|
104
147
|
switch (node.type) {
|
|
105
148
|
case 'text':
|
|
@@ -192,7 +235,7 @@ function handleTable(ctx, table) {
|
|
|
192
235
|
const text = cells.map((r) => r.join(' | ')).join(' \n ');
|
|
193
236
|
push(ctx, { type: 'table', text: strictNormalize(text), cells, links }, table);
|
|
194
237
|
}
|
|
195
|
-
function handle(ctx, node, listItem
|
|
238
|
+
function handle(ctx, node, listItem) {
|
|
196
239
|
switch (node.type) {
|
|
197
240
|
case 'heading': {
|
|
198
241
|
const run = { text: '', links: [] };
|
|
@@ -207,7 +250,7 @@ function handle(ctx, node, listItem = false) {
|
|
|
207
250
|
inlineChildren(ctx, node.children, run, node.position?.start.line);
|
|
208
251
|
const text = strictNormalize(run.text);
|
|
209
252
|
if (text !== '')
|
|
210
|
-
push(ctx, { type: listItem ? 'listItem' : 'paragraph', text, links: run.links }, node);
|
|
253
|
+
push(ctx, { type: listItem ? 'listItem' : 'paragraph', text, links: run.links, ...(listItem ? { list: listItem } : {}) }, node);
|
|
211
254
|
return;
|
|
212
255
|
}
|
|
213
256
|
case 'code': {
|
|
@@ -219,17 +262,25 @@ function handle(ctx, node, listItem = false) {
|
|
|
219
262
|
case 'table':
|
|
220
263
|
handleTable(ctx, node);
|
|
221
264
|
return;
|
|
222
|
-
case 'list':
|
|
265
|
+
case 'list': {
|
|
266
|
+
// A Markdown list shows its start number and counts on; its items carry the list kind, the nesting level and
|
|
267
|
+
// the task state for the comparison (0.2.13).
|
|
268
|
+
let n = typeof node.start === 'number' ? node.start : 1;
|
|
223
269
|
for (const item of node.children) {
|
|
270
|
+
const info = { ordered: node.ordered === true, depth: ctx.listDepth, checked: typeof item.checked === 'boolean' ? item.checked : null };
|
|
271
|
+
if (node.ordered === true)
|
|
272
|
+
info.ordinal = n;
|
|
273
|
+
n++;
|
|
274
|
+
ctx.listDepth++;
|
|
224
275
|
let first = true;
|
|
225
276
|
for (const child of item.children) {
|
|
226
|
-
handle(ctx, child, first && child.type === 'paragraph');
|
|
277
|
+
handle(ctx, child, first && child.type === 'paragraph' ? info : undefined);
|
|
227
278
|
first = false;
|
|
228
279
|
}
|
|
229
|
-
|
|
230
|
-
continue;
|
|
280
|
+
ctx.listDepth--;
|
|
231
281
|
}
|
|
232
282
|
return;
|
|
283
|
+
}
|
|
233
284
|
case 'blockquote':
|
|
234
285
|
for (const c of node.children)
|
|
235
286
|
handle(ctx, c);
|
|
@@ -237,9 +288,14 @@ function handle(ctx, node, listItem = false) {
|
|
|
237
288
|
case 'html':
|
|
238
289
|
handleRawHtml(ctx, node.value, node.position?.start.line);
|
|
239
290
|
return;
|
|
291
|
+
case 'footnoteDefinition':
|
|
292
|
+
// Footnotes are not compared: an HTML page renders them as a numbered list with back links, which would not
|
|
293
|
+
// read as the Markdown definitions. Up to 0.2.12 a definition was dropped without a trace, so a footnote added
|
|
294
|
+
// to the Markdown passed strict mode (found by an outside review 2026-09-26). It is now a warning with its text.
|
|
295
|
+
ctx.issues.push({ code: 'MARKDOWN_FOOTNOTE_NOT_COMPARED', severity: 'warning', message: `Footnote [^${node.identifier}] is not compared; its text, numbers and links were left out of the comparison.`, line: node.position?.start.line, excerpt: excerpt(footnoteText(node)) });
|
|
296
|
+
return;
|
|
240
297
|
case 'thematicBreak':
|
|
241
298
|
case 'definition':
|
|
242
|
-
case 'footnoteDefinition':
|
|
243
299
|
case 'yaml':
|
|
244
300
|
return;
|
|
245
301
|
default:
|
|
@@ -248,6 +304,14 @@ function handle(ctx, node, listItem = false) {
|
|
|
248
304
|
handle(ctx, c);
|
|
249
305
|
}
|
|
250
306
|
}
|
|
307
|
+
/** Plain text of a footnote definition for the report excerpt. */
|
|
308
|
+
function footnoteText(node) {
|
|
309
|
+
if ('value' in node && typeof node.value === 'string')
|
|
310
|
+
return node.value;
|
|
311
|
+
if ('children' in node)
|
|
312
|
+
return node.children.map((c) => footnoteText(c)).join(' ');
|
|
313
|
+
return '';
|
|
314
|
+
}
|
|
251
315
|
/** A raw HTML block in Markdown is parsed with the HTML extractor so its content takes part in the
|
|
252
316
|
* comparison; the report shows that this happened. Comments and bare tags without text yield nothing. */
|
|
253
317
|
function handleRawHtml(ctx, value, line) {
|
|
@@ -338,7 +402,7 @@ export function extractMarkdown(source, options = {}) {
|
|
|
338
402
|
const depth = treeDepth(tree);
|
|
339
403
|
if (depth > maxDepth)
|
|
340
404
|
throw new MarkdownExtractError(`Markdown nesting depth ${depth} exceeds the limit of ${maxDepth} levels; the comparison was not run.`);
|
|
341
|
-
const ctx = { base: options.baseUrl ?? null, source: fm.text, blocks: [], notes: [], issues: [], definitions: collectDefinitions(tree) };
|
|
405
|
+
const ctx = { base: options.baseUrl ?? null, source: fm.text, blocks: [], notes: [], issues: [], definitions: collectDefinitions(tree), listDepth: 0 };
|
|
342
406
|
const fmExcerpt = () => excerpt(fm.body.replace(/\s+/g, ' '));
|
|
343
407
|
if (mode === 'strip' && fm.skippedLines > 0) {
|
|
344
408
|
ctx.notes.push(`Front matter (${fm.skippedLines} lines) was stripped as requested (--front-matter strip).`);
|
package/dist/src/model.d.ts
CHANGED
|
@@ -30,10 +30,22 @@ export interface Block {
|
|
|
30
30
|
cells?: string[][];
|
|
31
31
|
/** Code content after normalizeCode: line endings normalized to LF and trailing newlines removed. Only for type 'code'. */
|
|
32
32
|
code?: string;
|
|
33
|
+
/** Where a list item sits in its list. Only for type 'listItem' (0.2.13). */
|
|
34
|
+
list?: ListInfo;
|
|
33
35
|
links: Link[];
|
|
34
36
|
numbers: string[];
|
|
35
37
|
location: Location;
|
|
36
38
|
}
|
|
39
|
+
export interface ListInfo {
|
|
40
|
+
/** A numbered list (ol, or a Markdown list with numbers). */
|
|
41
|
+
ordered: boolean;
|
|
42
|
+
/** Nesting level, 0 for a top-level list. */
|
|
43
|
+
depth: number;
|
|
44
|
+
/** The number the item shows, only in a numbered list: the list start or the item value, counted on. */
|
|
45
|
+
ordinal?: number;
|
|
46
|
+
/** Task item state: true checked, false unchecked, null when the item has no checkbox. */
|
|
47
|
+
checked: boolean | null;
|
|
48
|
+
}
|
|
37
49
|
export interface Extraction {
|
|
38
50
|
blocks: Block[];
|
|
39
51
|
/** How the main content was selected. */
|
package/dist/src/normalize.js
CHANGED
|
@@ -3,7 +3,12 @@
|
|
|
3
3
|
// classifies minor text differences (TEXT_MINOR_CHANGED).
|
|
4
4
|
const NBSP = /[\u00a0\u2007\u202f]/g;
|
|
5
5
|
const WS = /[ \t\r\n\f\v]+/g;
|
|
6
|
-
|
|
6
|
+
// Zero width space, byte order mark and soft hyphen: invisible artefacts of editing and export. Up to 0.2.12 the
|
|
7
|
+
// zero width joiner and non-joiner went with them, and two texts that render differently, such as an emoji
|
|
8
|
+
// sequence with and without its joiner, compared equal (found by an outside review 2026-09-26). They stay in the
|
|
9
|
+
// strict text now, and JOINERS takes them out of the loose text, so a difference in them alone is a minor change.
|
|
10
|
+
const ZERO_WIDTH = /[\u200b\ufeff\u00ad]/g;
|
|
11
|
+
const JOINERS = /[\u200c\u200d]/g;
|
|
7
12
|
export function strictNormalize(text) {
|
|
8
13
|
return text
|
|
9
14
|
.normalize('NFC')
|
|
@@ -14,6 +19,7 @@ export function strictNormalize(text) {
|
|
|
14
19
|
}
|
|
15
20
|
export function looseNormalize(text) {
|
|
16
21
|
return strictNormalize(text)
|
|
22
|
+
.replace(JOINERS, '')
|
|
17
23
|
.toLowerCase()
|
|
18
24
|
// Map typographic quotes and dashes to plain forms, for alignment and for classifying minor text differences.
|
|
19
25
|
.replace(/[\u2018\u2019\u201a\u2032]/g, "'")
|
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.13";
|
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.13';
|
package/package.json
CHANGED