Last active
May 25, 2021 20:07
-
-
Save dmwyatt/0f555c8f9c129c0ac6fed6fabe49078b to your computer and use it in GitHub Desktop.
[Sphinx docs as markdown] Parse autodoc as markdown #sphinx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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