Is there a way to convert markdown to interpreted RTF?
Asked Answered
B

1

5

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.

Blankbook answered 21/12, 2016 at 14:8 Comment(0)
U
10

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)

Unbridled answered 21/12, 2016 at 15:40 Comment(2)
Since this question was tagged for Python, it might be helpful for future searchers who land here to note that pypandoc very conveniently wraps Pandoc.Kweilin
you're right, i'll edit the responseUnbridled

© 2022 - 2024 — McMap. All rights reserved.