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 worktextutil [… opts]
converts from HTML to RTFpbcopy | pbpaste -Prefer rtf
does the magic interpreting plain-text RTF directives out fromtextutil
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.
Did you take a look at Pandoc ? This tool can convert Markdown files to RTF easily.
Usage:
[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)