Skip to content

fix(doc2md): read PPTX strikethrough from a:rPr, not Font.strike - #18399

Open
MohammadHijjawi97 wants to merge 1 commit into
PaddlePaddle:mainfrom
MohammadHijjawi97:fix/doc2md-pptx-strikethrough
Open

MohammadHijjawi97 wants to merge 1 commit into
PaddlePaddle:mainfrom
MohammadHijjawi97:fix/doc2md-pptx-strikethrough

Conversation

@MohammadHijjawi97

Copy link
Copy Markdown

Description

doc2md_convert fails on any .pptx that contains a table with text:

RuntimeError: Failed to convert deck.pptx: 'Font' object has no attribute 'strike'

The table-cell code in paddleocr/_doc2md/converters/pptx.py reads run.font.strike, but python-pptx's Font has no strikethrough property (python-pptx 1.0.2 exposes only bold, color, fill, italic, language_id, name, size and underline).

The helper meant for this, _pptx_run_strike(), had a second bug: it looked up a namespace-qualified strike attribute, but DrawingML writes strike unqualified on <a:rPr> (the same as baseline, which _pptx_run_script() already reads correctly). So strikethrough in text boxes was never rendered either.

Changes:

  • _pptx_run_strike() reads the unqualified strike attribute (sngStrike / dblStrike).
  • Table cells use _pptx_run_strike() instead of run.font.strike.
  • New tests/doc2md/test_pptx_converter.py builds small decks with python-pptx in tmp_path and checks a table (with a struck cell) and a text box with struck and plain runs.

Repro (deck: one 2x2 table, one text box with a struck run):

Before:

RuntimeError Failed to convert t.pptx: 'Font' object has no attribute 'strike'

After:

<table>
<tr>
<th>Name</th>
<th>Value</th>
</tr>
<tr>
<td>a</td>
<td><del>1</del></td>
</tr>
</table>

- ~~old price~~

Testing

  • pytest tests/doc2md tests/utils: 4 passed. Both new tests fail without the fix.
  • black 24.10.0 and flake8 7.1.1 (the pre-commit pins) are clean on the changed files.

python-pptx's Font has no `strike` attribute, so converting any PPTX
that contains a table with text failed with
"RuntimeError: Failed to convert ...: 'Font' object has no attribute
'strike'". Table cells now use _pptx_run_strike() like text frames do.

_pptx_run_strike() itself looked up a namespace-qualified "strike"
attribute, but DrawingML writes it unqualified on <a:rPr> (as with
"baseline"), so strikethrough in text frames was never rendered.
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants