Skip to content

Instantly share code, notes, and snippets.

@dmwyatt
Last active May 25, 2021 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmwyatt/0f555c8f9c129c0ac6fed6fabe49078b to your computer and use it in GitHub Desktop.
Save dmwyatt/0f555c8f9c129c0ac6fed6fabe49078b to your computer and use it in GitHub Desktop.
[Sphinx docs as markdown] Parse autodoc as markdown #sphinx
# based on https://stackoverflow.com/a/56428123/23972
import commonmark
def docstring(app, what, name, obj, options, lines):
if len(lines) > 1 and lines[0] == "@&ismd":
md = "\n".join(lines[1:])
ast = commonmark.Parser().parse(md)
rst = commonmark.ReStructuredTextRenderer().render(ast)
lines.clear()
lines += rst.splitlines()
def setup(app):
app.connect("autodoc-process-docstring", docstring)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment