Skip to content

Fix ragged PDF tables, newlines in HTML link/image titles, and non-positive page width handling - #2796

Open
scks1 wants to merge 1 commit into
microsoft:mainfrom
scks1:fix-converter-silent-drops
Open

scks1 wants to merge 1 commit into
microsoft:mainfrom
scks1:fix-converter-silent-drops

Conversation

@scks1

@scks1 scks1 commented Oct 30, 2026 •

Copy link
Copy Markdown

Summary

Two small, independently reproduced defects on 0.1.9, plus one minor
robustness guard:

  1. pdf: _to_markdown_table truncated ragged rows. Column widths came
    from zip(*table) and rows were formatted with zip(row, col_widths);
    zip stops at the shortest row, so cells beyond it were dropped in
    both directions (a long data row lost cells, and a long header lost
    header cells).

  2. html/markdownify: a newline in a title attribute was emitted
    literally.
    convert_a and convert_img escaped only " in the
    title, producing a literal newline inside the quoted title and breaking
    the link/image syntax. convert_img already collapsed newlines in
    alt; the title was missed.

  3. pdf (minor): a non-positive page width dropped form tables.
    _extract_form_content_from_words compared line widths against
    page.width * 0.55; with a degenerate width of 0 every row counted as
    a paragraph and the form content was dropped. This is a robustness
    guard — the trigger requires a degenerate MediaBox, and page text
    still survives via the extract_text fallback.

Changes

  • _pdf_converter.py: pad rows to the widest row before computing column
    widths in _to_markdown_table; fall back to page_width = 612 when
    page.width is missing, zero, or negative.
  • _markdownify.py: collapse \n to a space in the title in
    convert_a and convert_img, as convert_img already did for alt.

Scope note

This PR originally also fixed notebooks whose cell source is a single
string (valid nbformat v4) losing their title in the IPYNB converter.
That fix and its tests have been withdrawn: #2768 covers it with an
identical mechanism, and #2549 covers a broader form of it. The
remaining components — the PDF table pad, the page-width guard, and the
markdownify title fix — have no competing PR.

Tests

Six new tests (seven cases; the page-width test is parametrized over 0
and −5) across tests/test_html.py and tests/test_pdf.py, each
failing on 0.1.9 and passing with this change: both ragged-table
directions, both title-newline cases, and the non-positive page width.

Full run of tests/test_docx.py, tests/test_pdf.py,
tests/test_module_misc.py, and tests/test_html.py on the narrowed
tree: 338 passed, 11 skipped.

Disclosure: this contribution was prepared by Árbol, an AI assistant working under the direction of the account holder (scks1), who set the acceptance criteria and verified the results before submission.

@scks1
scks1 force-pushed the fix-converter-silent-drops branch from 137321a to fd4e545 Compare October 30, 2026 19:27
@scks1 scks1 changed the title Fix ipynb string-source titles, ragged PDF tables, and newlines in HTML link/image titles Fix ragged PDF tables, newlines in HTML link/image titles, and non-positive page width handling Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant