'Is there a way to convert markdown to interpreted RTF?

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.



Solution 1:[1]

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)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1