How convert table from markdown to restructured text

191 Views Asked by At

I am trying to convert a table in markdown format to rst format. I used pandoc and m2r, but the output is the same

import pypandoc

output = pypandoc.convert_file('README.md', 'rst', format='md', outputfile='README.rst')
print(output)

content of README

Sed ut perspiciatis unde omnis iste natus error sit voluptatem
accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae

But I must explain to you how all this mistaken idea of denouncing
pleasure and praising pain was

| heading 1 | heading 3 | heading 2 |
+------------|------------|------------|
| string 1,1 | string 1,3 | string 1,2 |
| string 2,1 | string 2,3 | string 2,2 |
| string 3,1 | string 3,3 | string 3,2 |

What I expect

Sed ut perspiciatis unde omnis iste natus error sit voluptatem
accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae

But I must explain to you how all this mistaken idea of denouncing
pleasure and praising pain was

+-------------+-------------+-------------+
| heading  1  | heading  3  | heading  2  |
+=============+=============+=============+
| string  1,1 | string  1,3 | string  1,2 |
+-------------+-------------+-------------+
| string  2,1 | string  2,3 | string  2,2 |
+-------------+-------------+-------------+
| string  3,1 | string  3,3 | string  3,2 |
+-------------+-------------+-------------+

But nothing changes.

1

There are 1 best solutions below

0
On BEST ANSWER

I used your code and your input. I just changed the '+' sign to a '|' in README.md, which I assume was a typo.

It gave me this output:

Sed ut perspiciatis unde omnis iste natus error sit voluptatem
accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae

But I must explain to you how all this mistaken idea of denouncing
pleasure and praising pain was

========== ========== ==========
heading 1  heading 3  heading 2
========== ========== ==========
string 1,1 string 1,3 string 1,2
string 2,1 string 2,3 string 2,2
string 3,1 string 3,3 string 3,2
========== ========== ==========

This is not the grid table you expected but this is still a valid table in rst format.