Skip to content

Expose embedded image assets in markdown output #63

Description

@adiberk

Context

When processing DOCX files, to_document() correctly extracts embedded images into doc.assets (with raw bytes, media type, and origin part). However, these images don't appear in the markdown output from to_markdown_bytes() — there are no ![alt](...) references, and the inline block model doesn't surface image inlines.

Current behavior

doc = anydoc.to_document(docx_bytes)
print(len(doc.assets))  # 1 (608KB PNG found)

md = anydoc.to_markdown_bytes(docx_bytes)
print("![" in md)  # False (no image references)

The asset data is extracted and available, but the markdown doesn't reference it.

Request

It would be useful if to_markdown_bytes() emitted image references (e.g., ![alt text](asset:0) or ![](embedded:image0.png)) at the positions where images appear in the document. The actual bytes are already in doc.assets — consumers could then decide whether to inline them as data URIs, upload them, or send them to a vision model for descriptions.

This would also apply to XLSX and PPTX files that contain embedded images/charts.

Workaround

Using to_document() to get the asset bytes and processing them separately works, though without positional information it's hard to associate an image with the surrounding content.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions