Skip to content

fix: render raw HTML images in generated documents - #19

Merged
leonardosalasd merged 3 commits into
leonardosalasd:mainfrom
mikevillari:fix/html-images
Sep 10, 2026
Merged

leonardosalasd merged 3 commits into
leonardosalasd:mainfrom
mikevillari:fix/html-images

Conversation

@mikevillari

Copy link
Copy Markdown
Contributor

Raw HTML <img> tags were discarded by both HTML renderers, so their images never reached the PDF. Parse image attributes with the standard-library HTMLParser and route them through the existing Markdown image registration and placement methods.

Fixes #18.

This preserves asset deduplication, escaped alt fallback, and opt-in remote fetching. The change handles block/inline images and images inside HTML wrappers; it does not add general HTML/CSS rendering or honor image sizing attributes.

Validation:

  • Original suite before editing: 229 passed.
  • New regressions against the original converter: eight failed, one passed.
  • Full suite after the fix: 238 passed on Python 3.13.5 and Python 3.14.7.
  • Ruff lint and repository-wide format checks passed; git diff --check passed.
  • Built a real PDF through python -m doc_engine build from Markdown containing block and inline HTML images. PDF image inventory shows both placements, and the rendered page was visually checked.

Nine regressions cover embedding, surrounding text, ordering/deduplication with Markdown, attribute case/quotes/entities, missing-source alt fallback, remote-fetch opt-in with a stub, comments/script content, and existing br behavior. No remote image requests were made. AI-assisted implementation and verification.

@leonardosalasd

Copy link
Copy Markdown
Owner

Thanks for this. The approach is the right one — routing HTML images through _register_image and _place instead of growing a second image path is what I would have done, and the regressions are thorough.

I ran the branch here: 238 tests pass, ruff check and format are clean. I also threw awkward input at it — images inside headings and table cells, <picture> and <a> wrappers, an unclosed tag, a data: URI, entity-encoded and single-quoted attributes, uppercase <IMG SRC=...>. Nothing crashed, and every case degraded the way I want it to.

One thing before I merge: the README documents what the converter handles, and this needs a line there. The "Supported Markdown Elements" checklist, and the conversion table above it where ![alt](local.png) lives. Worth stating that sizing attributes are not honored, since this repo's own README puts width on its <img> tags and people will expect that to carry over.

For the record: building this repo's README with your branch now embeds the four GIFs, which is the point, and the shields.io badges fall back to their alt text exactly like remote Markdown images already do. Both are what I want.

@mikevillari

Copy link
Copy Markdown
Contributor Author

Addressed in 8bfc35c: added raw HTML support to both the conversion table and Supported Markdown Elements checklist, and explicitly documented that width, height, and other sizing attributes are not honored. Documentation-only follow-up; converter/test code is unchanged from the 238-test version you verified. Thank you for the additional edge-case checks.

@leonardosalasd
leonardosalasd merged commit e84fccf into leonardosalasd:main Sep 10, 2026
21 checks passed
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.

raw HTML <img> tags are ignored and missing in generated output

2 participants