3

Is there any Python3.X library that helps to write rST file/text. I do not want to write rST file with manual styling with file.write(). I am looking for a library which makes it easier to create an rST file with different elements like bold, underline, tables.

Note: I do not want to read a rST file, rather I want to create a rST file programmatically

Kumar Roshan Mehta
  • 3,078
  • 2
  • 27
  • 50
  • Look into Pandoc, docutils, sphinx – Thaer A May 06 '20 at 14:55
  • I do look into sphinx but as far as I found it is only parsing a rST file. – Kumar Roshan Mehta May 06 '20 at 14:57
  • Where is this library you are looking for suppose to get its content from? Normally a Human writes RST and then a computer will turn that into a final product (HTML, PDF, etc...) – noslenkwah May 06 '20 at 15:35
  • 1
    I wished to have a have library which makes my life easier to create and write rST file. e.g. subsubtitle text, writing it with file.write(subsubtitle) and file.write(*********) I find it too cumbersome. – Kumar Roshan Mehta May 06 '20 at 15:46
  • I was wondering something similar to get around some other problem. At one point I considered hacking up rst2rst. I found a more standard solution - so this was not necessary for me. rst2rst: https://pypi.org/project/rst2rst/ – natersoz Oct 09 '20 at 23:49

1 Answers1

2

Use RstCloth to create RST-files via an easy Python API.

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
danwos
  • 416
  • 3
  • 12