@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.d.cts
CHANGED
|
@@ -250,6 +250,14 @@ declare class DocumentProcessor {
|
|
|
250
250
|
* 5. TocExtractor - LLM-based structured extraction
|
|
251
251
|
*/
|
|
252
252
|
private extractTableOfContents;
|
|
253
|
+
/**
|
|
254
|
+
* Extract the maximum page number from TOC markdown
|
|
255
|
+
*
|
|
256
|
+
* Parses page numbers from dot-leader patterns (e.g., "..... 175")
|
|
257
|
+
* to detect compiled volume scenarios where TOC page numbers exceed
|
|
258
|
+
* the sub-document's page count.
|
|
259
|
+
*/
|
|
260
|
+
private extractMaxPageNumber;
|
|
253
261
|
/**
|
|
254
262
|
* Process resource captions (for images and tables)
|
|
255
263
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -250,6 +250,14 @@ declare class DocumentProcessor {
|
|
|
250
250
|
* 5. TocExtractor - LLM-based structured extraction
|
|
251
251
|
*/
|
|
252
252
|
private extractTableOfContents;
|
|
253
|
+
/**
|
|
254
|
+
* Extract the maximum page number from TOC markdown
|
|
255
|
+
*
|
|
256
|
+
* Parses page numbers from dot-leader patterns (e.g., "..... 175")
|
|
257
|
+
* to detect compiled volume scenarios where TOC page numbers exceed
|
|
258
|
+
* the sub-document's page count.
|
|
259
|
+
*/
|
|
260
|
+
private extractMaxPageNumber;
|
|
253
261
|
/**
|
|
254
262
|
* Process resource captions (for images and tables)
|
|
255
263
|
*
|
package/dist/index.js
CHANGED
|
@@ -4464,8 +4464,10 @@ var DocumentProcessor = class {
|
|
|
4464
4464
|
);
|
|
4465
4465
|
}
|
|
4466
4466
|
const totalPages = Object.keys(doclingDoc.pages).length;
|
|
4467
|
+
const maxTocPageNo = this.extractMaxPageNumber(markdown);
|
|
4468
|
+
const effectiveTotalPages = maxTocPageNo > totalPages ? void 0 : totalPages;
|
|
4467
4469
|
const tocResult = await this.tocExtractor.extract(markdown, {
|
|
4468
|
-
totalPages
|
|
4470
|
+
totalPages: effectiveTotalPages
|
|
4469
4471
|
});
|
|
4470
4472
|
for (const usage of tocResult.usages) {
|
|
4471
4473
|
this.usageAggregator.track(usage);
|
|
@@ -4480,6 +4482,20 @@ var DocumentProcessor = class {
|
|
|
4480
4482
|
);
|
|
4481
4483
|
return tocResult.entries;
|
|
4482
4484
|
}
|
|
4485
|
+
/**
|
|
4486
|
+
* Extract the maximum page number from TOC markdown
|
|
4487
|
+
*
|
|
4488
|
+
* Parses page numbers from dot-leader patterns (e.g., "..... 175")
|
|
4489
|
+
* to detect compiled volume scenarios where TOC page numbers exceed
|
|
4490
|
+
* the sub-document's page count.
|
|
4491
|
+
*/
|
|
4492
|
+
extractMaxPageNumber(markdown) {
|
|
4493
|
+
const matches = [...markdown.matchAll(/\.{2,}\s*(\d+)/g)];
|
|
4494
|
+
if (matches.length === 0) {
|
|
4495
|
+
return 0;
|
|
4496
|
+
}
|
|
4497
|
+
return Math.max(...matches.map((m) => parseInt(m[1], 10)));
|
|
4498
|
+
}
|
|
4483
4499
|
/**
|
|
4484
4500
|
* Process resource captions (for images and tables)
|
|
4485
4501
|
*
|