@heripo/document-processor 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +17 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +17 -1
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -4527,8 +4527,10 @@ var DocumentProcessor = class {
|
|
|
4527
4527
|
);
|
|
4528
4528
|
}
|
|
4529
4529
|
const totalPages = Object.keys(doclingDoc.pages).length;
|
|
4530
|
+
const maxTocPageNo = this.extractMaxPageNumber(markdown);
|
|
4531
|
+
const effectiveTotalPages = maxTocPageNo > totalPages ? void 0 : totalPages;
|
|
4530
4532
|
const tocResult = await this.tocExtractor.extract(markdown, {
|
|
4531
|
-
totalPages
|
|
4533
|
+
totalPages: effectiveTotalPages
|
|
4532
4534
|
});
|
|
4533
4535
|
for (const usage of tocResult.usages) {
|
|
4534
4536
|
this.usageAggregator.track(usage);
|
|
@@ -4543,6 +4545,20 @@ var DocumentProcessor = class {
|
|
|
4543
4545
|
);
|
|
4544
4546
|
return tocResult.entries;
|
|
4545
4547
|
}
|
|
4548
|
+
/**
|
|
4549
|
+
* Extract the maximum page number from TOC markdown
|
|
4550
|
+
*
|
|
4551
|
+
* Parses page numbers from dot-leader patterns (e.g., "..... 175")
|
|
4552
|
+
* to detect compiled volume scenarios where TOC page numbers exceed
|
|
4553
|
+
* the sub-document's page count.
|
|
4554
|
+
*/
|
|
4555
|
+
extractMaxPageNumber(markdown) {
|
|
4556
|
+
const matches = [...markdown.matchAll(/\.{2,}\s*(\d+)/g)];
|
|
4557
|
+
if (matches.length === 0) {
|
|
4558
|
+
return 0;
|
|
4559
|
+
}
|
|
4560
|
+
return Math.max(...matches.map((m) => parseInt(m[1], 10)));
|
|
4561
|
+
}
|
|
4546
4562
|
/**
|
|
4547
4563
|
* Process resource captions (for images and tables)
|
|
4548
4564
|
*
|