-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #300 from VikParuchuri/dev
Better tables, better markdown output, header level detection, table of contents
- Loading branch information
Showing
33 changed files
with
2,646 additions
and
2,767 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from typing import List | ||
|
||
from marker.schema.page import Page | ||
|
||
|
||
def get_pdf_toc(doc, max_depth=15): | ||
toc = doc.get_toc(max_depth=max_depth) | ||
toc_list = [] | ||
for item in toc: | ||
list_item = { | ||
"title": item.title, | ||
"level": item.level, | ||
"page": item.page_index, | ||
} | ||
toc_list.append(list_item) | ||
return toc_list | ||
|
||
|
||
def compute_toc(pages: List[Page]): | ||
toc = [] | ||
for page in pages: | ||
for block in page.blocks: | ||
if block.block_type in ["Title", "Section-header"]: | ||
toc.append({ | ||
"title": block.prelim_text, | ||
"level": block.heading_level, | ||
"page": page.pnum | ||
}) | ||
return toc |
Oops, something went wrong.