Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance _markitdown.py to support embedding images in markdown #205

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

MauroDruwel
Copy link

This update enhances the DocxConverter class by adding functionality to extract and embed images when converting DOCX files to Markdown. The changes include:

  • convert_image method: Handles image extraction, sanitizes the filename, and saves the image as a PNG in the specified output directory.
  • convert method: Integrates the convert_image method with the Mammoth library's HTML conversion process, ensuring images are extracted and included in the final output.

@MauroDruwel
Copy link
Author

@microsoft-github-policy-service agree

@afourney
Copy link
Member

afourney commented Jan 3, 2025

Looks promising. @MauroDruwel Can you please add some test cases?

Also, sanitizing filenames is a task that will come up a lot (and my already be implemented). I'm going to ask around for advice on how to handle this broadly and robustly (without regular expressions). Filenames may also have other restrictions (e.g., length etc.) on some OSs.

@afourney afourney requested review from afourney and gagb January 3, 2025 21:49
@afourney afourney added the awaiting op response The PR is awaiting response/edits from the original poster. label Jan 3, 2025
@MauroDruwel
Copy link
Author

Hi @afourney,

I've added the following improvements:

  1. Test cases: I've included some test cases, which you can view in the result here.
  2. Filename formatting: I've replaced spaces with underscores in filenames to ensure compatibility.
  3. Length limit checker: A checker has been added to enforce a length limit for filenames.
  4. File existence check: Now the script checks if the file already exists and appends a counter to avoid overwriting.
  5. Alt text formatting: I've fixed an issue where newlines in the image alt_text were causing images not to show by removing them.

Let me know if you need any further adjustments!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting op response The PR is awaiting response/edits from the original poster.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants