3

I'm rookie with Sphinx, and I was trying to figure out how to use MyST parser for sphinx to make it work with .autodoc extension.

I found this thread. I've been trying to convert this code to work with MyST and I failed.

I've been trying to do something like this:

import myst_parser

def docstring(app, what, name, obj, options, lines):
    md  = '\n'.join(lines)
    ast = myst_parser.sphinx_parser.MystParser().parse(md)
    rst = myst_parser.ReStructuredTextRenderer().render(ast)
    lines.clear()
    lines += rst.splitlines()

def setup(app):
    app.connect('autodoc-process-docstring', docstring)

I don't know what else should I pass to parse method. and what to do afterwards (from what I saw myst_parser doesnt have ReStructuredTextRenderer).

Could anyone help me with it? Thx

mzjn
  • 48,958
  • 13
  • 128
  • 248
Rafal
  • 83
  • 5
  • I've just edited the post with more detail – Rafal Jun 23 '21 at 12:53
  • 3
    See open issue in the MyST tracker: https://github.com/executablebooks/MyST-Parser/issues/228 – Steve Piercy Jun 24 '21 at 08:31
  • @JohnHennig your code strips out necessary whitespace from the docstring, and doesn't use MyST. You even say "MyST does not yet support Markdown in doc-strings either", which is essentially an answer to this question – Will Da Silva Jun 24 '21 at 21:36
  • A way to do the above conversion from markdown to rst without losing the whitespace would be great. – Will Da Silva Jun 24 '21 at 21:53

0 Answers0