Is there a way to convert markdown to interpreted RTF?

4.9k views Asked by At

I am trying to convert a text from markdown to rendered RTF in a shell script and wrap the command in an Apple Automator Service.

I realized that the only way to achieve the task is by doing:

python -m markdown | textutil -convert rtf -format html -stdin -stdout -font Helvetica -inputencoding UTF-8 | pbcopy | pbpaste -Prefer rtf

Question:

  • How to avoid using the clipboard to interpret RTF?
  • Is there another application to use instead of pbcopy pbpaste?

Cmd explain:

  • python -m markdown does the main work
  • textutil [… opts] converts from HTML to RTF
  • pbcopy | pbpaste -Prefer rtf does the magic interpreting plain-text RTF directives out from textutil and returning as interpreted RTF.

The issue would be far easier if RTF were not requested to be interpreted. I already tried to call the first two steps of the pipe and able to save rtf-formatted files (and other formats as well) correctly.

1

There are 1 answers

2
Canuto-C On

Did you take a look at Pandoc ? This tool can convert Markdown files to RTF easily.

Usage:

pandoc -s INPUT.md -o OUTPUT.rtf

[EDIT]

If you want a full pythonic solution, you can use the package pypandoc which is a wrapper around the pandoc tool (thanks @rusty-shackleford for the comment)