Markdown and RTF

11/12/2005 11:00:33

I was thinking about how to best convert from Markdown to RTF. I thought about other projects I have worked on (ScreenplayFormatPro for instance) and how it’s not that hard to generate RTF.

The problem is that RTF is a pretty weak format, and I don’t use it any more. I really didn’t want to spend a lot of time working on something that I am not going to use (since I don’t get paid for the overwhelming majority of computer software I write).

Then I remembered that TextEdit imports HTML files and exports RTF and RTFD documents.

This is the perfect answer (for Mac users anyways).

Work with Markdown and MultiMarkdown like you normally do. If you use MultiMarkdown, you can generate PDF’s like you normally do. But when you want an RTF, simply open your HTML file in \TextEdit, and then you can export it to RTF. It handles tables, images, links (but not crossreference links within a MultiMarkdown document).

As a test, I converted the MultiMarkdown page, which is a relatively complex example. I was quite pleased with the overall output. There was one link that had some extra underlining (it is at the beginning of a list item), and there are a few paragraphs that need an extra carriage return in front of them to clarify that they are new paragraphs. But overall, it is pretty good, and much better than spending a lot of time trying to create something from scratch that I will never use.

And then, of course, you can import the RTF into Microsoft Word, and save your output as a doc file (granted, Microsoft somehow manages to screw up the formatting when importing their own document type (RTF) but that’s another story.)

Alternative Approach

Bill Muench pointed out the textutil tool included in Mac OS 10.4 that allows you to convert various document formats (txt, html, rtf, rtfd, doc, wordml, or webarchive). Unlike using TextEdit, I don’t seem to be able to get images to work when using the command-line approach. In either case, it does add an easy route to convert to .doc files (though I can’t imagine why you would want to… ;)

I don’t have much use for this, but would be interested in getting images to work.

For more information, try man textutil in Terminal.

Limitations

  • blockquotes do not seem to be indented or set apart in any other way. You must manually do that.

  • codeblocks are not indented, but are converted to monospace font.

Other fetaures

  • \TextEdit (in Tiger anyways) will let you name your own styles - you can copy the style from a list item, and use that to format blockquotes, and then do something similar for code blocks. A PITA if you are doing it often, but not too bad infrequently. (And why are you working so much in RTF files anyways!!!! Use Markdown for your source document and pdf for the final. ;)

Similar Pages

Old Comments

This is awesome. I had no idea that utility existed. I just converted a markdown document to an RTF file. I’ve always wanted to be able to use CSS and HTML to create RTF documents. Fantastic post!