-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/dev' into vik_dev
- Loading branch information
Showing
8 changed files
with
86 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,12 @@ | ||
import re | ||
|
||
from marker.schema import BlockTypes | ||
from marker.schema.blocks import Block | ||
|
||
|
||
def superscript(child_blocks): | ||
# Superscript leading symbol or digit sequence | ||
first_block = None | ||
while len(child_blocks) > 0: | ||
first_block = child_blocks[0] | ||
child_blocks = first_block.children | ||
|
||
if first_block is not None and first_block.id.block_type == BlockTypes.Line: | ||
digit_start = r"^([0-9\W]+)(.*)" | ||
first_block.html = re.sub(digit_start, r"<sup>\1</sup>\2", first_block.html.lstrip()) | ||
|
||
|
||
class Footnote(Block): | ||
block_type: BlockTypes = BlockTypes.Footnote | ||
|
||
def assemble_html(self, document, child_blocks, parent_structure): | ||
template = super().assemble_html(document, child_blocks, parent_structure) | ||
template = template.replace("\n", " ") | ||
|
||
# Add superscripts to start | ||
superscript(child_blocks) | ||
return f"<p>{template}</p>" |
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,32 @@ | ||
import pytest | ||
|
||
from marker.converters.pdf import PdfConverter | ||
from marker.renderers.markdown import MarkdownOutput | ||
from marker.schema import BlockTypes | ||
from marker.schema.document import Document | ||
|
||
|
||
@pytest.mark.filename("arxiv_test.pdf") | ||
@pytest.mark.output_format("markdown") | ||
@pytest.mark.config({"page_range": [1]}) | ||
def test_pdf_links(pdf_document: Document, pdf_converter: PdfConverter, temp_pdf): | ||
first_page = pdf_document.pages[0] | ||
|
||
for section_header_span in first_page.contained_blocks(pdf_document, (BlockTypes.Span,)): | ||
if "II." in section_header_span.text: | ||
assert section_header_span.url == "#page-1-0" | ||
break | ||
else: | ||
raise ValueError("Could not find II. in the first page") | ||
|
||
section_header_block = first_page.contained_blocks(pdf_document, (BlockTypes.SectionHeader,))[0] | ||
assert section_header_block.raw_text(pdf_document) == 'II. THEORETICAL FRAMEWORK\n' | ||
|
||
section_header_span = section_header_block.contained_blocks(pdf_document, (BlockTypes.Span,))[0] | ||
assert section_header_span.anchors == ['page-1-0'] | ||
|
||
markdown_output: MarkdownOutput = pdf_converter(temp_pdf.name) | ||
markdown = markdown_output.markdown | ||
|
||
assert '[II.](#page-1-0)' in markdown | ||
assert '<span id="page-1-0"/>II. THEORETICAL FRAMEWORK' in markdown |