@effortlessmotion/pdf-to-md 0.1.8 → 0.2.1
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 +5 -5
- 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/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/cli/index.js.map +1 -1
- package/dist/cjs/cli/render.js.map +1 -1
- package/dist/cjs/cli/types.js.map +1 -1
- package/dist/cjs/cli.js.map +1 -1
- package/dist/cjs/collect.js +91 -35
- package/dist/cjs/collect.js.map +1 -1
- package/dist/cjs/dict.js.map +1 -1
- package/dist/cjs/emit.js.map +1 -1
- package/dist/cjs/engines/tesseract.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/geometry.js.map +1 -1
- package/dist/cjs/index.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/pdf-open.js.map +1 -1
- package/dist/cjs/raster.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/resolve.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/cjs/validate.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/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/cli/index.js.map +1 -1
- package/dist/esm/cli/render.js.map +1 -1
- package/dist/esm/cli/types.js.map +1 -1
- package/dist/esm/cli.js.map +1 -1
- package/dist/esm/collect.js +64 -15
- package/dist/esm/collect.js.map +1 -1
- package/dist/esm/dict.js.map +1 -1
- package/dist/esm/emit.js.map +1 -1
- package/dist/esm/engines/tesseract.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/geometry.js.map +1 -1
- package/dist/esm/index.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/pdf-open.js.map +1 -1
- package/dist/esm/raster.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/resolve.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/dist/esm/validate.js.map +1 -1
- package/package.json +1 -1
- package/skills/pdf-to-md/SKILL.md +39 -66
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @effortlessmotion/pdf-to-md
|
|
2
2
|
|
|
3
|
-
Convert born-digital and scanned PDFs to Markdown. `pdf-to-md` reads
|
|
3
|
+
Convert born-digital and scanned PDFs to Markdown. `pdf-to-md` reads each page's text layer and uses local OCR where needed. It returns a QA report; the OCR path marks text it cannot place reliably for review.
|
|
4
4
|
|
|
5
5
|
Use it when you need editable Markdown plus evidence about conversion quality. OCR runs locally and makes no cloud calls.
|
|
6
6
|
|
|
@@ -23,7 +23,7 @@ The package installs the `pdf-to-md` executable:
|
|
|
23
23
|
npx pdf-to-md book.pdf
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
This writes `book.md`.
|
|
26
|
+
This writes `book.md`. Pages with too little embedded text are assessed individually for OCR, so one document can use both extraction paths. The command reports those choices on stderr.
|
|
27
27
|
|
|
28
28
|
Specify an output path or force OCR when needed:
|
|
29
29
|
|
|
@@ -33,7 +33,7 @@ npx pdf-to-md scan.pdf notes.md --ocr
|
|
|
33
33
|
|
|
34
34
|
A conversion can produce ordinary Markdown plus visible review markers:
|
|
35
35
|
|
|
36
|
-
```
|
|
36
|
+
```text
|
|
37
37
|
## DAILY TALLIES
|
|
38
38
|
|
|
39
39
|
Every skiff was counted at the north pier.
|
|
@@ -51,7 +51,7 @@ import { pdfToMarkdown } from '@effortlessmotion/pdf-to-md';
|
|
|
51
51
|
const { markdown, report, warnings } = await pdfToMarkdown('book.pdf');
|
|
52
52
|
|
|
53
53
|
console.log(markdown);
|
|
54
|
-
console.log(report.path); // "text" or "
|
|
54
|
+
console.log(report.path); // "text", "ocr", or "mixed"
|
|
55
55
|
console.warn(warnings);
|
|
56
56
|
```
|
|
57
57
|
|
|
@@ -91,7 +91,7 @@ Common flags:
|
|
|
91
91
|
- `--stdout` writes the converted content to stdout.
|
|
92
92
|
- `--json` prints the QA report.
|
|
93
93
|
- `--format md|txt|raw` selects Markdown, plain text or analysis JSON.
|
|
94
|
-
- `--debug-words=FILE` writes recognized OCR words for `pdf-to-md audit`.
|
|
94
|
+
- `--debug-words=FILE` writes source text items or recognized OCR words for `pdf-to-md audit`. Use `--page-markers` when producing Markdown for a page-by-page audit.
|
|
95
95
|
- `--dpi=N` changes OCR render resolution. The default is 288; higher values are not always more accurate.
|
|
96
96
|
|
|
97
97
|
Run `npx pdf-to-md --help` for the complete option list.
|
package/dist/cjs/analyze.d.cts
CHANGED
|
@@ -28,7 +28,9 @@ export declare function buildOcrAnalysisPages(input: {
|
|
|
28
28
|
* `Analysis`: plain, JSON-serializable per-page `words`/`blocks` plus the same QA `report` the other entry points return. Render with toMarkdown()/toText(), or hand-edit/splice it (no merge API — see toMarkdown's doc comment).
|
|
29
29
|
*
|
|
30
30
|
* @param input a bare pdf path, or `{ words }` to replay a dump (always analyzed as OCR) — unlike extractOcr, never `{ pdfPath }`
|
|
31
|
-
* @param opts see {@link AnalyzeOptions}; for a
|
|
31
|
+
* @param opts see {@link AnalyzeOptions}; for a PDF path, `path` explicitly
|
|
32
|
+
* selects text (default) or OCR. Automatic per-page routing belongs to
|
|
33
|
+
* pdfToMarkdown and the CLI output formats.
|
|
32
34
|
*/
|
|
33
35
|
export declare function analyze(input: string | {
|
|
34
36
|
words: OcrWordInput[];
|
package/dist/cjs/analyze.d.ts
CHANGED
|
@@ -28,7 +28,9 @@ export declare function buildOcrAnalysisPages(input: {
|
|
|
28
28
|
* `Analysis`: plain, JSON-serializable per-page `words`/`blocks` plus the same QA `report` the other entry points return. Render with toMarkdown()/toText(), or hand-edit/splice it (no merge API — see toMarkdown's doc comment).
|
|
29
29
|
*
|
|
30
30
|
* @param input a bare pdf path, or `{ words }` to replay a dump (always analyzed as OCR) — unlike extractOcr, never `{ pdfPath }`
|
|
31
|
-
* @param opts see {@link AnalyzeOptions}; for a
|
|
31
|
+
* @param opts see {@link AnalyzeOptions}; for a PDF path, `path` explicitly
|
|
32
|
+
* selects text (default) or OCR. Automatic per-page routing belongs to
|
|
33
|
+
* pdfToMarkdown and the CLI output formats.
|
|
32
34
|
*/
|
|
33
35
|
export declare function analyze(input: string | {
|
|
34
36
|
words: OcrWordInput[];
|
package/dist/cjs/analyze.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// analyze() plus the OCR-path core (buildOcrAnalysisPages) that extractOcr
|
|
2
|
-
// shares with it
|
|
2
|
+
// shares with it. Text analysis uses text-analysis.ts so it captures the same
|
|
3
|
+
// blocks, source runs, and report input as extractText.
|
|
3
4
|
"use strict";
|
|
4
5
|
Object.defineProperty(exports, "__esModule", {
|
|
5
6
|
value: true
|
|
@@ -23,10 +24,9 @@ var _dictts = require("./dict.js");
|
|
|
23
24
|
var _emitts = require("./emit.js");
|
|
24
25
|
var _tesseractts = require("./engines/tesseract.js");
|
|
25
26
|
var _geometryts = require("./geometry.js");
|
|
26
|
-
var _linests = require("./lines.js");
|
|
27
|
-
var _markdownts = require("./markdown.js");
|
|
28
27
|
var _renderanalysists = require("./render-analysis.js");
|
|
29
28
|
var _reportts = require("./report.js");
|
|
29
|
+
var _textanalysists = require("./text-analysis.js");
|
|
30
30
|
var _validatets = require("./validate.js");
|
|
31
31
|
function _array_like_to_array(arr, len) {
|
|
32
32
|
if (len == null || len > arr.length) len = arr.length;
|
|
@@ -293,6 +293,9 @@ function buildOcrAnalysisPages(input, opts, warn) {
|
|
|
293
293
|
words = result.words;
|
|
294
294
|
_state.label = 4;
|
|
295
295
|
case 4:
|
|
296
|
+
words = words.filter(function(word) {
|
|
297
|
+
return word.page >= first && word.page <= last;
|
|
298
|
+
});
|
|
296
299
|
(_opts_onWords = opts.onWords) === null || _opts_onWords === void 0 ? void 0 : _opts_onWords.call(opts, words);
|
|
297
300
|
// Stable per-page index, assigned in recognition/replay order — this IS
|
|
298
301
|
// the page's flat `words` list order; `wordIndex` recovers it later since geometry.ts never clones a Word (object identity survives row-building).
|
|
@@ -357,6 +360,7 @@ function buildOcrAnalysisPages(input, opts, warn) {
|
|
|
357
360
|
}
|
|
358
361
|
pages.push({
|
|
359
362
|
page: pn1,
|
|
363
|
+
path: 'ocr',
|
|
360
364
|
words: ((_byPage_get1 = byPage.get(pn1)) !== null && _byPage_get1 !== void 0 ? _byPage_get1 : []).map(toAnalysisWord),
|
|
361
365
|
blocks: blocks
|
|
362
366
|
});
|
|
@@ -410,22 +414,9 @@ function analyzeOcr(input, opts) {
|
|
|
410
414
|
});
|
|
411
415
|
})();
|
|
412
416
|
}
|
|
413
|
-
// TEXT path: deliberately NOT routed through the OCR shared-core pattern —
|
|
414
|
-
// buildMarkdown's reflow/hyphen-rejoin/list rules don't fit the 4-type Analysis block union, so this is an independent, intentionally coarser reconstruction (one word/block per visual LINE) — honest, not byte-identical to extractText (see AnalysisPage, src/types.ts).
|
|
415
|
-
// Converts a text-path Line's page-point geometry (src/lines.ts) into the
|
|
416
|
-
// same normalized box contract the OCR path uses (see AnalysisPage.words) — only the coordinate SYSTEM changes; `box.y` anchors on the line's baseline, `box.w` stays 0.
|
|
417
|
-
function textLineBox(l, dims) {
|
|
418
|
-
var width = dims.width, height = dims.height;
|
|
419
|
-
return {
|
|
420
|
-
x: width > 0 ? l.x / width : 0,
|
|
421
|
-
y: height > 0 ? (height - l.y) / height : 0,
|
|
422
|
-
w: 0,
|
|
423
|
-
h: height > 0 ? l.h / height : 0
|
|
424
|
-
};
|
|
425
|
-
}
|
|
426
417
|
function analyzeText(pdfPath, opts) {
|
|
427
418
|
return _async_to_generator(function() {
|
|
428
|
-
var _opts_pages_last, _opts_pageMarkers, warn, range,
|
|
419
|
+
var _opts_pages_last, _opts_pageMarkers, _opts_onWords, warn, range, collected, result, hybridPages, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, n, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, page;
|
|
429
420
|
return _ts_generator(this, function(_state) {
|
|
430
421
|
switch(_state.label){
|
|
431
422
|
case 0:
|
|
@@ -443,33 +434,12 @@ function analyzeText(pdfPath, opts) {
|
|
|
443
434
|
(0, _collectts.collect)(pdfPath, range)
|
|
444
435
|
];
|
|
445
436
|
case 1:
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
height: p.height
|
|
453
|
-
}
|
|
454
|
-
];
|
|
455
|
-
}));
|
|
456
|
-
pageLines = pages.map(function(p) {
|
|
457
|
-
return {
|
|
458
|
-
page: p.page,
|
|
459
|
-
lines: (0, _linests.toLines)(p)
|
|
460
|
-
};
|
|
461
|
-
});
|
|
462
|
-
pageMarkers = (_opts_pageMarkers = opts.pageMarkers) !== null && _opts_pageMarkers !== void 0 ? _opts_pageMarkers : false;
|
|
463
|
-
_buildMarkdown = (0, _markdownts.buildMarkdown)(pageLines, heightChars, {
|
|
464
|
-
pageMarkers: pageMarkers
|
|
465
|
-
}), md = _buildMarkdown.md, stats = _buildMarkdown.stats, bodyH = _buildMarkdown.bodyH, headingSizes = _buildMarkdown.headingSizes;
|
|
466
|
-
statsMd = pageMarkers ? md : (0, _markdownts.buildMarkdown)(pageLines, heightChars, {
|
|
467
|
-
pageMarkers: true
|
|
468
|
-
}).md;
|
|
469
|
-
hybridPages = pages.filter(function(p) {
|
|
470
|
-
return p.largeImage;
|
|
471
|
-
}).map(function(p) {
|
|
472
|
-
return p.page;
|
|
437
|
+
collected = _state.sent();
|
|
438
|
+
result = (0, _textanalysists.buildTextAnalysis)(collected, (_opts_pageMarkers = opts.pageMarkers) !== null && _opts_pageMarkers !== void 0 ? _opts_pageMarkers : false);
|
|
439
|
+
hybridPages = collected.pages.filter(function(page) {
|
|
440
|
+
return page.largeImage;
|
|
441
|
+
}).map(function(page) {
|
|
442
|
+
return page.page;
|
|
473
443
|
});
|
|
474
444
|
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
475
445
|
try {
|
|
@@ -491,64 +461,32 @@ function analyzeText(pdfPath, opts) {
|
|
|
491
461
|
}
|
|
492
462
|
}
|
|
493
463
|
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
return {
|
|
518
|
-
text: l.text,
|
|
519
|
-
box: textLineBox(l, dims)
|
|
520
|
-
};
|
|
521
|
-
});
|
|
522
|
-
var blocks = lines.map(function(l, i) {
|
|
523
|
-
var level = levelOf.get(l.h);
|
|
524
|
-
return level !== undefined ? {
|
|
525
|
-
type: 'heading',
|
|
526
|
-
text: l.text,
|
|
527
|
-
level: level,
|
|
528
|
-
wordIndexes: [
|
|
529
|
-
i
|
|
530
|
-
]
|
|
531
|
-
} : {
|
|
532
|
-
type: 'paragraph',
|
|
533
|
-
text: l.text,
|
|
534
|
-
wordIndexes: [
|
|
535
|
-
i
|
|
536
|
-
]
|
|
537
|
-
};
|
|
538
|
-
});
|
|
539
|
-
return {
|
|
540
|
-
page: page,
|
|
541
|
-
words: words,
|
|
542
|
-
blocks: blocks
|
|
543
|
-
};
|
|
544
|
-
});
|
|
464
|
+
_iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
|
465
|
+
try {
|
|
466
|
+
for(_iterator1 = collected.pages.filter(function(page) {
|
|
467
|
+
return page.textChars === 0 && !page.hasImage;
|
|
468
|
+
})[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
|
|
469
|
+
page = _step1.value;
|
|
470
|
+
warn("p".concat(page.page, ": no extractable text; the page may be blank or contain only vector content"));
|
|
471
|
+
}
|
|
472
|
+
} catch (err) {
|
|
473
|
+
_didIteratorError1 = true;
|
|
474
|
+
_iteratorError1 = err;
|
|
475
|
+
} finally{
|
|
476
|
+
try {
|
|
477
|
+
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
478
|
+
_iterator1.return();
|
|
479
|
+
}
|
|
480
|
+
} finally{
|
|
481
|
+
if (_didIteratorError1) {
|
|
482
|
+
throw _iteratorError1;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
(_opts_onWords = opts.onWords) === null || _opts_onWords === void 0 ? void 0 : _opts_onWords.call(opts, result.words);
|
|
545
487
|
return [
|
|
546
488
|
2,
|
|
547
|
-
|
|
548
|
-
outputVersion: _reportts.OUTPUT_VERSION,
|
|
549
|
-
report: report,
|
|
550
|
-
pages: analysisPages
|
|
551
|
-
}
|
|
489
|
+
result.analysis
|
|
552
490
|
];
|
|
553
491
|
}
|
|
554
492
|
});
|
package/dist/cjs/analyze.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/formats/pdf-to-md/src/analyze.ts"],"sourcesContent":["// analyze() plus the OCR-path core (buildOcrAnalysisPages) that extractOcr\n// shares with it — same buildPageOCR -> emitPage -> renderPagesToMarkdown pipeline, so OCR-path markdown is byte-identical by construction, not two implementations kept in sync by hand. The TEXT path is NOT shared this way (see analyzeText).\nimport { collect, pageCount } from './collect.ts';\nimport { dictAvailable, dictUnavailableWarning } from './dict.ts';\nimport type { EmitBlock } from './emit.ts';\nimport { emitPage, renderEmitBlock } from './emit.ts';\nimport { recognizePdf } from './engines/tesseract.ts';\n// Type-only: erased at compile time, so this does NOT create a runtime\n// circular dependency even though src/extract.ts imports (value-level) from this module.\nimport type { ExtractOcrOptions, ExtractTextOptions, OcrWordInput } from './extract.ts';\nimport type { PageOCR, Tuning, Word } from './geometry.ts';\nimport { buildPageOCR, DEFAULT_TUNING, headingLevels } from './geometry.ts';\nimport { toLines } from './lines.ts';\nimport { buildMarkdown } from './markdown.ts';\nimport { renderPagesToMarkdown } from './render-analysis.ts';\nimport { buildOcrReport, buildReport, OUTPUT_VERSION } from './report.ts';\nimport type { Analysis, AnalysisBlock, AnalysisPage, AnalysisWord, Line, PageLines } from './types.ts';\nimport { validateOcrAnalysisInput, validatePages, validateWordsInput } from './validate.ts';\n\n/** analyze(pdf) with the default/'text' path — OCR-only fields don't exist\n * on this branch, so passing e.g. `tuning` without `path: 'ocr'` is a compile error. */\nexport type AnalyzeTextOptions = ExtractTextOptions & { path?: 'text' };\n\n/** analyze(pdf, {path:'ocr'}) — same fields as {@link ExtractOcrOptions},\n * unlocked only once `path: 'ocr'` is set. */\nexport type AnalyzeOcrOptions = ExtractOcrOptions & { path: 'ocr' };\n\n/** Options for {@link analyze}: which fields type-check depends on `path`\n * (ignored, forced 'ocr', when `input` is a `{ words }` replay). */\nexport type AnalyzeOptions = AnalyzeTextOptions | AnalyzeOcrOptions;\n\nfunction toAnalysisWord(w: OcrWordInput): AnalysisWord {\n const box = { x: w.x, y: w.y, w: w.w, h: w.h };\n return w.confidence === undefined ? { text: w.text, box } : { text: w.text, box, confidence: w.confidence };\n}\n\n// EmitBlock -> AnalysisBlock: collapses emit.ts's 'quote' kind (a pull-quote)\n// into Analysis's 'paragraph' type, `text` keeping its literal '> ' prefix — see AnalysisBlock's doc comment (src/types.ts) for why.\nfunction toAnalysisBlock(b: EmitBlock, wordIndex: Map<Word, number>): AnalysisBlock {\n const wordIndexes = b.words.map((w) => wordIndex.get(w) as number);\n if (b.kind === 'heading') return { type: 'heading', text: b.text, level: b.level, wordIndexes };\n if (b.kind === 'review') return { type: 'review', text: renderEmitBlock(b), wordIndexes };\n return { type: 'paragraph', text: renderEmitBlock(b), wordIndexes };\n}\n\n/** The OCR-path core shared by extractOcr and analyze(..., {path:'ocr'}):\n * recognizes (or replays) words and runs the unchanged buildPageOCR/emitPage pipeline. Word IDENTITY (object reference), not value, carries indices through into the emitted blocks — see `geometry.ts`'s OcrLine.words. */\nexport async function buildOcrAnalysisPages(input: { pdfPath: string } | { words: OcrWordInput[] }, opts: ExtractOcrOptions, warn: (m: string) => void): Promise<{ pages: AnalysisPage[]; words: OcrWordInput[] }> {\n const tuning: Tuning = { ...DEFAULT_TUNING, ...opts.tuning };\n const validated = validateOcrAnalysisInput(input);\n\n let words: OcrWordInput[];\n let first: number;\n let last: number;\n if ('words' in validated) {\n // Replay: page range from --pages if given, else every page up to the highest one the dump mentions.\n words = validated.words;\n first = opts.pages?.first ?? 1;\n last = opts.pages?.last ?? opts.pages?.first ?? Math.max(1, ...words.map((w) => w.page));\n } else {\n const totalPages = await pageCount(validated.pdfPath);\n const rawFirst = opts.pages?.first ?? 1;\n const rawLast = opts.pages?.last ?? (opts.pages ? rawFirst : totalPages);\n first = Math.min(Math.max(1, rawFirst), Math.max(1, totalPages));\n last = Math.min(Math.max(first, rawLast), totalPages);\n const result = await recognizePdf(validated.pdfPath, first, last, {\n dpi: opts.dpi,\n onProgress: opts.onProgress,\n onWarning: warn,\n });\n words = result.words;\n }\n\n opts.onWords?.(words);\n\n // Stable per-page index, assigned in recognition/replay order — this IS\n // the page's flat `words` list order; `wordIndex` recovers it later since geometry.ts never clones a Word (object identity survives row-building).\n const byPage = new Map<number, OcrWordInput[]>();\n const wordIndex = new Map<Word, number>();\n for (const w of words) {\n const list = byPage.get(w.page);\n if (list) {\n wordIndex.set(w, list.length);\n list.push(w);\n } else {\n wordIndex.set(w, 0);\n byPage.set(w.page, [w]);\n }\n }\n\n const pageOcrs = new Map<number, PageOCR>();\n for (let pn = first; pn <= last; pn++) pageOcrs.set(pn, buildPageOCR(byPage.get(pn) ?? [], tuning));\n const { levelOf } = headingLevels([...pageOcrs.values()], tuning);\n\n const pages: AnalysisPage[] = [];\n for (let pn = first; pn <= last; pn++) {\n const p = pageOcrs.get(pn) as PageOCR;\n // An in-range page with no recognized words stays visible (marker +\n // warning), never silently absent — same rule as extractOcr.\n if (!byPage.has(pn)) warn(`p${pn}: no recognized words, page emitted with no OCR text`);\n\n const blocks: AnalysisBlock[] = emitPage(p, levelOf, tuning).map((b) => toAnalysisBlock(b, wordIndex));\n // Decorative fragments always render as one visible \"> [floats]\" aside\n // per page (matching the one printed line) — see geometry.ts's PageOCR.floats.\n if (p.floats.length) {\n blocks.push({\n type: 'float',\n text: `> [floats] ${p.floats.map((f) => f.text).join(' · ')}`,\n wordIndexes: p.floats.flatMap((f) => f.words).map((w) => wordIndex.get(w) as number),\n });\n }\n\n pages.push({\n page: pn,\n words: (byPage.get(pn) ?? []).map(toAnalysisWord),\n blocks,\n });\n }\n\n return { pages, words };\n}\n\nasync function analyzeOcr(input: { pdfPath: string } | { words: OcrWordInput[] }, opts: ExtractOcrOptions): Promise<Analysis> {\n const warn = (m: string) => opts.onWarning?.(m);\n if (!dictAvailable()) warn(dictUnavailableWarning());\n const { pages, words } = await buildOcrAnalysisPages(input, opts, warn);\n const md = renderPagesToMarkdown(pages, { forcePageMarkers: true, pageMarkers: true });\n const report = buildOcrReport({ md, fallback: opts.fallback, words });\n return { outputVersion: OUTPUT_VERSION, report, pages };\n}\n\n// TEXT path: deliberately NOT routed through the OCR shared-core pattern —\n// buildMarkdown's reflow/hyphen-rejoin/list rules don't fit the 4-type Analysis block union, so this is an independent, intentionally coarser reconstruction (one word/block per visual LINE) — honest, not byte-identical to extractText (see AnalysisPage, src/types.ts).\n\n// Converts a text-path Line's page-point geometry (src/lines.ts) into the\n// same normalized box contract the OCR path uses (see AnalysisPage.words) — only the coordinate SYSTEM changes; `box.y` anchors on the line's baseline, `box.w` stays 0.\nfunction textLineBox(l: Line, dims: { width: number; height: number }): AnalysisWord['box'] {\n const { width, height } = dims;\n return {\n x: width > 0 ? l.x / width : 0,\n y: height > 0 ? (height - l.y) / height : 0,\n w: 0,\n h: height > 0 ? l.h / height : 0,\n };\n}\n\nasync function analyzeText(pdfPath: string, opts: ExtractTextOptions): Promise<Analysis> {\n const warn = (m: string) => opts.onWarning?.(m);\n if (!dictAvailable()) warn(dictUnavailableWarning());\n const range = opts.pages ? { first: opts.pages.first, last: opts.pages.last ?? opts.pages.first } : {};\n const { numPages, pages, heightChars } = await collect(pdfPath, range);\n const pageDims = new Map(pages.map((p) => [p.page, { width: p.width, height: p.height }]));\n const pageLines: PageLines[] = pages.map((p) => ({ page: p.page, lines: toLines(p) }));\n const pageMarkers = opts.pageMarkers ?? false;\n const { md, stats, bodyH, headingSizes } = buildMarkdown(pageLines, heightChars, { pageMarkers });\n const statsMd = pageMarkers ? md : buildMarkdown(pageLines, heightChars, { pageMarkers: true }).md;\n\n const hybridPages = pages.filter((p) => p.largeImage).map((p) => p.page);\n for (const n of hybridPages) {\n warn(`p${n}: text layer used but page carries large image(s); if it has baked-in text this output won't have it — compare (don't blindly replace) against --pages ${n} --ocr, which can itself introduce errors`);\n }\n\n // Report is measured from the REAL markdown above — accurate regardless of\n // the coarser block/word reconstruction below.\n const report = buildReport({ numPages, md, statsMd, stats, bodyH, headingSizes, hybridPages });\n\n // headingSizes is offset-independent — reused directly, then re-leveled\n // here with offset 0 regardless of `opts.pageMarkers` (see AnalysisPage).\n const levelOf = new Map(headingSizes.slice(0, 6).map((h, i) => [h, Math.min(6, i + 1)]));\n const analysisPages: AnalysisPage[] = pageLines.map(({ page, lines }) => {\n const dims = pageDims.get(page) as { width: number; height: number };\n const words: AnalysisWord[] = lines.map((l) => ({ text: l.text, box: textLineBox(l, dims) }));\n const blocks: AnalysisBlock[] = lines.map((l, i) => {\n const level = levelOf.get(l.h);\n return level !== undefined ? { type: 'heading' as const, text: l.text, level, wordIndexes: [i] } : { type: 'paragraph' as const, text: l.text, wordIndexes: [i] };\n });\n return { page, words, blocks };\n });\n\n return { outputVersion: OUTPUT_VERSION, report, pages: analysisPages };\n}\n\n/**\n * Analyze a PDF (or replay an already-recognized OCR word dump) into\n * `Analysis`: plain, JSON-serializable per-page `words`/`blocks` plus the same QA `report` the other entry points return. Render with toMarkdown()/toText(), or hand-edit/splice it (no merge API — see toMarkdown's doc comment).\n *\n * @param input a bare pdf path, or `{ words }` to replay a dump (always analyzed as OCR) — unlike extractOcr, never `{ pdfPath }`\n * @param opts see {@link AnalyzeOptions}; for a pdf path, `opts.path` picks 'text' (default) or 'ocr' — analyze() makes no auto-fallback decision (that's pdfToMarkdown's job)\n */\nexport async function analyze(input: string | { words: OcrWordInput[] }, opts: AnalyzeOptions = {}): Promise<Analysis> {\n validatePages(opts.pages);\n if (typeof input !== 'string') return analyzeOcr({ words: validateWordsInput(input) }, opts);\n if (opts.path === 'ocr') return analyzeOcr({ pdfPath: input }, opts);\n return analyzeText(input, opts);\n}\n"],"names":["analyze","buildOcrAnalysisPages","toAnalysisWord","w","box","x","y","h","confidence","undefined","text","toAnalysisBlock","b","wordIndex","wordIndexes","words","map","get","kind","type","level","renderEmitBlock","input","opts","warn","byPage","tuning","validated","first","last","Math","totalPages","rawFirst","rawLast","result","list","pageOcrs","pn","levelOf","pages","p","blocks","DEFAULT_TUNING","validateOcrAnalysisInput","max","page","pageCount","pdfPath","min","recognizePdf","dpi","onProgress","onWarning","onWords","Map","set","length","push","buildPageOCR","headingLevels","values","has","emitPage","floats","f","join","flatMap","analyzeOcr","md","report","m","dictAvailable","dictUnavailableWarning","renderPagesToMarkdown","forcePageMarkers","pageMarkers","buildOcrReport","fallback","outputVersion","OUTPUT_VERSION","textLineBox","l","dims","width","height","analyzeText","range","numPages","heightChars","pageDims","pageLines","buildMarkdown","stats","bodyH","headingSizes","statsMd","hybridPages","n","analysisPages","collect","lines","toLines","filter","largeImage","buildReport","slice","i","validatePages","validateWordsInput","path"],"mappings":"AAAA,2EAA2E;AAC3E,kPAAkP;;;;;;;;;;;;QA4L5NA;eAAAA;;QA9IAC;eAAAA;;;yBA7Ca;sBACmB;sBAEZ;2BACb;0BAK+B;uBACpC;0BACM;gCACQ;wBACsB;0BAEgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAc5E,SAASC,eAAeC,CAAe;IACrC,IAAMC,MAAM;QAAEC,GAAGF,EAAEE,CAAC;QAAEC,GAAGH,EAAEG,CAAC;QAAEH,GAAGA,EAAEA,CAAC;QAAEI,GAAGJ,EAAEI,CAAC;IAAC;IAC7C,OAAOJ,EAAEK,UAAU,KAAKC,YAAY;QAAEC,MAAMP,EAAEO,IAAI;QAAEN,KAAAA;IAAI,IAAI;QAAEM,MAAMP,EAAEO,IAAI;QAAEN,KAAAA;QAAKI,YAAYL,EAAEK,UAAU;IAAC;AAC5G;AAEA,8EAA8E;AAC9E,qIAAqI;AACrI,SAASG,gBAAgBC,CAAY,EAAEC,SAA4B;IACjE,IAAMC,cAAcF,EAAEG,KAAK,CAACC,GAAG,CAAC,SAACb;eAAMU,UAAUI,GAAG,CAACd;;IACrD,IAAIS,EAAEM,IAAI,KAAK,WAAW,OAAO;QAAEC,MAAM;QAAWT,MAAME,EAAEF,IAAI;QAAEU,OAAOR,EAAEQ,KAAK;QAAEN,aAAAA;I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c;4BAAEV,QAAAA;4BAAQ9B,OAAO2D;wBAAc;;;;IACvE;;AASO,SAAelG;wCAAQsB,KAAyC;YAAEC;;;YAAAA,OAAAA,oEAAuB,CAAC;YAC/FoF,IAAAA,yBAAa,EAACpF,KAAKgB,KAAK;YACxB,IAAI,OAAOjB,UAAU,UAAU;;gBAAO6C,WAAW;oBAAEpD,OAAO6F,IAAAA,8BAAkB,EAACtF;gBAAO,GAAGC;;YACvF,IAAIA,KAAKsF,IAAI,KAAK,OAAO;;gBAAO1C,WAAW;oBAAEpB,SAASzB;gBAAM,GAAGC;;YAC/D;;gBAAO8D,YAAY/D,OAAOC;;;IAC5B"}
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/open-source/formats/pdf-to-md/src/analyze.ts"],"sourcesContent":["// analyze() plus the OCR-path core (buildOcrAnalysisPages) that extractOcr\n// shares with it. Text analysis uses text-analysis.ts so it captures the same\n// blocks, source runs, and report input as extractText.\nimport { collect, pageCount } from './collect.ts';\nimport { dictAvailable, dictUnavailableWarning } from './dict.ts';\nimport type { EmitBlock } from './emit.ts';\nimport { emitPage, renderEmitBlock } from './emit.ts';\nimport { recognizePdf } from './engines/tesseract.ts';\n// Type-only: erased at compile time, so this does NOT create a runtime\n// circular dependency even though src/extract.ts imports (value-level) from this module.\nimport type { ExtractOcrOptions, ExtractTextOptions, OcrWordInput } from './extract.ts';\nimport type { PageOCR, Tuning, Word } from './geometry.ts';\nimport { buildPageOCR, DEFAULT_TUNING, headingLevels } from './geometry.ts';\nimport { renderPagesToMarkdown } from './render-analysis.ts';\nimport { buildOcrReport, OUTPUT_VERSION } from './report.ts';\nimport { buildTextAnalysis } from './text-analysis.ts';\nimport type { Analysis, AnalysisBlock, AnalysisPage, AnalysisWord } from './types.ts';\nimport { validateOcrAnalysisInput, validatePages, validateWordsInput } from './validate.ts';\n\n/** analyze(pdf) with the default/'text' path — OCR-only fields don't exist\n * on this branch, so passing e.g. `tuning` without `path: 'ocr'` is a compile error. */\nexport type AnalyzeTextOptions = ExtractTextOptions & { path?: 'text' };\n\n/** analyze(pdf, {path:'ocr'}) — same fields as {@link ExtractOcrOptions},\n * unlocked only once `path: 'ocr'` is set. */\nexport type AnalyzeOcrOptions = ExtractOcrOptions & { path: 'ocr' };\n\n/** Options for {@link analyze}: which fields type-check depends on `path`\n * (ignored, forced 'ocr', when `input` is a `{ words }` replay). */\nexport type AnalyzeOptions = AnalyzeTextOptions | AnalyzeOcrOptions;\n\nfunction toAnalysisWord(w: OcrWordInput): AnalysisWord {\n const box = { x: w.x, y: w.y, w: w.w, h: w.h };\n return w.confidence === undefined ? { text: w.text, box } : { text: w.text, box, confidence: w.confidence };\n}\n\n// EmitBlock -> AnalysisBlock: collapses emit.ts's 'quote' kind (a pull-quote)\n// into Analysis's 'paragraph' type, `text` keeping its literal '> ' prefix — see AnalysisBlock's doc comment (src/types.ts) for why.\nfunction toAnalysisBlock(b: EmitBlock, wordIndex: Map<Word, number>): AnalysisBlock {\n const wordIndexes = b.words.map((w) => wordIndex.get(w) as number);\n if (b.kind === 'heading') return { type: 'heading', text: b.text, level: b.level, wordIndexes };\n if (b.kind === 'review') return { type: 'review', text: renderEmitBlock(b), wordIndexes };\n return { type: 'paragraph', text: renderEmitBlock(b), wordIndexes };\n}\n\n/** The OCR-path core shared by extractOcr and analyze(..., {path:'ocr'}):\n * recognizes (or replays) words and runs the unchanged buildPageOCR/emitPage pipeline. Word IDENTITY (object reference), not value, carries indices through into the emitted blocks — see `geometry.ts`'s OcrLine.words. */\nexport async function buildOcrAnalysisPages(input: { pdfPath: string } | { words: OcrWordInput[] }, opts: ExtractOcrOptions, warn: (m: string) => void): Promise<{ pages: AnalysisPage[]; words: OcrWordInput[] }> {\n const tuning: Tuning = { ...DEFAULT_TUNING, ...opts.tuning };\n const validated = validateOcrAnalysisInput(input);\n\n let words: OcrWordInput[];\n let first: number;\n let last: number;\n if ('words' in validated) {\n // Replay: page range from --pages if given, else every page up to the highest one the dump mentions.\n words = validated.words;\n first = opts.pages?.first ?? 1;\n last = opts.pages?.last ?? opts.pages?.first ?? Math.max(1, ...words.map((w) => w.page));\n } else {\n const totalPages = await pageCount(validated.pdfPath);\n const rawFirst = opts.pages?.first ?? 1;\n const rawLast = opts.pages?.last ?? (opts.pages ? rawFirst : totalPages);\n first = Math.min(Math.max(1, rawFirst), Math.max(1, totalPages));\n last = Math.min(Math.max(first, rawLast), totalPages);\n const result = await recognizePdf(validated.pdfPath, first, last, {\n dpi: opts.dpi,\n onProgress: opts.onProgress,\n onWarning: warn,\n });\n words = result.words;\n }\n\n words = words.filter((word) => word.page >= first && word.page <= last);\n opts.onWords?.(words);\n\n // Stable per-page index, assigned in recognition/replay order — this IS\n // the page's flat `words` list order; `wordIndex` recovers it later since geometry.ts never clones a Word (object identity survives row-building).\n const byPage = new Map<number, OcrWordInput[]>();\n const wordIndex = new Map<Word, number>();\n for (const w of words) {\n const list = byPage.get(w.page);\n if (list) {\n wordIndex.set(w, list.length);\n list.push(w);\n } else {\n wordIndex.set(w, 0);\n byPage.set(w.page, [w]);\n }\n }\n\n const pageOcrs = new Map<number, PageOCR>();\n for (let pn = first; pn <= last; pn++) pageOcrs.set(pn, buildPageOCR(byPage.get(pn) ?? [], tuning));\n const { levelOf } = headingLevels([...pageOcrs.values()], tuning);\n\n const pages: AnalysisPage[] = [];\n for (let pn = first; pn <= last; pn++) {\n const p = pageOcrs.get(pn) as PageOCR;\n // An in-range page with no recognized words stays visible (marker +\n // warning), never silently absent — same rule as extractOcr.\n if (!byPage.has(pn)) warn(`p${pn}: no recognized words, page emitted with no OCR text`);\n\n const blocks: AnalysisBlock[] = emitPage(p, levelOf, tuning).map((b) => toAnalysisBlock(b, wordIndex));\n // Decorative fragments always render as one visible \"> [floats]\" aside\n // per page (matching the one printed line) — see geometry.ts's PageOCR.floats.\n if (p.floats.length) {\n blocks.push({\n type: 'float',\n text: `> [floats] ${p.floats.map((f) => f.text).join(' · ')}`,\n wordIndexes: p.floats.flatMap((f) => f.words).map((w) => wordIndex.get(w) as number),\n });\n }\n\n pages.push({\n page: pn,\n path: 'ocr',\n words: (byPage.get(pn) ?? []).map(toAnalysisWord),\n blocks,\n });\n }\n\n return { pages, words };\n}\n\nasync function analyzeOcr(input: { pdfPath: string } | { words: OcrWordInput[] }, opts: ExtractOcrOptions): Promise<Analysis> {\n const warn = (m: string) => opts.onWarning?.(m);\n if (!dictAvailable()) warn(dictUnavailableWarning());\n const { pages, words } = await buildOcrAnalysisPages(input, opts, warn);\n const md = renderPagesToMarkdown(pages, { forcePageMarkers: true, pageMarkers: true });\n const report = buildOcrReport({ md, fallback: opts.fallback, words });\n return { outputVersion: OUTPUT_VERSION, report, pages };\n}\n\nasync function analyzeText(pdfPath: string, opts: ExtractTextOptions): Promise<Analysis> {\n const warn = (m: string) => opts.onWarning?.(m);\n if (!dictAvailable()) warn(dictUnavailableWarning());\n const range = opts.pages ? { first: opts.pages.first, last: opts.pages.last ?? opts.pages.first } : {};\n const collected = await collect(pdfPath, range);\n const result = buildTextAnalysis(collected, opts.pageMarkers ?? false);\n const hybridPages = collected.pages.filter((page) => page.largeImage).map((page) => page.page);\n for (const n of hybridPages) {\n warn(`p${n}: text layer used but page carries large image(s); if it has baked-in text this output won't have it — compare (don't blindly replace) against --pages ${n} --ocr, which can itself introduce errors`);\n }\n for (const page of collected.pages.filter((page) => page.textChars === 0 && !page.hasImage)) {\n warn(`p${page.page}: no extractable text; the page may be blank or contain only vector content`);\n }\n opts.onWords?.(result.words);\n return result.analysis;\n}\n\n/**\n * Analyze a PDF (or replay an already-recognized OCR word dump) into\n * `Analysis`: plain, JSON-serializable per-page `words`/`blocks` plus the same QA `report` the other entry points return. Render with toMarkdown()/toText(), or hand-edit/splice it (no merge API — see toMarkdown's doc comment).\n *\n * @param input a bare pdf path, or `{ words }` to replay a dump (always analyzed as OCR) — unlike extractOcr, never `{ pdfPath }`\n * @param opts see {@link AnalyzeOptions}; for a PDF path, `path` explicitly\n * selects text (default) or OCR. Automatic per-page routing belongs to\n * pdfToMarkdown and the CLI output formats.\n */\nexport async function analyze(input: string | { words: OcrWordInput[] }, opts: AnalyzeOptions = {}): Promise<Analysis> {\n validatePages(opts.pages);\n if (typeof input !== 'string') return analyzeOcr({ words: validateWordsInput(input) }, opts);\n if (opts.path === 'ocr') return analyzeOcr({ pdfPath: input }, opts);\n return analyzeText(input, opts);\n}\n"],"names":["analyze","buildOcrAnalysisPages","toAnalysisWord","w","box","x","y","h","confidence","undefined","text","toAnalysisBlock","b","wordIndex","wordIndexes","words","map","get","kind","type","level","renderEmitBlock","input","opts","warn","byPage","tuning","validated","first","last","Math","totalPages","rawFirst","rawLast","result","list","pageOcrs","pn","levelOf","pages","p","blocks","DEFAULT_TUNING","validateOcrAnalysisInput","max","page","pageCount","pdfPath","min","recognizePdf","dpi","onProgress","onWarning","filter","word","onWords","Map","set","length","push","buildPageOCR","headingLevels","values","has","emitPage","floats","f","join","flatMap","path","analyzeOcr","md","report","m","dictAvailable","dictUnavailableWarning","renderPagesToMarkdown","forcePageMarkers","pageMarkers","buildOcrReport","fallback","outputVersion","OUTPUT_VERSION","analyzeText","range","collected","hybridPages","n","collect","buildTextAnalysis","largeImage","textChars","hasImage","analysis","validatePages","validateWordsInput"],"mappings":"AAAA,2EAA2E;AAC3E,8EAA8E;AAC9E,wDAAwD;;;;;;;;;;;;QA6JlCA;eAAAA;;QAhHAC;eAAAA;;;yBA5Ca;sBACmB;sBAEZ;2BACb;0BAK+B;gCACtB;wBACS;8BACb;0BAE0C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAc5E,SAASC,eAAeC,CAAe;IACrC,IAAMC,MAAM;QAAEC,GAAGF,EAAEE,CAAC;QAAEC,GAAGH,E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;gCAAA;;;gCAAA;sCAAA;;;;qBAGLtB,gBAAAA,KAAKgC,OAAO,cAAZhC,oCAAAA,mBAAAA,MAAeW,OAAOnB,KAAK;oBAC3B;;wBAAOmB,OAAO2D,QAAQ;;;;IACxB;;AAWO,SAAe7F;wCAAQsB,KAAyC;YAAEC;;;YAAAA,OAAAA,oEAAuB,CAAC;YAC/FuE,IAAAA,yBAAa,EAACvE,KAAKgB,KAAK;YACxB,IAAI,OAAOjB,UAAU,UAAU;;gBAAOgD,WAAW;oBAAEvD,OAAOgF,IAAAA,8BAAkB,EAACzE;gBAAO,GAAGC;;YACvF,IAAIA,KAAK8C,IAAI,KAAK,OAAO;;gBAAOC,WAAW;oBAAEvB,SAASzB;gBAAM,GAAGC;;YAC/D;;gBAAO4D,YAAY7D,OAAOC;;;IAC5B"}
|
package/dist/cjs/audit.d.cts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
export interface AuditResult {
|
|
3
3
|
/** JSON lines successfully parsed from the word dump */
|
|
4
4
|
parsed: number;
|
|
5
|
-
/** lines in the dump that were not parseable JSON
|
|
6
|
-
*
|
|
5
|
+
/** lines in the dump that were not parseable JSON; auditWords rejects
|
|
6
|
+
* evidence with any such line */
|
|
7
7
|
nonJsonSkipped: number;
|
|
8
8
|
/** distinct page numbers present in the dump */
|
|
9
9
|
pages: number;
|
|
@@ -13,7 +13,7 @@ export interface AuditResult {
|
|
|
13
13
|
* hyphen-join/split repair is applied; always `>= missing` */
|
|
14
14
|
strictDeficits: number;
|
|
15
15
|
/** words genuinely absent from the markdown after repair-checking; `0` is
|
|
16
|
-
* the only passing value (`pdf-to-md audit` exits
|
|
16
|
+
* the only passing value (`pdf-to-md audit` exits nonzero otherwise) */
|
|
17
17
|
missing: number;
|
|
18
18
|
/** per-page detail for every page with at least one missing word (capped
|
|
19
19
|
* sample of the missing tokens per page) */
|
|
@@ -29,8 +29,9 @@ export interface AuditResult {
|
|
|
29
29
|
lines: string[];
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
|
-
* Audit a --debug-words dump against a
|
|
33
|
-
* must land
|
|
32
|
+
* Audit a --debug-words dump against a Markdown file. Every recognized word
|
|
33
|
+
* must land on its page. Invalid evidence or absent page provenance throws a
|
|
34
|
+
* PdfToMdError with code `AUDIT_INPUT`.
|
|
34
35
|
*
|
|
35
36
|
* @param wordsPath path to a --debug-words JSON-lines dump (`{page, text, ...}` per line)
|
|
36
37
|
* @param mdPath path to the markdown file to check the dump against
|
package/dist/cjs/audit.d.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
export interface AuditResult {
|
|
3
3
|
/** JSON lines successfully parsed from the word dump */
|
|
4
4
|
parsed: number;
|
|
5
|
-
/** lines in the dump that were not parseable JSON
|
|
6
|
-
*
|
|
5
|
+
/** lines in the dump that were not parseable JSON; auditWords rejects
|
|
6
|
+
* evidence with any such line */
|
|
7
7
|
nonJsonSkipped: number;
|
|
8
8
|
/** distinct page numbers present in the dump */
|
|
9
9
|
pages: number;
|
|
@@ -13,7 +13,7 @@ export interface AuditResult {
|
|
|
13
13
|
* hyphen-join/split repair is applied; always `>= missing` */
|
|
14
14
|
strictDeficits: number;
|
|
15
15
|
/** words genuinely absent from the markdown after repair-checking; `0` is
|
|
16
|
-
* the only passing value (`pdf-to-md audit` exits
|
|
16
|
+
* the only passing value (`pdf-to-md audit` exits nonzero otherwise) */
|
|
17
17
|
missing: number;
|
|
18
18
|
/** per-page detail for every page with at least one missing word (capped
|
|
19
19
|
* sample of the missing tokens per page) */
|
|
@@ -29,8 +29,9 @@ export interface AuditResult {
|
|
|
29
29
|
lines: string[];
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
|
-
* Audit a --debug-words dump against a
|
|
33
|
-
* must land
|
|
32
|
+
* Audit a --debug-words dump against a Markdown file. Every recognized word
|
|
33
|
+
* must land on its page. Invalid evidence or absent page provenance throws a
|
|
34
|
+
* PdfToMdError with code `AUDIT_INPUT`.
|
|
34
35
|
*
|
|
35
36
|
* @param wordsPath path to a --debug-words JSON-lines dump (`{page, text, ...}` per line)
|
|
36
37
|
* @param mdPath path to the markdown file to check the dump against
|