-
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 remote-tracking branch 'origin/vik_v2' into dev-mose/marker-v2
- Loading branch information
Showing
25 changed files
with
199 additions
and
74 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 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,33 @@ | ||
from bs4 import BeautifulSoup | ||
from marker.v2.renderers import BaseRenderer | ||
from marker.v2.schema import BlockTypes | ||
|
||
|
||
class HTMLRenderer(BaseRenderer): | ||
remove_blocks: list = [BlockTypes.PageHeader, BlockTypes.PageFooter] | ||
image_blocks: list = [BlockTypes.Picture, BlockTypes.Figure] | ||
|
||
def extract_html(self, document, document_output): | ||
soup = BeautifulSoup(document_output.html, 'html.parser') | ||
|
||
content_refs = soup.find_all('content-ref') | ||
ref_block_type = None | ||
for ref in content_refs: | ||
src = ref.get('src') | ||
for item in document_output.children: | ||
if item.id == src: | ||
content = self.extract_html(document, item) | ||
ref_block_type = item.id.block_type | ||
break | ||
|
||
if ref_block_type in self.remove_blocks: | ||
ref.replace_with('') | ||
else: | ||
ref.replace_with(BeautifulSoup(f"<div>{content}</div>", 'html.parser')) | ||
|
||
return str(soup) | ||
|
||
def __call__(self, document): | ||
document_output = document.render() | ||
full_html = self.extract_html(document, document_output) | ||
return full_html |
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,26 +1,17 @@ | ||
from bs4 import BeautifulSoup | ||
from markdownify import markdownify | ||
from marker.v2.renderers import BaseRenderer | ||
|
||
|
||
class MarkdownRenderer(BaseRenderer): | ||
def extract_html(self, document_output): | ||
soup = BeautifulSoup(document_output.html, 'html.parser') | ||
|
||
content_refs = soup.find_all('content-ref') | ||
for ref in content_refs: | ||
src = ref.get('src') | ||
for item in document_output.children: | ||
if item.id == src: | ||
content = self.extract_html(item) | ||
break | ||
|
||
ref.replace_with(BeautifulSoup(content, 'html.parser')) | ||
|
||
return str(soup) | ||
|
||
def __call__(self, document_output): | ||
full_html = self.extract_html(document_output) | ||
return markdownify(full_html) | ||
from marker.v2.renderers.html import HTMLRenderer | ||
|
||
|
||
class MarkdownRenderer(HTMLRenderer): | ||
def __call__(self, document): | ||
document_output = document.render() | ||
full_html = self.extract_html(document, document_output) | ||
return markdownify( | ||
full_html, | ||
heading_style="ATX", | ||
bullets="-", | ||
escape_misc=False, | ||
escape_underscores=False | ||
) | ||
|
||
|
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 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,10 +1,21 @@ | ||
import re | ||
|
||
from marker.v2.schema import BlockTypes | ||
from marker.v2.schema.blocks import Block | ||
|
||
|
||
def replace_bullets(text): | ||
# Replace bullet characters with a - | ||
bullet_pattern = r"(^|[\n ])[•●○■▪▫–—]( )" | ||
replaced_string = re.sub(bullet_pattern, r"\1-\2", text) | ||
return replaced_string | ||
|
||
|
||
class ListItem(Block): | ||
block_type: BlockTypes = BlockTypes.ListItem | ||
|
||
def assemble_html(self, child_blocks): | ||
template = super().assemble_html(child_blocks) | ||
def assemble_html(self, child_blocks, parent_structure): | ||
template = super().assemble_html(child_blocks, parent_structure) | ||
template = template.replace("\n", " ") | ||
template = replace_bullets(template) | ||
return f"<li>{template}</li>" |
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 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,6 +1,5 @@ | ||
from marker.v2.schema import BlockTypes | ||
from marker.v2.schema.blocks import Block | ||
|
||
|
||
class TableGroup(Block): | ||
block_type: BlockTypes = BlockTypes.TableGroup |
Oops, something went wrong.