15

I have rst files containing lines like

.. figure:: examples/foo.png 
    :scale: 80%

    Fig. 1 : Illustration of the awesomeness of stackoverflow

now I want this file to be converted into markdown. I tried using pandoc,

pandoc -s -w rst --toc foo.rst -o foo.md

but the output file foo.md seems ignore the figure inclusion lines. So, how can I convert into markdown files without losing the awesomeness of figures? Thanks

nye17
  • 12,857
  • 11
  • 58
  • 68
  • If you want to output Markdown, you don't want the `-w rst` flag, which tells it to write rst. – poolie Nov 30 '15 at 16:25

1 Answers1

4

This online demonstration of Pandoc converts the following markdown:

![Map to buried treasure](/path/to/img.jpg "Optional title")

into the following reStructuredText:

.. figure:: /path/to/img.jpg
   :align: center
   :alt: Optional title

   Map to buried treasure

So this should be how you can define a figure that can be converted to markdown. However, using this reStructuredText in the online converter causes an error with a very unhelpful error message. Do you get any error messages when you run Pandoc?

Perhaps your reStructuredText syntax is incorrect: options to the figure (and any other) directive should be indented with respect to the directive name. Try using

.. figure:: examples/foo.png 
   :scale: 80%

   Fig. 1 : Illustration of the awesomeness of stackoverflow

and see if that makes a difference.

Chris
  • 44,602
  • 16
  • 137
  • 156
  • there was no error reported when I ran pandoc, and my rst syntax is right - it is shown correctly elsewhere or when converted to html etc. – nye17 May 27 '12 at 02:30
  • Then this is probably a bug with Pandoc. I would email the developers or raise this on the Pandoc mailing list/issue tracker. – Chris May 27 '12 at 08:41
  • Sure, and it seems that there is no alternative tools for doing the job. – nye17 May 27 '12 at 15:52
  • One thing you could try is to convert from reStructuredText to another format, say HTML, and then convert to markdown. Not a great solution but worth giving it a go. – Chris May 27 '12 at 19:20