ocr_mkcontent.py 924 B

1234567891011121314151617181920212223
  1. def mk_nlp_markdown(pdf_info_dict: dict):
  2. markdown = []
  3. for _, page_info in pdf_info_dict.items():
  4. blocks = page_info.get("preproc_blocks")
  5. if not blocks:
  6. continue
  7. for block in blocks:
  8. for line in block['lines']:
  9. line_text = ''
  10. for span in line['spans']:
  11. if not span.get('content'):
  12. continue
  13. content = span['content'].replace('$', '\$') # 转义$
  14. if span['type'] == 'inline_equation':
  15. content = f"${content}$"
  16. elif span['type'] == 'displayed_equation':
  17. content = f"$$\n{content}\n$$"
  18. line_text += content + ' '
  19. # 在行末添加两个空格以强制换行
  20. markdown.append(line_text.strip() + ' ')
  21. return '\n'.join(markdown)