412-pypandoc

文件格式转换器,例如 txt 和 markdown 格式的转换

https://github.com/JessicaTegner/pypandoc

Pypandoc provides a thin wrapper for pandoc, a universal document converter.

There are two basic ways to use pypandoc: with input files or with input strings.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
import pypandoc

# With an input file: it will infer the input format from the filename
output = pypandoc.convert_file('somefile.md', 'rst')


# ...but you can overwrite the format via the `format` argument:
output = pypandoc.convert_file('somefile.txt', 'rst', format='md')


# alternatively you could just pass some string. In this case you need to
# define the input format:
output = pypandoc.convert_text('# some title', 'rst', format='md')
# output == 'some title\r\n==========\r\n\r\n'