Skip to content

fix(table): escape html-sensitive OCR text in table markdown output#5101

Open
jimmyzhuu wants to merge 1 commit intoPaddlePaddle:developfrom
jimmyzhuu:fix/table-markdown-escaping-paddlex
Open

fix(table): escape html-sensitive OCR text in table markdown output#5101
jimmyzhuu wants to merge 1 commit intoPaddlePaddle:developfrom
jimmyzhuu:fix/table-markdown-escaping-paddlex

Conversation

@jimmyzhuu
Copy link
Copy Markdown

@jimmyzhuu jimmyzhuu commented Apr 20, 2026

Summary

This PR fixes HTML escaping for OCR text inserted into table cell markdown / HTML output.

It applies the fix to both table post-processing paths:

  • table_recognition_post_processing.py
  • table_recognition_post_processing_v2.py

The fix escapes HTML-sensitive OCR text before inserting it into generated <td> content, while preserving a single outer <b>...</b> wrapper when present.

Why This Change

When OCR text inside a table cell contains content such as <recv .../> or <pause .../>, the current HTML assembly path may inject raw OCR text directly into the generated table structure.

This breaks exported markdown / HTML rendering and mixes original OCR content with generated HTML.

The root cause is in PaddleX table post-processing rather than the PaddleOCR wrapper layer.

What Changed

  • escape HTML-sensitive OCR text with html.escape(..., quote=True)
  • preserve a single outer <b>...</b> wrapper for bold cell content
  • keep the existing multi-fragment cell concatenation behavior
  • apply the same behavior to both legacy and v2 table post-processing paths
  • add regression tests for single-fragment, bold-wrapped, and multi-fragment OCR text

Tests

python -m pytest tests/unit/inference/pipelines/table_recognition/test_table_markdown_escaping.py -q
python -m py_compile \
  paddlex/inference/pipelines/table_recognition/table_recognition_post_processing.py \
  paddlex/inference/pipelines/table_recognition/table_recognition_post_processing_v2.py \
  tests/unit/inference/pipelines/table_recognition/test_table_markdown_escaping.py

Related

@paddle-bot
Copy link
Copy Markdown

paddle-bot Bot commented Apr 20, 2026

Thanks for your contribution!

@paddle-bot paddle-bot Bot added the contributor External developers label Apr 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor External developers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant