[英]Write reStructuredText t programmatically in Python
Is there any Python3.X library that helps to write rST file/text.是否有任何有助于编写 rST 文件/文本的 Python3.X 库。 I do not want to write rST file with manual styling with file.write().我不想使用 file.write() 编写带有手动样式的 rST 文件。 I am looking for a library which makes it easier to create an rST file with different elements like bold, underline, tables.我正在寻找一个库,它可以更轻松地创建具有不同元素(如粗体、下划线、表格)的 rST 文件。
Note : I do not want to read a rST file, rather I want to create a rST file programmatically注意:我不想读取 rST 文件,而是想以编程方式创建 rST 文件
Use RstCloth to create RST-files via an easy Python API.使用RstCloth通过简单的 Python API 创建 RST 文件。
from rstcloth import RstCloth
d = RstCloth()
d.title('Example Use')
d.newline()
d.h2('Contents')
d.directive(name="contents", fields=[('local', ''), ('backlinks', 'None')])
d.newline()
d.h2('Code -- shebang')
d.codeblock('#!/usr/bin/env')
d.print_content()
Result:结果:
===========
Example Use
===========
Contents
--------
.. contents::
:local:
:backlinks: None
Code -- shebang
---------------
::
#!/usr/bin/env
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.