Convert Markdown text to RTF, using Ruby and Pandoc?

Posted by niteshade on Stack Overflow See other posts from Stack Overflow or by niteshade
Published on 2012-10-09T03:33:16Z Indexed on 2012/10/09 3:37 UTC
Read the original article Hit count: 136

Filed under:
|
|
|
|

Playing with Ruby and Ruby-Pandoc. Seems like a nice tool, if I can get it to work.

I'd like to convert some Markdown text (with embedded lists and other fanciness) to Rich Text. Here's the text I'm converting:

Title
===

This is a paragraph. Hallelujah.

Here comes a nested list.
---

* List item 1
  * List item 1.1
  * List item 1.2
* List item 2
  * List item 2.1

Here's my Ruby code...

require 'pandoc-ruby'

input = File.read(test.md)
converter = PandocRuby.new(input, from: :markdown, to: :rtf)
puts converter.convert

... which (after saving the output to a file) produces a document without anything but a title:

screenshot of RTF

Here's the code of the RTF file:

{\pard \ql \f0 \sa180 \li0 \fi0 \b \fs36 Title\par}
{\pard \ql \f0 \sa180 \li0 \fi0 This is a paragraph. Hallelujah.\par}
{\pard \ql \f0 \sa180 \li0 \fi0 \b \fs32 Here comes a nested list.\par}
{\pard \ql \f0 \sa0 \li360 \fi-360 \bullet \tx360\tab List item 1\par}
{\pard \ql \f0 \sa0 \li360 \fi-360 \bullet \tx360\tab List item 1.1\par}
{\pard \ql \f0 \sa0 \li360 \fi-360 \bullet \tx360\tab List item 1.2\par}
{\pard \ql \f0 \sa0 \li360 \fi-360 \bullet \tx360\tab List item 2\par}
{\pard \ql \f0 \sa0 \li360 \fi-360 \bullet \tx360\tab List item 2.1\sa180\par}

In addition, even if it did show up in my RTF viewer (Mac TextEdit), the RTF code seems to have lost all list nesting. I don't know how to diagnose this, whether I have not stated necessary header information or something in Ruby-Pandoc.

Thanks in advance!

© Stack Overflow or respective owner

Related posts about ruby

Related posts about markdown