fix: deduplicate markdown table chunks (#16143)

This commit is contained in:
helloxjade
2026-06-24 13:22:57 +08:00
committed by GitHub
parent 39b194453d
commit 1b2da645c3
3 changed files with 41 additions and 6 deletions

View File

@@ -781,6 +781,7 @@ class Markdown(MarkdownParser):
return images, cache
def __call__(self, filename, binary=None, separate_tables=True, delimiter=None, return_section_images=False):
"""Parse markdown into text sections and optional standalone table chunks."""
if binary:
encoding = find_codec(binary)
txt = binary.decode(encoding, errors="ignore")
@@ -789,10 +790,9 @@ class Markdown(MarkdownParser):
txt = f.read()
remainder, tables = self.extract_tables_and_remainder(f"{txt}\n", separate_tables=separate_tables)
# To eliminate duplicate tables in chunking result, uncomment code below and set separate_tables to True in line 410.
# extractor = MarkdownElementExtractor(remainder)
extractor = MarkdownElementExtractor(txt)
image_refs = self.extract_image_urls_with_lines(txt)
parsing_text = remainder if separate_tables else txt
extractor = MarkdownElementExtractor(parsing_text)
image_refs = self.extract_image_urls_with_lines(parsing_text)
element_sections = extractor.extract_elements(delimiter, include_meta=True)
sections = []
@@ -1017,7 +1017,7 @@ def chunk(filename, binary=None, from_page=0, to_page=MAXIMUM_PAGE_NUMBER, lang=
sections, tables, section_images = markdown_parser(
filename,
binary,
separate_tables=False,
separate_tables=True,
delimiter=parser_config.get("delimiter", "\n!?;。;!?"),
return_section_images=True,
)

View File

@@ -955,7 +955,7 @@ class Parser(ProcessBase):
sections, tables, section_images = markdown_parser(
name,
blob,
separate_tables=False,
separate_tables=True,
delimiter=conf.get("delimiter"),
return_section_images=True,
)