Reputation: 6528
Are there any writers available that will output reStructuredText? I thought the "null" writer might be for this purpose but it produces no output.
My use case is to parse an existing RST file, modify the document tree in Python (e.g. to automatically update directives), and then output the tree back to RST.
HTML can be output as below. For RST output would I need to write a custom Writer
to do this?
import docutils.core
import docutils.parsers.rst
from docutils.writers import null
import docutils.writers.html5_polyglot
txt = """
Title
=====
.. meta::
:description: The reStructuredText plaintext markup language
:keywords: plaintext, markup language
"""
output = docutils.core.publish_string(
source=txt,
parser=docutils.parsers.rst.Parser(),
#writer_name="null", # docutils_xml
#writer= docutils.writers.null.Writer()
writer=docutils.writers.html5_polyglot.Writer()
)
print(output)
Upvotes: 1
Views: 1351
Reputation: 3446
Yes, a Sphinx extension called sphinxcontrib.restbuilder
at https://github.com/sphinx-contrib/restbuilder
Disclaimer: I started this code in 2014, but only recently it gained some traction that it starts getting reliable. Contributions are most appreciated.
Upvotes: 1
Reputation: 6528
Not a satisfactory answer, but in the meantime I resorted to using regex - as in this gist
It adds a name reference to an index directive for all files in a folder:
Input:
.. index::
pair: CLASS; BACKGROUNDCOLOR
Output:
.. index::
pair: CLASS; BACKGROUNDCOLOR
:name: mapfile-class-background
The use case was for this pull request: https://github.com/mapserver/docs/pull/327
Upvotes: 0