使用docutils解析和写入RST

问题描述 投票:0回答:1

是否有任何作家可以输出reStructuredText?我以为“空”作家可能是出于这个目的,但它没有产生任何输出。

我的用例是解析现有的RST文件,在Python中修改文档树(例如自动更新指令),然后将树输出回RST。

HTML可以如下输出。对于RST输出,我需要编写一个自定义Writer来做到这一点吗?

    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)
python restructuredtext docutils
1个回答
0
投票
它为文件夹中的所有文件的索引指令添加名称引用:

输入:

.. index:: pair: CLASS; BACKGROUNDCOLOR

输出:

.. index::
    pair: CLASS; BACKGROUNDCOLOR
    :name: mapfile-class-background

用例用于此拉取请求:https://github.com/mapserver/docs/pull/327

© www.soinside.com 2019 - 2024. All rights reserved.