Skip to content

Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.

Merge branch 'dev' into content-list-not-drop

Xiaomeng Zhao98313d4a25fa
diff --cc magic_pdf/dict2md/ocr_mkcontent.py
index 0293a7a9,49d90587..21c9d7a2
--- a/magic_pdf/dict2md/ocr_mkcontent.py
+++ b/magic_pdf/dict2md/ocr_mkcontent.py
@@@ -265,39 -272,41 +272,39 @@@ def para_to_standard_format(para, img_b
return para_content
- def para_to_standard_format_v2(para_block, img_buket_path, page_idx, drop_reason=None):
-def para_to_standard_format_v2(para_block, img_buket_path, page_idx, parse_type="auto", lang=None):
++def para_to_standard_format_v2(para_block, img_buket_path, page_idx, parse_type="auto", lang=None, drop_reason=None):
para_type = para_block['type']
+ para_content = {}
if para_type == BlockType.Text:
para_content = {
'type': 'text',
- 'text': merge_para_with_text(para_block),
+ 'text': merge_para_with_text(para_block, parse_type=parse_type, lang=lang),
- 'page_idx': page_idx,
}
elif para_type == BlockType.Title:
para_content = {
'type': 'text',
- 'text': merge_para_with_text(para_block),
+ 'text': merge_para_with_text(para_block, parse_type=parse_type, lang=lang),
'text_level': 1,
- 'page_idx': page_idx,
}
elif para_type == BlockType.InterlineEquation:
para_content = {
'type': 'equation',
- 'text': merge_para_with_text(para_block),
+ 'text': merge_para_with_text(para_block, parse_type=parse_type, lang=lang),
'text_format': 'latex',
- 'page_idx': page_idx,
}
elif para_type == BlockType.Image:
- para_content = {'type': 'image', 'page_idx': page_idx}
+ para_content = {'type': 'image'}
for block in para_block['blocks']:
if block['type'] == BlockType.ImageBody:
para_content['img_path'] = join_path(
img_buket_path,
block['lines'][0]['spans'][0]['image_path'])
if block['type'] == BlockType.ImageCaption:
- para_content['img_caption'] = merge_para_with_text(block)
+ para_content['img_caption'] = merge_para_with_text(block, parse_type=parse_type, lang=lang)
if block['type'] == BlockType.ImageFootnote:
- para_content['img_footnote'] = merge_para_with_text(block)
+ para_content['img_footnote'] = merge_para_with_text(block, parse_type=parse_type, lang=lang)
elif para_type == BlockType.Table:
- para_content = {'type': 'table', 'page_idx': page_idx}
+ para_content = {'type': 'table'}
for block in para_block['blocks']:
if block['type'] == BlockType.TableBody:
if block["lines"][0]["spans"][0].get('latex', ''):
@@@ -306,15 -315,10 +313,15 @@@
para_content['table_body'] = f"\n\n{block['lines'][0]['spans'][0]['html']}\n\n"
para_content['img_path'] = join_path(img_buket_path, block["lines"][0]["spans"][0]['image_path'])
if block['type'] == BlockType.TableCaption:
- para_content['table_caption'] = merge_para_with_text(block)
+ para_content['table_caption'] = merge_para_with_text(block, parse_type=parse_type, lang=lang)
if block['type'] == BlockType.TableFootnote:
- para_content['table_footnote'] = merge_para_with_text(block)
+ para_content['table_footnote'] = merge_para_with_text(block, parse_type=parse_type, lang=lang)
+ para_content['page_idx'] = page_idx
+
+ if drop_reason is not None:
+ para_content['drop_reason'] = drop_reason
+
return para_content
@@@ -397,11 -401,11 +404,13 @@@ def ocr_mk_mm_standard_format(pdf_info_
def union_make(pdf_info_dict: list,
make_mode: str,
drop_mode: str,
- img_buket_path: str = ''):
+ img_buket_path: str = '',
+ parse_type: str = "auto",
+ lang=None):
output_content = []
for page_info in pdf_info_dict:
+ drop_reason_flag = False
+ drop_reason = None
if page_info.get('need_drop', False):
drop_reason = page_info.get('drop_reason')
if drop_mode == DropMode.NONE:
@@@ -432,13 -434,8 +441,12 @@@
output_content.extend(page_markdown)
elif make_mode == MakeMode.STANDARD_FORMAT:
for para_block in paras_of_layout:
- para_content = para_to_standard_format_v2(
- para_block, img_buket_path, page_idx, parse_type=parse_type, lang=lang)
+ if drop_reason_flag:
+ para_content = para_to_standard_format_v2(
- para_block, img_buket_path, page_idx, drop_reason)
++ para_block, img_buket_path, page_idx, parse_type=parse_type, lang=lang, drop_reason=drop_reason)
+ else:
+ para_content = para_to_standard_format_v2(
- para_block, img_buket_path, page_idx)
-
++ para_block, img_buket_path, page_idx, parse_type=parse_type, lang=lang)
output_content.append(para_content)
if make_mode in [MakeMode.MM_MD, MakeMode.NLP_MD]:
return '\n\n'.join(output_content)