Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Being able to use markdown in docs (files, module docs, function/class docs) #1

Closed
thorwhalen opened this issue Sep 3, 2021 · 5 comments · Fixed by #6
Closed

Being able to use markdown in docs (files, module docs, function/class docs) #1

thorwhalen opened this issue Sep 3, 2021 · 5 comments · Fixed by #6
Assignees
Labels
enhancement New feature or request

Comments

@thorwhalen
Copy link
Member

@thorwhalen thorwhalen added the enhancement New feature or request label Sep 3, 2021
@sylvainbonnot
Copy link
Collaborator

sylvainbonnot commented Sep 6, 2021

Here are some thoughts on that:

  • sphinx offers some support for markdown: https://myst-parser.readthedocs.io/en/latest/sphinx/intro.html, allowing to use .md files instead of .rst files to generate the docs.
  • even with myst-parser, sphinx cannot at the moment convert markdown written within the docstrings: see the github issue no md in docstring
  • pros of md: easier syntax, more people can read and write it
  • workaround to convert markdown written inside a docstring (I checked it worked with sphinx, did not check yet with epythet):
    • pip install commonmark
    • inside the conf.py file of the sphinx doc, include this snippet:
      import commonmark
    
      def docstring(app, what, name, obj, options, lines):
          md  = '\n'.join(lines)
          ast = commonmark.Parser().parse(md)
          rst = commonmark.ReStructuredTextRenderer().render(ast)
          lines.clear()
          lines += rst.splitlines()
    
      def setup(app):
          app.connect('autodoc-process-docstring', docstring)
    

@thorwhalen
Copy link
Member Author

That could work. How/where do we integrate with epythet. See with @andeaseme .

@thorwhalen
Copy link
Member Author

Can you include some reference about how there's no support for md-parsing module's and function's docstrings in sphinx? Seems like if they can do it with files, docstrings shouldn't be too far away.

@sylvainbonnot
Copy link
Collaborator

sylvainbonnot commented Sep 7, 2021

The fact that sphinx, even with the myst-parser extension cannot do autodoc on functions docstrings without a hack is documented in that issue : no md docstring.

@sylvainbonnot
Copy link
Collaborator

This has been integrated in my fork of epythet: https://github.com/sylvainbonnot/epythet/blob/dev-sylvain/epythet/_static/docsrc/conf.py

In short: markdown within docstrings can be read by epythet.

Here is an example with a code block within docstrings:
Screen Shot 2021-09-22 at 10 41 15

@sylvainbonnot sylvainbonnot linked a pull request Sep 22, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants