0

I am using VuePress for documentation, but find the more precise formatting and support for Python code in reStructured Text useful at times.

How can I use Sphinx and/or reStructuredText to generate fragments of HTML that I will later integrate?

How can I programmatically drive Sphinx autodoc directives is basically what my question is about. I saw something from 2003 about Sphinx parts, but what's the current way to do it?

Example:

given file test.rst:



######
.. autoclass:: mymodule.MyClass
    :members:  __init__, process


######

And mymodule.py

class MyClass:

    def __init__(self, *args, **kwargs):
        """ init """

    def process(self, f_out : "file"):
        "process"
        print("I am processing")

I can generate html documentation with

sphinx-build -a . ./out

and opening the generated out/test.html gives me:

enter image description here

where the part that I am interested in is really only:

<dl class="class">
    <dt id="mymodule.MyClass">
        <em class="property">class </em><code class="sig-prename descclassname">mymodule.</code><code
            class="sig-name descname">MyClass</code><span class="sig-paren">(</span><em class="sig-param">*args</em>,
        <em class="sig-param">**kwargs</em><span class="sig-paren">)</span><a class="headerlink"
            href="#mymodule.MyClass" title="Permalink to this definition">¶</a></dt>
    <dd>
✂️✂️✂️✂️
    </dd>
</dl>

bad_coder
  • 11,289
  • 20
  • 44
  • 72
JL Peyret
  • 10,917
  • 2
  • 54
  • 73
  • "something from 2003 about Sphinx parts". What is that? Sphinx did not exist in 2003. – mzjn Feb 08 '20 at 06:18
  • @mzjn Must have been just rst itself then. [Here it is](http://code.activestate.com/recipes/193890-using-rest-restructuredtext-to-create-html-snippet/) Point is, nothing really recent seems to be around and while I see the value of rst's integration with Python, I really prefer Markdown, even with its shortcomings, most of the time. – JL Peyret Feb 12 '20 at 03:23

0 Answers0