@effortlessmotion/pdf-to-md 0.1.7 → 0.2.0
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 +69 -76
- package/dist/cjs/analyze.d.cts +3 -1
- package/dist/cjs/analyze.d.ts +3 -1
- package/dist/cjs/analyze.js +38 -100
- package/dist/cjs/analyze.js.map +1 -1
- package/dist/cjs/audit.d.cts +6 -5
- package/dist/cjs/audit.d.ts +6 -5
- package/dist/cjs/audit.js +368 -60
- package/dist/cjs/audit.js.map +1 -1
- package/dist/cjs/cli/extract.js +13 -48
- package/dist/cjs/cli/extract.js.map +1 -1
- package/dist/cjs/collect.js +91 -35
- package/dist/cjs/collect.js.map +1 -1
- package/dist/cjs/errors.d.cts +2 -0
- package/dist/cjs/errors.d.ts +2 -0
- package/dist/cjs/errors.js.map +1 -1
- package/dist/cjs/extract.d.cts +20 -9
- package/dist/cjs/extract.d.ts +20 -9
- package/dist/cjs/extract.js +333 -106
- package/dist/cjs/extract.js.map +1 -1
- package/dist/cjs/lines.js +21 -10
- package/dist/cjs/lines.js.map +1 -1
- package/dist/cjs/markdown.js +140 -54
- package/dist/cjs/markdown.js.map +1 -1
- package/dist/cjs/page-marker.d.cts +1 -1
- package/dist/cjs/page-marker.d.ts +1 -1
- package/dist/cjs/page-marker.js +39 -8
- package/dist/cjs/page-marker.js.map +1 -1
- package/dist/cjs/render-analysis.d.cts +4 -2
- package/dist/cjs/render-analysis.d.ts +4 -2
- package/dist/cjs/render-analysis.js +5 -3
- package/dist/cjs/render-analysis.js.map +1 -1
- package/dist/cjs/report.d.cts +2 -2
- package/dist/cjs/report.d.ts +2 -2
- package/dist/cjs/report.js +27 -8
- package/dist/cjs/report.js.map +1 -1
- package/dist/cjs/text-analysis.d.cts +12 -0
- package/dist/cjs/text-analysis.d.ts +12 -0
- package/dist/cjs/text-analysis.js +175 -0
- package/dist/cjs/text-analysis.js.map +1 -0
- package/dist/cjs/types.d.cts +40 -3
- package/dist/cjs/types.d.ts +40 -3
- package/dist/cjs/types.js +2 -3
- package/dist/cjs/types.js.map +1 -1
- package/dist/esm/analyze.d.ts +3 -1
- package/dist/esm/analyze.js +18 -89
- package/dist/esm/analyze.js.map +1 -1
- package/dist/esm/audit.d.ts +6 -5
- package/dist/esm/audit.js +236 -29
- package/dist/esm/audit.js.map +1 -1
- package/dist/esm/cli/extract.js +10 -23
- package/dist/esm/cli/extract.js.map +1 -1
- package/dist/esm/collect.js +64 -15
- package/dist/esm/collect.js.map +1 -1
- package/dist/esm/errors.d.ts +2 -0
- package/dist/esm/errors.js.map +1 -1
- package/dist/esm/extract.d.ts +20 -9
- package/dist/esm/extract.js +167 -76
- package/dist/esm/extract.js.map +1 -1
- package/dist/esm/lines.js +14 -10
- package/dist/esm/lines.js.map +1 -1
- package/dist/esm/markdown.js +110 -27
- package/dist/esm/markdown.js.map +1 -1
- package/dist/esm/page-marker.d.ts +1 -1
- package/dist/esm/page-marker.js +15 -9
- package/dist/esm/page-marker.js.map +1 -1
- package/dist/esm/render-analysis.d.ts +4 -2
- package/dist/esm/render-analysis.js +9 -5
- package/dist/esm/render-analysis.js.map +1 -1
- package/dist/esm/report.d.ts +2 -2
- package/dist/esm/report.js +12 -7
- package/dist/esm/report.js.map +1 -1
- package/dist/esm/text-analysis.d.ts +12 -0
- package/dist/esm/text-analysis.js +81 -0
- package/dist/esm/text-analysis.js.map +1 -0
- package/dist/esm/types.d.ts +40 -3
- package/dist/esm/types.js +4 -4
- package/dist/esm/types.js.map +1 -1
- package/package.json +2 -8
- package/skills/pdf-to-md/SKILL.md +39 -66
package/dist/cjs/page-marker.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
// page-marker.ts —
|
|
2
|
-
// the page-marker heading imports from here so the regex can't drift (report.ts once had a `\s+` variant).
|
|
1
|
+
// page-marker.ts — page provenance shared by Markdown producers and readers.
|
|
3
2
|
/** The marker heading for page N, with no surrounding whitespace/newlines
|
|
4
3
|
* (callers own their own blank-line formatting). */ "use strict";
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -28,19 +27,51 @@ _export(exports, {
|
|
|
28
27
|
return splitByPageMarker;
|
|
29
28
|
}
|
|
30
29
|
});
|
|
30
|
+
function _array_like_to_array(arr, len) {
|
|
31
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
32
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
33
|
+
return arr2;
|
|
34
|
+
}
|
|
35
|
+
function _array_without_holes(arr) {
|
|
36
|
+
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
37
|
+
}
|
|
38
|
+
function _iterable_to_array(iter) {
|
|
39
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) {
|
|
40
|
+
return Array.from(iter);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function _non_iterable_spread() {
|
|
44
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
45
|
+
}
|
|
46
|
+
function _to_consumable_array(arr) {
|
|
47
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
48
|
+
}
|
|
49
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
50
|
+
if (!o) return;
|
|
51
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
52
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
53
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
54
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
55
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
56
|
+
}
|
|
31
57
|
function pageMarkerLine(page) {
|
|
32
58
|
return "### p".concat(page);
|
|
33
59
|
}
|
|
34
|
-
//
|
|
35
|
-
|
|
60
|
+
// Visible headings are emitted by this package; invisible comments preserve
|
|
61
|
+
// page provenance when a caller does not want headings in its final Markdown.
|
|
62
|
+
var MARKER_RE_SOURCE = '^(?:### p(\\d+)|<!-- p(\\d+) -->)\\r?$';
|
|
63
|
+
function markerPage(match) {
|
|
64
|
+
var _match_;
|
|
65
|
+
return Number((_match_ = match[1]) !== null && _match_ !== void 0 ? _match_ : match[2]);
|
|
66
|
+
}
|
|
36
67
|
function isPageMarkerLine(line) {
|
|
37
|
-
return
|
|
68
|
+
return new RegExp(MARKER_RE_SOURCE, 'u').test(line);
|
|
38
69
|
}
|
|
39
70
|
function splitByPageMarker(md) {
|
|
40
|
-
var re =
|
|
71
|
+
var re = new RegExp(MARKER_RE_SOURCE, 'gmu');
|
|
41
72
|
var markers = [];
|
|
42
73
|
for(var m = re.exec(md); m !== null; m = re.exec(md))markers.push({
|
|
43
|
-
page:
|
|
74
|
+
page: markerPage(m),
|
|
44
75
|
index: m.index,
|
|
45
76
|
end: m.index + m[0].length
|
|
46
77
|
});
|
|
@@ -80,6 +111,6 @@ function bodyByPage(md) {
|
|
|
80
111
|
return out;
|
|
81
112
|
}
|
|
82
113
|
function countPageMarkers(md) {
|
|
83
|
-
return (md.
|
|
114
|
+
return _to_consumable_array(md.matchAll(new RegExp(MARKER_RE_SOURCE, 'gmu'))).length;
|
|
84
115
|
}
|
|
85
116
|
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/formats/pdf-to-md/src/page-marker.ts"],"sourcesContent":["// page-marker.ts —
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/formats/pdf-to-md/src/page-marker.ts"],"sourcesContent":["// page-marker.ts — page provenance shared by Markdown producers and readers.\n\n/** The marker heading for page N, with no surrounding whitespace/newlines\n * (callers own their own blank-line formatting). */\nexport function pageMarkerLine(page: number): string {\n return `### p${page}`;\n}\n\n// Visible headings are emitted by this package; invisible comments preserve\n// page provenance when a caller does not want headings in its final Markdown.\nconst MARKER_RE_SOURCE = '^(?:### p(\\\\d+)|<!-- p(\\\\d+) -->)\\\\r?$';\n\nfunction markerPage(match: RegExpExecArray): number {\n return Number(match[1] ?? match[2]);\n}\n\n/** Is this line (already split, no trailing newline) a page-marker heading? */\nexport function isPageMarkerLine(line: string): boolean {\n return new RegExp(MARKER_RE_SOURCE, 'u').test(line);\n}\n\n/** Split markdown into per-marker body slices, in document order — one entry\n * PER OCCURRENCE (a duplicate \"### pN\" yields two entries; no slice is ever dropped). */\nexport function splitByPageMarker(md: string): { page: number; body: string }[] {\n const re = new RegExp(MARKER_RE_SOURCE, 'gmu');\n const markers: { page: number; index: number; end: number }[] = [];\n for (let m = re.exec(md); m !== null; m = re.exec(md)) markers.push({ page: markerPage(m), index: m.index, end: m.index + m[0].length });\n const out: { page: number; body: string }[] = [];\n for (let i = 0; i < markers.length; i++) {\n const end = i + 1 < markers.length ? markers[i + 1].index : md.length;\n out.push({ page: markers[i].page, body: md.slice(markers[i].end, end) });\n }\n return out;\n}\n\n/** Per-page body text, duplicate-marker slices CONCATENATED — a word anywhere\n * on page N counts as on page N (the auditor's membership semantics). */\nexport function bodyByPage(md: string): Map<number, string> {\n const out = new Map<number, string>();\n for (const { page, body } of splitByPageMarker(md)) out.set(page, (out.get(page) ?? '') + body);\n return out;\n}\n\n/** Count of visible or invisible page-provenance marker lines in `md`. */\nexport function countPageMarkers(md: string): number {\n return [...md.matchAll(new RegExp(MARKER_RE_SOURCE, 'gmu'))].length;\n}\n"],"names":["bodyByPage","countPageMarkers","isPageMarkerLine","pageMarkerLine","splitByPageMarker","page","MARKER_RE_SOURCE","markerPage","match","Number","line","RegExp","test","md","re","markers","m","exec","push","index","end","length","out","i","body","slice","Map","set","get","matchAll"],"mappings":"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,EAAU;QAEgCS;IADnE,IAAMA,MAAM,IAAII;QACX,kCAAA,2BAAA;;QAAL,QAAK,YAAwBtB,kBAAkBS,wBAA1C,SAAA,6BAAA,QAAA,yBAAA;YAAA,kBAAA,aAAQR,mBAAAA,MAAMmB,mBAAAA;YAAiCF,IAAIK,GAAG,CAACtB,MAAM,EAACiB,WAAAA,IAAIM,GAAG,CAACvB,mBAARiB,sBAAAA,WAAiB,MAAME;;;QAArF;QAAA;;;iBAAA,6BAAA;gBAAA;;;gBAAA;sBAAA;;;;IACL,OAAOF;AACT;AAGO,SAASrB,iBAAiBY,EAAU;IACzC,OAAO,AAAC,qBAAGA,GAAGgB,QAAQ,CAAC,IAAIlB,OAAOL,kBAAkB,SAASe,MAAM;AACrE"}
|
|
@@ -8,10 +8,12 @@ export declare function renderPagesToMarkdown(pages: AnalysisPage[], opts: {
|
|
|
8
8
|
export declare function renderPagesToText(pages: AnalysisPage[]): string;
|
|
9
9
|
/**
|
|
10
10
|
* Render an Analysis to markdown. PURE and fail-fast over any well-formed Analysis (including hand-built/spliced ones) — throws `PdfToMdError`/`'ANALYSIS_INPUT'` before any output on a malformed one.
|
|
11
|
-
* OCR-origin output is byte-identical to extractOcr's own markdown
|
|
11
|
+
* OCR-origin output is byte-identical to extractOcr's own markdown. Text
|
|
12
|
+
* output comes from the same captured blocks as extractText. Mixed output
|
|
13
|
+
* always includes page markers because adjacent pages have different producers.
|
|
12
14
|
*
|
|
13
15
|
* @param analysis the Analysis to render (from analyze(), or hand-built/spliced)
|
|
14
|
-
* @param opts.pageMarkers text-origin only;
|
|
16
|
+
* @param opts.pageMarkers text-origin only; OCR and mixed Analysis values always carry markers
|
|
15
17
|
*/
|
|
16
18
|
export declare function toMarkdown(analysis: Analysis, opts?: {
|
|
17
19
|
pageMarkers?: boolean;
|
|
@@ -8,10 +8,12 @@ export declare function renderPagesToMarkdown(pages: AnalysisPage[], opts: {
|
|
|
8
8
|
export declare function renderPagesToText(pages: AnalysisPage[]): string;
|
|
9
9
|
/**
|
|
10
10
|
* Render an Analysis to markdown. PURE and fail-fast over any well-formed Analysis (including hand-built/spliced ones) — throws `PdfToMdError`/`'ANALYSIS_INPUT'` before any output on a malformed one.
|
|
11
|
-
* OCR-origin output is byte-identical to extractOcr's own markdown
|
|
11
|
+
* OCR-origin output is byte-identical to extractOcr's own markdown. Text
|
|
12
|
+
* output comes from the same captured blocks as extractText. Mixed output
|
|
13
|
+
* always includes page markers because adjacent pages have different producers.
|
|
12
14
|
*
|
|
13
15
|
* @param analysis the Analysis to render (from analyze(), or hand-built/spliced)
|
|
14
|
-
* @param opts.pageMarkers text-origin only;
|
|
16
|
+
* @param opts.pageMarkers text-origin only; OCR and mixed Analysis values always carry markers
|
|
15
17
|
*/
|
|
16
18
|
export declare function toMarkdown(analysis: Analysis, opts?: {
|
|
17
19
|
pageMarkers?: boolean;
|
|
@@ -92,7 +92,7 @@ function validateAnalysis(analysis) {
|
|
|
92
92
|
var a = analysis;
|
|
93
93
|
if (_type_of(a.report) !== 'object' || a.report === null) fail('Analysis.report must be an object');
|
|
94
94
|
var path = a.report.path;
|
|
95
|
-
if (path !== 'text' && path !== 'ocr') fail('Analysis.report.path must be "text" or "
|
|
95
|
+
if (path !== 'text' && path !== 'ocr' && path !== 'mixed') fail('Analysis.report.path must be "text", "ocr", or "mixed" (got '.concat(JSON.stringify(path), ")"));
|
|
96
96
|
if (!Array.isArray(a.pages)) fail('Analysis.pages must be an array');
|
|
97
97
|
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
98
98
|
try {
|
|
@@ -101,6 +101,7 @@ function validateAnalysis(analysis) {
|
|
|
101
101
|
if ((typeof page === "undefined" ? "undefined" : _type_of(page)) !== 'object' || page === null) fail("Analysis.pages[".concat(pi, "] must be an object"));
|
|
102
102
|
var p = page;
|
|
103
103
|
if (typeof p.page !== 'number') fail("Analysis.pages[".concat(pi, "].page must be a number"));
|
|
104
|
+
if (p.path !== 'text' && p.path !== 'ocr') fail("Analysis.pages[".concat(pi, '].path must be "text" or "ocr" (got ').concat(JSON.stringify(p.path), ")"));
|
|
104
105
|
if (!Array.isArray(p.words)) fail("Analysis.pages[".concat(pi, "].words must be an array"));
|
|
105
106
|
var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
|
106
107
|
try {
|
|
@@ -145,6 +146,7 @@ function validateAnalysis(analysis) {
|
|
|
145
146
|
} else if (block.level !== undefined) {
|
|
146
147
|
fail("Analysis.pages[".concat(pi, "].blocks[").concat(bi, "].level is only allowed on heading blocks (got a ").concat(JSON.stringify(block.type), " block with level ").concat(JSON.stringify(block.level), ")"));
|
|
147
148
|
}
|
|
149
|
+
if (block.tight !== undefined && typeof block.tight !== 'boolean') fail("Analysis.pages[".concat(pi, "].blocks[").concat(bi, "].tight must be boolean when present"));
|
|
148
150
|
if (!Array.isArray(block.wordIndexes)) fail("Analysis.pages[".concat(pi, "].blocks[").concat(bi, "].wordIndexes must be an array"));
|
|
149
151
|
var _iteratorNormalCompletion3 = true, _didIteratorError3 = false, _iteratorError3 = undefined;
|
|
150
152
|
try {
|
|
@@ -218,7 +220,7 @@ function renderPagesToMarkdown(pages, opts) {
|
|
|
218
220
|
try {
|
|
219
221
|
for(var _iterator1 = page.blocks[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
|
|
220
222
|
var block = _step1.value;
|
|
221
|
-
md += "".concat(renderBlockLiteral(block)
|
|
223
|
+
md += "".concat(renderBlockLiteral(block)).concat(block.tight ? '\n' : '\n\n');
|
|
222
224
|
}
|
|
223
225
|
} catch (err) {
|
|
224
226
|
_didIteratorError1 = true;
|
|
@@ -305,7 +307,7 @@ function renderPagesToText(pages) {
|
|
|
305
307
|
function toMarkdown(analysis) {
|
|
306
308
|
var opts = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
307
309
|
validateAnalysis(analysis);
|
|
308
|
-
var isOcr = analysis.report.path
|
|
310
|
+
var isOcr = analysis.report.path !== 'text';
|
|
309
311
|
var md = renderPagesToMarkdown(analysis.pages, {
|
|
310
312
|
forcePageMarkers: isOcr,
|
|
311
313
|
pageMarkers: !!opts.pageMarkers
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/formats/pdf-to-md/src/render-analysis.ts"],"sourcesContent":["// Pure renderers over the Analysis IR: toMarkdown()/toText() are the public,\n// validated entry points; renderPagesToMarkdown/renderPagesToText below are the unvalidated core, reused (unvalidated) by src/analyze.ts.\nimport { PdfToMdError } from './errors.ts';\nimport { pageMarkerLine } from './page-marker.ts';\nimport type { Analysis, AnalysisBlock, AnalysisPage } from './types.ts';\n\nconst BLOCK_TYPES = new Set(['heading', 'paragraph', 'float', 'review']);\n\n// Whole-object, fail-fast validation: every page/block/wordIndexes entry is\n// checked BEFORE toMarkdown/toText render a single character — a malformed Analysis must never produce partial output, only a clean throw.\nfunction validateAnalysis(analysis: unknown): asserts analysis is Analysis {\n const fail = (msg: string): never => {\n throw new PdfToMdError('ANALYSIS_INPUT', msg);\n };\n if (typeof analysis !== 'object' || analysis === null) fail('Analysis must be an object');\n const a = analysis as Record<string, unknown>;\n if (typeof a.report !== 'object' || a.report === null) fail('Analysis.report must be an object');\n const path = (a.report as Record<string, unknown>).path;\n if (path !== 'text' && path !== 'ocr') fail(`Analysis.report.path must be \"text\" or \"ocr\" (got ${JSON.stringify(path)})`);\n if (!Array.isArray(a.pages)) fail('Analysis.pages must be an array');\n\n for (const [pi, page] of (a.pages as unknown[]).entries()) {\n if (typeof page !== 'object' || page === null) fail(`Analysis.pages[${pi}] must be an object`);\n const p = page as Record<string, unknown>;\n if (typeof p.page !== 'number') fail(`Analysis.pages[${pi}].page must be a number`);\n if (!Array.isArray(p.words)) fail(`Analysis.pages[${pi}].words must be an array`);\n for (const [wi, w] of (p.words as unknown[]).entries()) {\n if (typeof w !== 'object' || w === null || typeof (w as Record<string, unknown>).text !== 'string') {\n fail(`Analysis.pages[${pi}].words[${wi}] must be an object with a string 'text'`);\n }\n }\n const wordCount = (p.words as unknown[]).length;\n\n if (!Array.isArray(p.blocks)) fail(`Analysis.pages[${pi}].blocks must be an array`);\n for (const [bi, b] of (p.blocks as unknown[]).entries()) {\n if (typeof b !== 'object' || b === null) fail(`Analysis.pages[${pi}].blocks[${bi}] must be an object`);\n const block = b as Record<string, unknown>;\n if (typeof block.type !== 'string' || !BLOCK_TYPES.has(block.type)) {\n fail(`Analysis.pages[${pi}].blocks[${bi}].type must be one of heading|paragraph|float|review (got ${JSON.stringify(block.type)})`);\n }\n if (typeof block.text !== 'string') fail(`Analysis.pages[${pi}].blocks[${bi}].text must be a string`);\n // `level` contract (see AnalysisBlock, src/types.ts): required 1-6 on a\n // heading, forbidden otherwise — rejected, not ignored, since it likely means `type` was mistyped.\n if (block.type === 'heading') {\n if (!Number.isInteger(block.level) || (block.level as number) < 1 || (block.level as number) > 6) {\n fail(`Analysis.pages[${pi}].blocks[${bi}].level must be an integer 1-6 on a heading block (got ${JSON.stringify(block.level)})`);\n }\n } else if (block.level !== undefined) {\n fail(`Analysis.pages[${pi}].blocks[${bi}].level is only allowed on heading blocks (got a ${JSON.stringify(block.type)} block with level ${JSON.stringify(block.level)})`);\n }\n if (!Array.isArray(block.wordIndexes)) fail(`Analysis.pages[${pi}].blocks[${bi}].wordIndexes must be an array`);\n for (const idx of block.wordIndexes as unknown[]) {\n if (typeof idx !== 'number' || !Number.isInteger(idx) || idx < 0 || idx >= wordCount) {\n fail(`Analysis.pages[${pi}].blocks[${bi}].wordIndexes has an out-of-range index (${JSON.stringify(idx)}; page ${pi} has ${wordCount} words)`);\n }\n }\n }\n }\n}\n\n// See AnalysisBlock's doc comment (src/types.ts) for the `text` contract this relies on.\nfunction renderBlockLiteral(block: AnalysisBlock): string {\n // A heading's `level` is guaranteed present (1-6): validateAnalysis\n // enforces it, and src/analyze.ts (the only unvalidated caller) always sets it.\n if (block.type === 'heading') return `${'#'.repeat(block.level as number)} ${block.text}`;\n return block.text;\n}\n\n/** Unvalidated core, reused by `src/analyze.ts`. `forcePageMarkers` is the\n * OCR path's always-on \"### pN\"; `pageMarkers` is the text path's opt-in flag, ignored when `forcePageMarkers` is set. */\nexport function renderPagesToMarkdown(pages: AnalysisPage[], opts: { forcePageMarkers: boolean; pageMarkers: boolean }): string {\n let md = '';\n for (const page of pages) {\n if (opts.forcePageMarkers) md += `\\n${pageMarkerLine(page.page)}\\n\\n`;\n else if (opts.pageMarkers) md += `${pageMarkerLine(page.page)}\\n\\n`;\n for (const block of page.blocks) md += `${renderBlockLiteral(block)}\\n\\n`;\n }\n return md;\n}\n\n// Strips a block's markdown decoration for plain-text rendering (the inverse\n// of AnalysisBlock's literal-text convention); headings need no stripping.\nfunction bareBlockText(block: AnalysisBlock): string {\n if (block.type === 'heading') return block.text;\n if (block.type === 'review') return block.text.replace(/^> \\[review: [^\\]]*\\] /, '');\n if (block.type === 'float') return block.text.replace(/^> \\[floats\\] /, '');\n return block.text.replace(/^> /, '');\n}\n\nexport function renderPagesToText(pages: AnalysisPage[]): string {\n const out: string[] = [];\n for (const page of pages) {\n for (const block of page.blocks) out.push(bareBlockText(block));\n }\n return out.length ? `${out.join('\\n\\n').trim()}\\n` : '';\n}\n\n/**\n * Render an Analysis to markdown. PURE and fail-fast over any well-formed Analysis (including hand-built/spliced ones) — throws `PdfToMdError`/`'ANALYSIS_INPUT'` before any output on a malformed one.\n * OCR-origin output is byte-identical to extractOcr's own markdown (shared core); text-origin is NOT byte-identical to extractText's (see `AnalysisPage.words`, `src/types.ts`).\n *\n * @param analysis the Analysis to render (from analyze(), or hand-built/spliced)\n * @param opts.pageMarkers text-origin only; an OCR-origin Analysis always carries markers\n */\nexport function toMarkdown(analysis: Analysis, opts: { pageMarkers?: boolean } = {}): string {\n validateAnalysis(analysis);\n const isOcr = analysis.report.path === 'ocr';\n const md = renderPagesToMarkdown(analysis.pages, { forcePageMarkers: isOcr, pageMarkers: !!opts.pageMarkers });\n return isOcr ? md : `${md.trim()}\\n`;\n}\n\n/**\n * Render an Analysis to reading-order plain text: headings drop their `#`;\n * float/review content is INCLUDED with only its markdown decoration stripped, so no content is lost silently. Same fail-fast validation as toMarkdown.\n *\n * @param analysis the Analysis to render (from analyze(), or hand-built/spliced)\n */\nexport function toText(analysis: Analysis): string {\n validateAnalysis(analysis);\n return renderPagesToText(analysis.pages);\n}\n"],"names":["renderPagesToMarkdown","renderPagesToText","toMarkdown","toText","BLOCK_TYPES","Set","validateAnalysis","analysis","fail","msg","PdfToMdError","a","report","path","JSON","stringify","Array","isArray","pages","entries","pi","page","p","words","wi","w","text","wordCount","length","blocks","bi","b","block","type","has","Number","isInteger","level","undefined","wordIndexes","idx","renderBlockLiteral","repeat","opts","md","forcePageMarkers","pageMarkerLine","pageMarkers","bareBlockText","replace","out","push","join","trim","isOcr"],"mappings":"AAAA,6EAA6E;AAC7E,0IAA0I;;;;;;;;;;;;QAqE1HA;eAAAA;;QAmBAC;eAAAA;;QAeAC;eAAAA;;QAaAC;eAAAA;;;wBAnHa;4BACE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAG/B,IAAMC,cAAc,IAAIC,IAAI;IAAC;IAAW;IAAa;IAAS;CAAS;AAEvE,4EAA4E;AAC5E,2IAA2I;AAC3I,SAASC,iBAAiBC,QAAiB;IACzC,IAAMC,OAAO,cAACC;QACZ,MAAM,IAAIC,sBAAY,CAAC,kBAAkBD;IAC3C;IACA,IAAI,CAAA,OAAOF,yCAAP,SAAOA,SAAO,MAAM,YAAYA,aAAa,MAAMC,KAAK;IAC5D,IAAMG,IAAIJ;IACV,IAAI,SAAOI,EAAEC,MAAM,MAAK,YAAYD,EAAEC,MAAM,KAAK,MAAMJ,KAAK;IAC5D,IAAMK,OAAO,AAACF,EAAEC,MAAM,CAA6BC,IAAI;IACvD,IAAIA,SAAS,UAAUA,SAAS,OAAOL,KAAK,AAAC,qDA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ACC,IAAI,KAAK;IACvC,IAAM+B,KAAK5C,sBAAsBO,SAASW,KAAK,EAAE;QAAE2B,kBAAkBS;QAAOP,aAAa,CAAC,CAACJ,KAAKI,WAAW;IAAC;IAC5G,OAAOO,QAAQV,KAAK,AAAC,GAAY,OAAVA,GAAGS,IAAI,IAAG;AACnC;AAQO,SAASlD,OAAOI,QAAkB;IACvCD,iBAAiBC;IACjB,OAAON,kBAAkBM,SAASW,KAAK;AACzC"}
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/formats/pdf-to-md/src/render-analysis.ts"],"sourcesContent":["// Pure renderers over the Analysis IR: toMarkdown()/toText() are the public,\n// validated entry points; renderPagesToMarkdown/renderPagesToText below are the unvalidated core, reused (unvalidated) by src/analyze.ts.\nimport { PdfToMdError } from './errors.ts';\nimport { pageMarkerLine } from './page-marker.ts';\nimport type { Analysis, AnalysisBlock, AnalysisPage } from './types.ts';\n\nconst BLOCK_TYPES = new Set(['heading', 'paragraph', 'float', 'review']);\n\n// Whole-object, fail-fast validation: every page/block/wordIndexes entry is\n// checked BEFORE toMarkdown/toText render a single character — a malformed Analysis must never produce partial output, only a clean throw.\nfunction validateAnalysis(analysis: unknown): asserts analysis is Analysis {\n const fail = (msg: string): never => {\n throw new PdfToMdError('ANALYSIS_INPUT', msg);\n };\n if (typeof analysis !== 'object' || analysis === null) fail('Analysis must be an object');\n const a = analysis as Record<string, unknown>;\n if (typeof a.report !== 'object' || a.report === null) fail('Analysis.report must be an object');\n const path = (a.report as Record<string, unknown>).path;\n if (path !== 'text' && path !== 'ocr' && path !== 'mixed') fail(`Analysis.report.path must be \"text\", \"ocr\", or \"mixed\" (got ${JSON.stringify(path)})`);\n if (!Array.isArray(a.pages)) fail('Analysis.pages must be an array');\n\n for (const [pi, page] of (a.pages as unknown[]).entries()) {\n if (typeof page !== 'object' || page === null) fail(`Analysis.pages[${pi}] must be an object`);\n const p = page as Record<string, unknown>;\n if (typeof p.page !== 'number') fail(`Analysis.pages[${pi}].page must be a number`);\n if (p.path !== 'text' && p.path !== 'ocr') fail(`Analysis.pages[${pi}].path must be \"text\" or \"ocr\" (got ${JSON.stringify(p.path)})`);\n if (!Array.isArray(p.words)) fail(`Analysis.pages[${pi}].words must be an array`);\n for (const [wi, w] of (p.words as unknown[]).entries()) {\n if (typeof w !== 'object' || w === null || typeof (w as Record<string, unknown>).text !== 'string') {\n fail(`Analysis.pages[${pi}].words[${wi}] must be an object with a string 'text'`);\n }\n }\n const wordCount = (p.words as unknown[]).length;\n\n if (!Array.isArray(p.blocks)) fail(`Analysis.pages[${pi}].blocks must be an array`);\n for (const [bi, b] of (p.blocks as unknown[]).entries()) {\n if (typeof b !== 'object' || b === null) fail(`Analysis.pages[${pi}].blocks[${bi}] must be an object`);\n const block = b as Record<string, unknown>;\n if (typeof block.type !== 'string' || !BLOCK_TYPES.has(block.type)) {\n fail(`Analysis.pages[${pi}].blocks[${bi}].type must be one of heading|paragraph|float|review (got ${JSON.stringify(block.type)})`);\n }\n if (typeof block.text !== 'string') fail(`Analysis.pages[${pi}].blocks[${bi}].text must be a string`);\n // `level` contract (see AnalysisBlock, src/types.ts): required 1-6 on a\n // heading, forbidden otherwise — rejected, not ignored, since it likely means `type` was mistyped.\n if (block.type === 'heading') {\n if (!Number.isInteger(block.level) || (block.level as number) < 1 || (block.level as number) > 6) {\n fail(`Analysis.pages[${pi}].blocks[${bi}].level must be an integer 1-6 on a heading block (got ${JSON.stringify(block.level)})`);\n }\n } else if (block.level !== undefined) {\n fail(`Analysis.pages[${pi}].blocks[${bi}].level is only allowed on heading blocks (got a ${JSON.stringify(block.type)} block with level ${JSON.stringify(block.level)})`);\n }\n if (block.tight !== undefined && typeof block.tight !== 'boolean') fail(`Analysis.pages[${pi}].blocks[${bi}].tight must be boolean when present`);\n if (!Array.isArray(block.wordIndexes)) fail(`Analysis.pages[${pi}].blocks[${bi}].wordIndexes must be an array`);\n for (const idx of block.wordIndexes as unknown[]) {\n if (typeof idx !== 'number' || !Number.isInteger(idx) || idx < 0 || idx >= wordCount) {\n fail(`Analysis.pages[${pi}].blocks[${bi}].wordIndexes has an out-of-range index (${JSON.stringify(idx)}; page ${pi} has ${wordCount} words)`);\n }\n }\n }\n }\n}\n\n// See AnalysisBlock's doc comment (src/types.ts) for the `text` contract this relies on.\nfunction renderBlockLiteral(block: AnalysisBlock): string {\n // A heading's `level` is guaranteed present (1-6): validateAnalysis\n // enforces it, and src/analyze.ts (the only unvalidated caller) always sets it.\n if (block.type === 'heading') return `${'#'.repeat(block.level as number)} ${block.text}`;\n return block.text;\n}\n\n/** Unvalidated core, reused by `src/analyze.ts`. `forcePageMarkers` is the\n * OCR path's always-on \"### pN\"; `pageMarkers` is the text path's opt-in flag, ignored when `forcePageMarkers` is set. */\nexport function renderPagesToMarkdown(pages: AnalysisPage[], opts: { forcePageMarkers: boolean; pageMarkers: boolean }): string {\n let md = '';\n for (const page of pages) {\n if (opts.forcePageMarkers) md += `\\n${pageMarkerLine(page.page)}\\n\\n`;\n else if (opts.pageMarkers) md += `${pageMarkerLine(page.page)}\\n\\n`;\n for (const block of page.blocks) md += `${renderBlockLiteral(block)}${block.tight ? '\\n' : '\\n\\n'}`;\n }\n return md;\n}\n\n// Strips a block's markdown decoration for plain-text rendering (the inverse\n// of AnalysisBlock's literal-text convention); headings need no stripping.\nfunction bareBlockText(block: AnalysisBlock): string {\n if (block.type === 'heading') return block.text;\n if (block.type === 'review') return block.text.replace(/^> \\[review: [^\\]]*\\] /, '');\n if (block.type === 'float') return block.text.replace(/^> \\[floats\\] /, '');\n return block.text.replace(/^> /, '');\n}\n\nexport function renderPagesToText(pages: AnalysisPage[]): string {\n const out: string[] = [];\n for (const page of pages) {\n for (const block of page.blocks) out.push(bareBlockText(block));\n }\n return out.length ? `${out.join('\\n\\n').trim()}\\n` : '';\n}\n\n/**\n * Render an Analysis to markdown. PURE and fail-fast over any well-formed Analysis (including hand-built/spliced ones) — throws `PdfToMdError`/`'ANALYSIS_INPUT'` before any output on a malformed one.\n * OCR-origin output is byte-identical to extractOcr's own markdown. Text\n * output comes from the same captured blocks as extractText. Mixed output\n * always includes page markers because adjacent pages have different producers.\n *\n * @param analysis the Analysis to render (from analyze(), or hand-built/spliced)\n * @param opts.pageMarkers text-origin only; OCR and mixed Analysis values always carry markers\n */\nexport function toMarkdown(analysis: Analysis, opts: { pageMarkers?: boolean } = {}): string {\n validateAnalysis(analysis);\n const isOcr = analysis.report.path !== 'text';\n const md = renderPagesToMarkdown(analysis.pages, { forcePageMarkers: isOcr, pageMarkers: !!opts.pageMarkers });\n return isOcr ? md : `${md.trim()}\\n`;\n}\n\n/**\n * Render an Analysis to reading-order plain text: headings drop their `#`;\n * float/review content is INCLUDED with only its markdown decoration stripped, so no content is lost silently. Same fail-fast validation as toMarkdown.\n *\n * @param analysis the Analysis to render (from analyze(), or hand-built/spliced)\n */\nexport function toText(analysis: Analysis): string {\n validateAnalysis(analysis);\n return renderPagesToText(analysis.pages);\n}\n"],"names":["renderPagesToMarkdown","renderPagesToText","toMarkdown","toText","BLOCK_TYPES","Set","validateAnalysis","analysis","fail","msg","PdfToMdError","a","report","path","JSON","stringify","Array","isArray","pages","entries","pi","page","p","words","wi","w","text","wordCount","length","blocks","bi","b","block","type","has","Number","isInteger","level","undefined","tight","wordIndexes","idx","renderBlockLiteral","repeat","opts","md","forcePageMarkers","pageMarkerLine","pageMarkers","bareBlockText","replace","out","push","join","trim","isOcr"],"mappings":"AAAA,6EAA6E;AAC7E,0IAA0I;;;;;;;;;;;;QAuE1HA;eAAAA;;QAmBAC;eAAAA;;QAiBAC;eAAAA;;QAaAC;eAAAA;;;wBAvHa;4BACE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAG/B,IAAMC,cAAc,IAAIC,IAAI;IAAC;IAAW;IAAa;IAAS;CAAS;AAEvE,4EAA4E;AAC5E,2IAA2I;AAC3I,SAASC,iBAAiBC,QAAiB;IACzC,IAAMC,OAAO,cAACC;QAC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O,CAAC,OAAO;AACnC;AAEO,SAASjD,kBAAkBiB,KAAqB;IACrD,IAAMiC,MAAgB,EAAE;QACnB,kCAAA,2BAAA;;QAAL,QAAK,YAAcjC,0BAAd,SAAA,6BAAA,QAAA,yBAAA,iCAAqB;YAArB,IAAMG,OAAN;gBACE,mCAAA,4BAAA;;gBAAL,QAAK,aAAeA,KAAKQ,MAAM,qBAA1B,UAAA,8BAAA,SAAA,0BAAA;oBAAA,IAAMG,QAAN;oBAA4BmB,IAAIC,IAAI,CAACH,cAAcjB;;;gBAAnD;gBAAA;;;yBAAA,8BAAA;wBAAA;;;wBAAA;8BAAA;;;;QACP;;QAFK;QAAA;;;iBAAA,6BAAA;gBAAA;;;gBAAA;sBAAA;;;;IAGL,OAAOmB,IAAIvB,MAAM,GAAG,AAAC,GAA0B,OAAxBuB,IAAIE,IAAI,CAAC,QAAQC,IAAI,IAAG,QAAM;AACvD;AAWO,SAASpD,WAAWK,QAAkB;QAAEqC,OAAAA,iEAAkC,CAAC;IAChFtC,iBAAiBC;IACjB,IAAMgD,QAAQhD,SAASK,MAAM,CAACC,IAAI,KAAK;IACvC,IAAMgC,KAAK7C,sBAAsBO,SAASW,KAAK,EAAE;QAAE4B,kBAAkBS;QAAOP,aAAa,CAAC,CAACJ,KAAKI,WAAW;IAAC;IAC5G,OAAOO,QAAQV,KAAK,AAAC,GAAY,OAAVA,GAAGS,IAAI,IAAG;AACnC;AAQO,SAASnD,OAAOI,QAAkB;IACvCD,iBAAiBC;IACjB,OAAON,kBAAkBM,SAASW,KAAK;AACzC"}
|
package/dist/cjs/report.d.cts
CHANGED
|
@@ -3,10 +3,10 @@ export declare const SPARSE_CHARS_PER_PAGE = 200;
|
|
|
3
3
|
export declare const AUTO_OCR_CHARS_PER_PAGE = 20;
|
|
4
4
|
/** A manually-bumped integer, deliberately not the npm package version —
|
|
5
5
|
* bump whenever a change can alter output for identical input. See `CHANGELOG.md` for history. */
|
|
6
|
-
export declare const OUTPUT_VERSION =
|
|
6
|
+
export declare const OUTPUT_VERSION = 2;
|
|
7
7
|
/** Below this per-word confidence (0-100, tesseract.js's `confidence`), a
|
|
8
8
|
* word counts as low-confidence. Measured: junk max 43 vs prose min 76, cut 60, 2026-08-17. */
|
|
9
9
|
export declare const LOW_CONFIDENCE_THRESHOLD = 60;
|
|
10
10
|
export declare const LOW_CONFIDENCE_SAMPLE_CAP = 12;
|
|
11
11
|
export declare function buildReport({ numPages, md, statsMd, stats, bodyH, headingSizes, hybridPages }: BuildReportInput): Report;
|
|
12
|
-
export declare function buildOcrReport({ md, fallback, words }: BuildOcrReportInput): Report;
|
|
12
|
+
export declare function buildOcrReport({ md, fallback, words, pagePaths, hybridPages }: BuildOcrReportInput): Report;
|
package/dist/cjs/report.d.ts
CHANGED
|
@@ -3,10 +3,10 @@ export declare const SPARSE_CHARS_PER_PAGE = 200;
|
|
|
3
3
|
export declare const AUTO_OCR_CHARS_PER_PAGE = 20;
|
|
4
4
|
/** A manually-bumped integer, deliberately not the npm package version —
|
|
5
5
|
* bump whenever a change can alter output for identical input. See `CHANGELOG.md` for history. */
|
|
6
|
-
export declare const OUTPUT_VERSION =
|
|
6
|
+
export declare const OUTPUT_VERSION = 2;
|
|
7
7
|
/** Below this per-word confidence (0-100, tesseract.js's `confidence`), a
|
|
8
8
|
* word counts as low-confidence. Measured: junk max 43 vs prose min 76, cut 60, 2026-08-17. */
|
|
9
9
|
export declare const LOW_CONFIDENCE_THRESHOLD = 60;
|
|
10
10
|
export declare const LOW_CONFIDENCE_SAMPLE_CAP = 12;
|
|
11
11
|
export declare function buildReport({ numPages, md, statsMd, stats, bodyH, headingSizes, hybridPages }: BuildReportInput): Report;
|
|
12
|
-
export declare function buildOcrReport({ md, fallback, words }: BuildOcrReportInput): Report;
|
|
12
|
+
export declare function buildOcrReport({ md, fallback, words, pagePaths, hybridPages }: BuildOcrReportInput): Report;
|
package/dist/cjs/report.js
CHANGED
|
@@ -41,6 +41,9 @@ function _array_like_to_array(arr, len) {
|
|
|
41
41
|
function _array_with_holes(arr) {
|
|
42
42
|
if (Array.isArray(arr)) return arr;
|
|
43
43
|
}
|
|
44
|
+
function _array_without_holes(arr) {
|
|
45
|
+
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
46
|
+
}
|
|
44
47
|
function _define_property(obj, key, value) {
|
|
45
48
|
if (key in obj) {
|
|
46
49
|
Object.defineProperty(obj, key, {
|
|
@@ -52,6 +55,11 @@ function _define_property(obj, key, value) {
|
|
|
52
55
|
} else obj[key] = value;
|
|
53
56
|
return obj;
|
|
54
57
|
}
|
|
58
|
+
function _iterable_to_array(iter) {
|
|
59
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) {
|
|
60
|
+
return Array.from(iter);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
55
63
|
function _iterable_to_array_limit(arr, i) {
|
|
56
64
|
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
57
65
|
if (_i == null) return;
|
|
@@ -79,6 +87,9 @@ function _iterable_to_array_limit(arr, i) {
|
|
|
79
87
|
function _non_iterable_rest() {
|
|
80
88
|
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
81
89
|
}
|
|
90
|
+
function _non_iterable_spread() {
|
|
91
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
92
|
+
}
|
|
82
93
|
function _object_spread(target) {
|
|
83
94
|
for(var i = 1; i < arguments.length; i++){
|
|
84
95
|
var source = arguments[i] != null ? arguments[i] : {};
|
|
@@ -97,6 +108,9 @@ function _object_spread(target) {
|
|
|
97
108
|
function _sliced_to_array(arr, i) {
|
|
98
109
|
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
99
110
|
}
|
|
111
|
+
function _to_consumable_array(arr) {
|
|
112
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
113
|
+
}
|
|
100
114
|
function _unsupported_iterable_to_array(o, minLen) {
|
|
101
115
|
if (!o) return;
|
|
102
116
|
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
@@ -107,7 +121,7 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
107
121
|
}
|
|
108
122
|
var SPARSE_CHARS_PER_PAGE = 200;
|
|
109
123
|
var AUTO_OCR_CHARS_PER_PAGE = 20;
|
|
110
|
-
var OUTPUT_VERSION =
|
|
124
|
+
var OUTPUT_VERSION = 2;
|
|
111
125
|
// A body paragraph line may end in sentence/clause punctuation, a closing
|
|
112
126
|
// quote/bracket, an ellipsis, or a digit (chart/label lines like "1/3" legitimately end in a number).
|
|
113
127
|
var TERMINAL_PUNCT = /[.!?:;"”'’)\]…0-9]$/;
|
|
@@ -252,16 +266,18 @@ function measurePage(body) {
|
|
|
252
266
|
//
|
|
253
267
|
// `hybridPages` (text path only) marks a row `largeImages: true` when that
|
|
254
268
|
// page used its text layer but also carries a large embedded image; omitted entirely on the OCR path, which has no equivalent signal.
|
|
255
|
-
function pageStats(md, hybridPages) {
|
|
269
|
+
function pageStats(md, path, hybridPages, pagePaths) {
|
|
256
270
|
var rows = [];
|
|
257
271
|
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
258
272
|
try {
|
|
259
273
|
for(var _iterator = (0, _pagemarkerts.splitByPageMarker)(md)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
260
274
|
var _step_value = _step.value, page = _step_value.page, body = _step_value.body;
|
|
275
|
+
var _ref;
|
|
261
276
|
var row = _object_spread({
|
|
262
|
-
page: page
|
|
277
|
+
page: page,
|
|
278
|
+
path: (_ref = pagePaths === null || pagePaths === void 0 ? void 0 : pagePaths.get(page)) !== null && _ref !== void 0 ? _ref : path
|
|
263
279
|
}, measurePage(body));
|
|
264
|
-
if (hybridPages) row.largeImages = hybridPages.includes(page);
|
|
280
|
+
if (hybridPages && row.path === 'text') row.largeImages = hybridPages.includes(page);
|
|
265
281
|
rows.push(row);
|
|
266
282
|
}
|
|
267
283
|
} catch (err) {
|
|
@@ -286,7 +302,7 @@ function buildReport(param) {
|
|
|
286
302
|
return !(0, _pagemarkerts.isPageMarkerLine)(h);
|
|
287
303
|
}); // page markers are provenance, not structure
|
|
288
304
|
var perPage = Math.round(md.length / numPages);
|
|
289
|
-
var perPageStats = pageStats(statsMd, hybridPages);
|
|
305
|
+
var perPageStats = pageStats(statsMd, 'text', hybridPages);
|
|
290
306
|
return {
|
|
291
307
|
outputVersion: OUTPUT_VERSION,
|
|
292
308
|
path: 'text',
|
|
@@ -322,13 +338,13 @@ function buildReport(param) {
|
|
|
322
338
|
};
|
|
323
339
|
}
|
|
324
340
|
function buildOcrReport(param) {
|
|
325
|
-
var md = param.md, fallback = param.fallback, _param_words = param.words, words = _param_words === void 0 ? [] : _param_words;
|
|
341
|
+
var md = param.md, fallback = param.fallback, _param_words = param.words, words = _param_words === void 0 ? [] : _param_words, pagePaths = param.pagePaths, hybridPages = param.hybridPages;
|
|
326
342
|
var numPages = (0, _pagemarkerts.countPageMarkers)(md);
|
|
327
343
|
var heads = (md.match(/^#{1,6}\s*(.+)$/gm) || []).filter(function(h) {
|
|
328
344
|
return !(0, _pagemarkerts.isPageMarkerLine)(h);
|
|
329
345
|
});
|
|
330
346
|
var perPage = numPages ? Math.round(md.length / numPages) : 0;
|
|
331
|
-
var perPageStats = pageStats(md);
|
|
347
|
+
var perPageStats = pageStats(md, 'ocr', hybridPages, pagePaths);
|
|
332
348
|
// Attach the low-confidence detector's per-page results after the fact:
|
|
333
349
|
// pageStats() has no confidence data (it reads markdown text only), so join it in here by page number.
|
|
334
350
|
var lowConf = lowConfidenceByPage(words);
|
|
@@ -356,9 +372,12 @@ function buildOcrReport(param) {
|
|
|
356
372
|
}
|
|
357
373
|
}
|
|
358
374
|
}
|
|
375
|
+
var mixed = pagePaths !== undefined && _to_consumable_array(pagePaths.values()).some(function(path) {
|
|
376
|
+
return path === 'text';
|
|
377
|
+
});
|
|
359
378
|
return {
|
|
360
379
|
outputVersion: OUTPUT_VERSION,
|
|
361
|
-
path: 'ocr',
|
|
380
|
+
path: mixed ? 'mixed' : 'ocr',
|
|
362
381
|
pages: numPages,
|
|
363
382
|
ocrFallback: !!fallback,
|
|
364
383
|
chars: md.length,
|
package/dist/cjs/report.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/formats/pdf-to-md/src/report.ts"],"sourcesContent":["// report.ts — QA report over an extraction, machine-readable with --json.\nimport { countPageMarkers, isPageMarkerLine, splitByPageMarker } from './page-marker.ts';\nimport type { BuildOcrReportInput, BuildReportInput, PageStatsRow, Report, WordConfidenceInput } from './types.ts';\n\n// < SPARSE warns only; < AUTO_OCR means the pages are certainly images (measured:\n// an image-only 100-pager yields ~4 chars/page) and the auto-OCR fallback fires.\nexport const SPARSE_CHARS_PER_PAGE = 200;\nexport const AUTO_OCR_CHARS_PER_PAGE = 20;\n\n/** A manually-bumped integer, deliberately not the npm package version —\n * bump whenever a change can alter output for identical input. See `CHANGELOG.md` for history. */\nexport const OUTPUT_VERSION = 1;\n\n// A body paragraph line may end in sentence/clause punctuation, a closing\n// quote/bracket, an ellipsis, or a digit (chart/label lines like \"1/3\" legitimately end in a number).\nconst TERMINAL_PUNCT = /[.!?:;\"”'’)\\]…0-9]$/;\n\n// Lines that are not body prose at all: headings (incl. \"### pN\" markers),\n// floats/blockquotes, table rows, and list items — excluded before TERMINAL_PUNCT runs.\nconst NON_PROSE_LINE = /^[#>|*-]/;\n\n// A `> [review: reason] text` line (src/emit.ts). Shared by pageStats (per\n// page) and both top-level report builders (whole doc) so the counts can't drift apart.\nconst REVIEW_LINE = /^> \\[review: /gm;\n\n// Dangling lines split by length: long ones are the invisible column-break/splice\n// signal; short ones are usually a missed heading or an unjoined label.\nconst DANGLING_LONG_MIN = 60;\n\n/** Below this per-word confidence (0-100, tesseract.js's `confidence`), a\n * word counts as low-confidence. Measured: junk max 43 vs prose min 76, cut 60, 2026-08-17. */\nexport const LOW_CONFIDENCE_THRESHOLD = 60;\n\n// Cap on `lowConfidenceSample`'s length per page — a few representative\n// offenders, not the whole page re-emitted a second time.\nexport const LOW_CONFIDENCE_SAMPLE_CAP = 12;\n\ninterface LowConfidenceStats {\n measured: number; // words on this page that carried a confidence value at all\n low: number; // of those, how many scored below LOW_CONFIDENCE_THRESHOLD\n sample: string[]; // worst-confidence-first, capped list of the actual low-confidence tokens\n}\n\n// Grouped from the flat recognized-word list (confidence is per-word, never\n// merged into a line — see Word's comment). `measured` is tracked separately from `low` so a page with nothing to measure reports ABSENT, not a lying zero.\nfunction lowConfidenceByPage(words: WordConfidenceInput[]): Map<number, LowConfidenceStats> {\n const byPage = new Map<number, { measured: number; low: number; lowWords: { text: string; confidence: number }[] }>();\n for (const w of words) {\n if (w.confidence === undefined) continue;\n const entry = byPage.get(w.page) ?? { measured: 0, low: 0, lowWords: [] };\n entry.measured++;\n if (w.confidence < LOW_CONFIDENCE_THRESHOLD) {\n entry.low++;\n entry.lowWords.push({ text: w.text, confidence: w.confidence });\n }\n byPage.set(w.page, entry);\n }\n const result = new Map<number, LowConfidenceStats>();\n for (const [page, entry] of byPage) {\n // Sort ascending by confidence BEFORE capping, so the cap keeps the\n // worst offenders regardless of appearance order.\n const sample = entry.lowWords\n .slice()\n .sort((a, b) => a.confidence - b.confidence)\n .slice(0, LOW_CONFIDENCE_SAMPLE_CAP)\n .map((w) => w.text);\n result.set(page, { measured: entry.measured, low: entry.low, sample });\n }\n return result;\n}\n\ninterface DanglingCounts {\n long: number;\n short: number;\n}\n\n// Counts of body paragraph LINES ending WITHOUT terminal punctuation, split\n// by length: `long` is the invisible column-break/splice signal; `short` is usually a missed heading or unjoined label.\nfunction danglingCounts(body: string): DanglingCounts {\n let long = 0;\n let short = 0;\n for (const raw of body.split('\\n')) {\n const line = raw.trim();\n if (!line || NON_PROSE_LINE.test(line)) continue;\n if (TERMINAL_PUNCT.test(line)) continue;\n if (line.length >= DANGLING_LONG_MIN) long++;\n else short++;\n }\n return { long, short };\n}\n\n// One page's own measured stats, derivable from its body text alone —\n// shared by `pageStats` and any future caller that already has a page's body text in hand.\nfunction measurePage(body: string): Omit<PageStatsRow, 'page' | 'largeImages' | 'lowConfidenceWords' | 'lowConfidenceSample'> {\n const heads = body.match(/^#{1,6}\\s*(.+)$/gm) || [];\n const dangling = danglingCounts(body);\n return {\n chars: body.length,\n headings: heads.length,\n junkHeadings: heads.filter((h) => !/[A-Za-z]{3}/.test(h)).length,\n floats: (body.match(/^> \\[floats\\]/gm) || []).length,\n paragraphs: (body.match(/^(?![#>-])\\S.*$/gm) || []).length,\n danglingLong: dangling.long,\n danglingShort: dangling.short,\n reviewBlocks: (body.match(REVIEW_LINE) || []).length,\n };\n}\n\n// Per-page QA rows, one per \"### pN\" block. The text path always passes\n// markdown with markers forced on (`statsMd`) regardless of `--page-markers`, so pageStats is always populated.\n//\n// `hybridPages` (text path only) marks a row `largeImages: true` when that\n// page used its text layer but also carries a large embedded image; omitted entirely on the OCR path, which has no equivalent signal.\nfunction pageStats(md: string, hybridPages?: number[]): PageStatsRow[] {\n const rows: PageStatsRow[] = [];\n for (const { page, body } of splitByPageMarker(md)) {\n const row: PageStatsRow = { page, ...measurePage(body) };\n if (hybridPages) row.largeImages = hybridPages.includes(page);\n rows.push(row);\n }\n return rows;\n}\n\nexport function buildReport({ numPages, md, statsMd, stats, bodyH, headingSizes, hybridPages = [] }: BuildReportInput): Report {\n const heads = (md.match(/^#{1,6}\\s*(.+)$/gm) || []).filter((h) => !isPageMarkerLine(h)); // page markers are provenance, not structure\n const perPage = Math.round(md.length / numPages);\n const perPageStats = pageStats(statsMd, hybridPages);\n return {\n outputVersion: OUTPUT_VERSION,\n path: 'text',\n pages: numPages,\n bodyFontHeight: bodyH,\n headingSizes: headingSizes.slice(0, 6),\n chars: md.length,\n charsPerPage: perPage,\n sparse: perPage < SPARSE_CHARS_PER_PAGE,\n headings: heads.length,\n junkHeadings: heads.filter((h) => !/[A-Za-z]{3}/.test(h)).length,\n listItems: stats.listItems,\n paragraphs: stats.paragraphs,\n joinedPairs: stats.joinedPairs,\n callouts: stats.callouts,\n closedHyphens: stats.closedHyphens,\n danglingLong: perPageStats.reduce((sum, r) => sum + r.danglingLong, 0),\n danglingShort: perPageStats.reduce((sum, r) => sum + r.danglingShort, 0),\n reviewBlocks: perPageStats.reduce((sum, r) => sum + r.reviewBlocks, 0),\n // The text path never sees per-word confidence at all; 0 here means\n // \"nothing to measure\" (see PageStatsRow's field doc), not \"measured 0\".\n lowConfidenceWords: 0,\n hybridPages,\n pageStats: perPageStats,\n };\n}\n\n// QA report for the OCR path: measured from the emitted markdown text.\n// `fallback` records that the text layer was tried first and found empty.\nexport function buildOcrReport({ md, fallback, words = [] }: BuildOcrReportInput): Report {\n const numPages = countPageMarkers(md);\n const heads = (md.match(/^#{1,6}\\s*(.+)$/gm) || []).filter((h) => !isPageMarkerLine(h));\n const perPage = numPages ? Math.round(md.length / numPages) : 0;\n const perPageStats = pageStats(md);\n // Attach the low-confidence detector's per-page results after the fact:\n // pageStats() has no confidence data (it reads markdown text only), so join it in here by page number.\n const lowConf = lowConfidenceByPage(words);\n for (const row of perPageStats) {\n const entry = lowConf.get(row.page);\n if (entry && entry.measured > 0) {\n row.lowConfidenceWords = entry.low;\n if (entry.sample.length) row.lowConfidenceSample = entry.sample;\n }\n }\n return {\n outputVersion: OUTPUT_VERSION,\n path: 'ocr',\n pages: numPages,\n ocrFallback: !!fallback,\n chars: md.length,\n charsPerPage: perPage,\n sparse: perPage < SPARSE_CHARS_PER_PAGE,\n headings: heads.length,\n junkHeadings: heads.filter((h) => !/[A-Za-z]{3}/.test(h)).length,\n paragraphs: (md.match(/^(?![#>-])\\S.*$/gm) || []).length,\n // Exclude BOTH \"[floats]\" and \"[review: ...]\" lines — a review marker is\n // a labeled unstructured block, not a genuine callout.\n callouts: (md.match(/^> (?!\\[floats\\]|\\[review:)/gm) || []).length,\n floats: (md.match(/^> \\[floats\\]/gm) || []).length,\n danglingLong: perPageStats.reduce((sum, r) => sum + r.danglingLong, 0),\n danglingShort: perPageStats.reduce((sum, r) => sum + r.danglingShort, 0),\n reviewBlocks: perPageStats.reduce((sum, r) => sum + r.reviewBlocks, 0),\n lowConfidenceWords: perPageStats.reduce((sum, r) => sum + (r.lowConfidenceWords ?? 0), 0),\n pageStats: perPageStats,\n };\n}\n"],"names":["AUTO_OCR_CHARS_PER_PAGE","LOW_CONFIDENCE_SAMPLE_CAP","LOW_CONFIDENCE_THRESHOLD","OUTPUT_VERSION","SPARSE_CHARS_PER_PAGE","buildOcrReport","buildReport","TERMINAL_PUNCT","NON_PROSE_LINE","REVIEW_LINE","DANGLING_LONG_MIN","lowConfidenceByPage","words","byPage","Map","w","confidence","undefined","entry","get","page","measured","low","lowWords","push","text","set","result","sample","slice","sort","a","b","map","danglingCounts","body","long","short","split","raw","line","trim","test","length","measurePage","heads","match","dangling","chars","headings","junkHeadings","filter","h","floats","paragraphs","danglingLong","danglingShort","reviewBlocks","pageStats","md","hybridPages","rows","splitByPageMarker","row","largeImages","includes","numPages","statsMd","stats","bodyH","headingSizes","isPageMarkerLine","perPage","Math","round","perPageStats","outputVersion","path","pages","bodyFontHeight","charsPerPage","sparse","listItems","joinedPairs","callouts","closedHyphens","reduce","sum","r","lowConfidenceWords","fallback","countPageMarkers","lowConf","lowConfidenceSample","ocrFallback"],"mappings":"AAAA,0EAA0E;;;;;;;;;;;;QAO7DA;eAAAA;;QA4BAC;eAAAA;;QAJAC;eAAAA;;QApBAC;eAAAA;;QALAC;eAAAA;;QAsJGC;eAAAA;;QAjCAC;eAAAA;;;4BA1HsD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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oBd,aAAaW,MAAM,CAAC,SAACC,KAAKC;gBAAaA;mBAAPD,QAAOC,wBAAAA,EAAEC,kBAAkB,cAApBD,mCAAAA,wBAAwB;WAAI;QACvF9B,WAAWiB;IACb;AACF"}
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/formats/pdf-to-md/src/report.ts"],"sourcesContent":["// report.ts — QA report over an extraction, machine-readable with --json.\nimport { countPageMarkers, isPageMarkerLine, splitByPageMarker } from './page-marker.ts';\nimport type { BuildOcrReportInput, BuildReportInput, PageStatsRow, Report, WordConfidenceInput } from './types.ts';\n\n// < SPARSE warns only; < AUTO_OCR means the pages are certainly images (measured:\n// an image-only 100-pager yields ~4 chars/page) and the auto-OCR fallback fires.\nexport const SPARSE_CHARS_PER_PAGE = 200;\nexport const AUTO_OCR_CHARS_PER_PAGE = 20;\n\n/** A manually-bumped integer, deliberately not the npm package version —\n * bump whenever a change can alter output for identical input. See `CHANGELOG.md` for history. */\nexport const OUTPUT_VERSION = 2;\n\n// A body paragraph line may end in sentence/clause punctuation, a closing\n// quote/bracket, an ellipsis, or a digit (chart/label lines like \"1/3\" legitimately end in a number).\nconst TERMINAL_PUNCT = /[.!?:;\"”'’)\\]…0-9]$/;\n\n// Lines that are not body prose at all: headings (incl. \"### pN\" markers),\n// floats/blockquotes, table rows, and list items — excluded before TERMINAL_PUNCT runs.\nconst NON_PROSE_LINE = /^[#>|*-]/;\n\n// A `> [review: reason] text` line (src/emit.ts). Shared by pageStats (per\n// page) and both top-level report builders (whole doc) so the counts can't drift apart.\nconst REVIEW_LINE = /^> \\[review: /gm;\n\n// Dangling lines split by length: long ones are the invisible column-break/splice\n// signal; short ones are usually a missed heading or an unjoined label.\nconst DANGLING_LONG_MIN = 60;\n\n/** Below this per-word confidence (0-100, tesseract.js's `confidence`), a\n * word counts as low-confidence. Measured: junk max 43 vs prose min 76, cut 60, 2026-08-17. */\nexport const LOW_CONFIDENCE_THRESHOLD = 60;\n\n// Cap on `lowConfidenceSample`'s length per page — a few representative\n// offenders, not the whole page re-emitted a second time.\nexport const LOW_CONFIDENCE_SAMPLE_CAP = 12;\n\ninterface LowConfidenceStats {\n measured: number; // words on this page that carried a confidence value at all\n low: number; // of those, how many scored below LOW_CONFIDENCE_THRESHOLD\n sample: string[]; // worst-confidence-first, capped list of the actual low-confidence tokens\n}\n\n// Grouped from the flat recognized-word list (confidence is per-word, never\n// merged into a line — see Word's comment). `measured` is tracked separately from `low` so a page with nothing to measure reports ABSENT, not a lying zero.\nfunction lowConfidenceByPage(words: WordConfidenceInput[]): Map<number, LowConfidenceStats> {\n const byPage = new Map<number, { measured: number; low: number; lowWords: { text: string; confidence: number }[] }>();\n for (const w of words) {\n if (w.confidence === undefined) continue;\n const entry = byPage.get(w.page) ?? { measured: 0, low: 0, lowWords: [] };\n entry.measured++;\n if (w.confidence < LOW_CONFIDENCE_THRESHOLD) {\n entry.low++;\n entry.lowWords.push({ text: w.text, confidence: w.confidence });\n }\n byPage.set(w.page, entry);\n }\n const result = new Map<number, LowConfidenceStats>();\n for (const [page, entry] of byPage) {\n // Sort ascending by confidence BEFORE capping, so the cap keeps the\n // worst offenders regardless of appearance order.\n const sample = entry.lowWords\n .slice()\n .sort((a, b) => a.confidence - b.confidence)\n .slice(0, LOW_CONFIDENCE_SAMPLE_CAP)\n .map((w) => w.text);\n result.set(page, { measured: entry.measured, low: entry.low, sample });\n }\n return result;\n}\n\ninterface DanglingCounts {\n long: number;\n short: number;\n}\n\n// Counts of body paragraph LINES ending WITHOUT terminal punctuation, split\n// by length: `long` is the invisible column-break/splice signal; `short` is usually a missed heading or unjoined label.\nfunction danglingCounts(body: string): DanglingCounts {\n let long = 0;\n let short = 0;\n for (const raw of body.split('\\n')) {\n const line = raw.trim();\n if (!line || NON_PROSE_LINE.test(line)) continue;\n if (TERMINAL_PUNCT.test(line)) continue;\n if (line.length >= DANGLING_LONG_MIN) long++;\n else short++;\n }\n return { long, short };\n}\n\n// One page's own measured stats, derivable from its body text alone —\n// shared by `pageStats` and any future caller that already has a page's body text in hand.\nfunction measurePage(body: string): Omit<PageStatsRow, 'page' | 'path' | 'largeImages' | 'lowConfidenceWords' | 'lowConfidenceSample'> {\n const heads = body.match(/^#{1,6}\\s*(.+)$/gm) || [];\n const dangling = danglingCounts(body);\n return {\n chars: body.length,\n headings: heads.length,\n junkHeadings: heads.filter((h) => !/[A-Za-z]{3}/.test(h)).length,\n floats: (body.match(/^> \\[floats\\]/gm) || []).length,\n paragraphs: (body.match(/^(?![#>-])\\S.*$/gm) || []).length,\n danglingLong: dangling.long,\n danglingShort: dangling.short,\n reviewBlocks: (body.match(REVIEW_LINE) || []).length,\n };\n}\n\n// Per-page QA rows, one per \"### pN\" block. The text path always passes\n// markdown with markers forced on (`statsMd`) regardless of `--page-markers`, so pageStats is always populated.\n//\n// `hybridPages` (text path only) marks a row `largeImages: true` when that\n// page used its text layer but also carries a large embedded image; omitted entirely on the OCR path, which has no equivalent signal.\nfunction pageStats(md: string, path: 'text' | 'ocr', hybridPages?: number[], pagePaths?: Map<number, 'text' | 'ocr'>): PageStatsRow[] {\n const rows: PageStatsRow[] = [];\n for (const { page, body } of splitByPageMarker(md)) {\n const row: PageStatsRow = { page, path: pagePaths?.get(page) ?? path, ...measurePage(body) };\n if (hybridPages && row.path === 'text') row.largeImages = hybridPages.includes(page);\n rows.push(row);\n }\n return rows;\n}\n\nexport function buildReport({ numPages, md, statsMd, stats, bodyH, headingSizes, hybridPages = [] }: BuildReportInput): Report {\n const heads = (md.match(/^#{1,6}\\s*(.+)$/gm) || []).filter((h) => !isPageMarkerLine(h)); // page markers are provenance, not structure\n const perPage = Math.round(md.length / numPages);\n const perPageStats = pageStats(statsMd, 'text', hybridPages);\n return {\n outputVersion: OUTPUT_VERSION,\n path: 'text',\n pages: numPages,\n bodyFontHeight: bodyH,\n headingSizes: headingSizes.slice(0, 6),\n chars: md.length,\n charsPerPage: perPage,\n sparse: perPage < SPARSE_CHARS_PER_PAGE,\n headings: heads.length,\n junkHeadings: heads.filter((h) => !/[A-Za-z]{3}/.test(h)).length,\n listItems: stats.listItems,\n paragraphs: stats.paragraphs,\n joinedPairs: stats.joinedPairs,\n callouts: stats.callouts,\n closedHyphens: stats.closedHyphens,\n danglingLong: perPageStats.reduce((sum, r) => sum + r.danglingLong, 0),\n danglingShort: perPageStats.reduce((sum, r) => sum + r.danglingShort, 0),\n reviewBlocks: perPageStats.reduce((sum, r) => sum + r.reviewBlocks, 0),\n // The text path never sees per-word confidence at all; 0 here means\n // \"nothing to measure\" (see PageStatsRow's field doc), not \"measured 0\".\n lowConfidenceWords: 0,\n hybridPages,\n pageStats: perPageStats,\n };\n}\n\n// QA report for the OCR path: measured from the emitted markdown text.\n// `fallback` records that the text layer was tried first and found empty.\nexport function buildOcrReport({ md, fallback, words = [], pagePaths, hybridPages }: BuildOcrReportInput): Report {\n const numPages = countPageMarkers(md);\n const heads = (md.match(/^#{1,6}\\s*(.+)$/gm) || []).filter((h) => !isPageMarkerLine(h));\n const perPage = numPages ? Math.round(md.length / numPages) : 0;\n const perPageStats = pageStats(md, 'ocr', hybridPages, pagePaths);\n // Attach the low-confidence detector's per-page results after the fact:\n // pageStats() has no confidence data (it reads markdown text only), so join it in here by page number.\n const lowConf = lowConfidenceByPage(words);\n for (const row of perPageStats) {\n const entry = lowConf.get(row.page);\n if (entry && entry.measured > 0) {\n row.lowConfidenceWords = entry.low;\n if (entry.sample.length) row.lowConfidenceSample = entry.sample;\n }\n }\n const mixed = pagePaths !== undefined && [...pagePaths.values()].some((path) => path === 'text');\n return {\n outputVersion: OUTPUT_VERSION,\n path: mixed ? 'mixed' : 'ocr',\n pages: numPages,\n ocrFallback: !!fallback,\n chars: md.length,\n charsPerPage: perPage,\n sparse: perPage < SPARSE_CHARS_PER_PAGE,\n headings: heads.length,\n junkHeadings: heads.filter((h) => !/[A-Za-z]{3}/.test(h)).length,\n paragraphs: (md.match(/^(?![#>-])\\S.*$/gm) || []).length,\n // Exclude BOTH \"[floats]\" and \"[review: ...]\" lines — a review marker is\n // a labeled unstructured block, not a genuine callout.\n callouts: (md.match(/^> (?!\\[floats\\]|\\[review:)/gm) || []).length,\n floats: (md.match(/^> \\[floats\\]/gm) || []).length,\n danglingLong: perPageStats.reduce((sum, r) => sum + r.danglingLong, 0),\n danglingShort: perPageStats.reduce((sum, r) => sum + r.danglingShort, 0),\n reviewBlocks: perPageStats.reduce((sum, r) => sum + r.reviewBlocks, 0),\n lowConfidenceWords: perPageStats.reduce((sum, r) => sum + (r.lowConfidenceWords ?? 0), 0),\n pageStats: perPageStats,\n };\n}\n"],"names":["AUTO_OCR_CHARS_PER_PAGE","LOW_CONFIDENCE_SAMPLE_CAP","LOW_CONFIDENCE_THRESHOLD","OUTPUT_VERSION","SPARSE_CHARS_PER_PAGE","buildOcrReport","buildReport","TERMINAL_PUNCT","NON_PROSE_LINE","REVIEW_LINE","DANGLING_LONG_MIN","lowConfidenceByPage","words","byPage","Map","w","confidence","undefined","entry","get","page","measured","low","lowWords","push","text","set","result","sample","slice","sort","a","b","map","danglingCounts","body","long","short","split","raw","line","trim","test","length","measurePage","heads","match","dangling","chars","headings","junkHeadings","filter","h","floats","paragraphs","danglingLong","danglingShort","reviewBlocks","pageStats","md","path","hybridPages","pagePaths","rows","splitByPageMarker","row","largeImages","includes","numPages","statsMd","stats","bodyH","headingSizes","isPageMarkerLine","perPage","Math","round","perPageStats","outputVersion","pages","bodyFontHeight","charsPerPage","sparse","listItems","joinedPairs","callouts","closedHyphens","reduce","sum","r","lowConfidenceWords","fallback","countPageMarkers","lowConf","lowConfidenceSample","mixed","values","some","ocrFallback"],"mappings":"AAAA,0EAA0E;;;;;;;;;;;;QAO7DA;eAAAA;;QA4BAC;eAAAA;;QAJAC;eAAAA;;QApBAC;eAAAA;;QALAC;eAAAA;;QAsJGC;eAAAA;;QAjCAC;eAAAA;;;4BA1HsD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AGb,KAAK,CAAC,sBAAsB,EAAE,AAAD,EAAGH,MAAM;QAClDY,cAAcsB,aAAaU,MAAM,CAAC,SAACC,KAAKC;mBAAMD,MAAMC,EAAElC,YAAY;WAAE;QACpEC,eAAeqB,aAAaU,MAAM,CAAC,SAACC,KAAKC;mBAAMD,MAAMC,EAAEjC,aAAa;WAAE;QACtEC,cAAcoB,aAAaU,MAAM,CAAC,SAACC,KAAKC;mBAAMD,MAAMC,EAAEhC,YAAY;WAAE;QACpEiC,oBAAoBb,aAAaU,MAAM,CAAC,SAACC,KAAKC;gBAAaA;mBAAPD,QAAOC,wBAAAA,EAAEC,kBAAkB,cAApBD,mCAAAA,wBAAwB;WAAI;QACvF/B,WAAWmB;IACb;AACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { PageWord } from './geometry.js';
|
|
2
|
+
import type { Analysis, CollectResult } from './types.js';
|
|
3
|
+
export interface TextAnalysisResult {
|
|
4
|
+
analysis: Analysis;
|
|
5
|
+
markdown: string;
|
|
6
|
+
words: PageWord[];
|
|
7
|
+
}
|
|
8
|
+
export declare function selectCollectedPages(collected: CollectResult, pageNumbers: Set<number>): CollectResult;
|
|
9
|
+
/** Builds the text result once for Markdown, raw analysis, text callbacks,
|
|
10
|
+
* and reporting. The `pages` returned by buildMarkdown own the actual block
|
|
11
|
+
* construction, so this never reconstructs ownership from rendered text. */
|
|
12
|
+
export declare function buildTextAnalysis(collected: CollectResult, pageMarkers: boolean): TextAnalysisResult;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { PageWord } from './geometry.js';
|
|
2
|
+
import type { Analysis, CollectResult } from './types.js';
|
|
3
|
+
export interface TextAnalysisResult {
|
|
4
|
+
analysis: Analysis;
|
|
5
|
+
markdown: string;
|
|
6
|
+
words: PageWord[];
|
|
7
|
+
}
|
|
8
|
+
export declare function selectCollectedPages(collected: CollectResult, pageNumbers: Set<number>): CollectResult;
|
|
9
|
+
/** Builds the text result once for Markdown, raw analysis, text callbacks,
|
|
10
|
+
* and reporting. The `pages` returned by buildMarkdown own the actual block
|
|
11
|
+
* construction, so this never reconstructs ownership from rendered text. */
|
|
12
|
+
export declare function buildTextAnalysis(collected: CollectResult, pageMarkers: boolean): TextAnalysisResult;
|