CSEE
CSEE

Reputation: 11

How to include images when converting Markdown to RTF using Pandoc?

Title: How to Include Images When Converting Markdown to RTF Using Pandoc?

I'm working on a script that converts Markdown to RTF format using Pandoc, followed by textutil for the final conversion to RTF. My challenge is that images from the Markdown file are not appearing in the RTF output.

Here's the relevant part of my index.ts script:

// ... [previous code]
await execAsync(`${pandocPath} -f markdown-smart -t html -H ${cssHtmlPath} ${tempMarkdownPath} -o ${tempHtmlPath}`);
await execAsync(`textutil -inputencoding utf-8 -format html -convert rtf ${tempHtmlPath} -output ${tempRtfPath}`);
// ... [following code]

And here's an example of the Markdown with an image:

![Random Image](https://letsenhance.io/static/8f5e523ee6b2479e26ecc91b9c25261e/1015f/MainAfter.jpg)

The image appears as expected in the HTML output, but not in the final RTF file. I found out that textutil may not support embedding images during HTML to RTF conversion.

I'm looking for suggestions on alternative tools or methods that could resolve this issue, ideally without significant changes to my current workflow.

Has anyone encountered a similar problem or can offer advice on how to include images in RTF output?

Thank you for your assistance!


Additional Context:

I examined both the HTML and RTF files, and the problem lies in the RTF file not having the images attached. I'm seeking an alternative to textutil on macOS.

What I Want to Achieve:

I want to convert Markdown text into visually styled, formatted text and copy it to my clipboard using the macOS Raycast extension. This allows me to write an email in Markdown, run the script, and get the properly formatted text ready to send.

Here is my Raycast extension, which includes a screencast demonstrating what I want to achieve.

Here is a screencast for what I want to achieve in general: https://raw.githubusercontent.com/yazanzaid00/raycast-extensions/ext/markdown-to-rich-text/extensions/markdown-to-rich-text/media/markdown-to-rich-text.gif

Upvotes: 0

Views: 188

Answers (0)

Related Questions