reStructuredText in docstrings not converted to Markdown
See original GitHub issueSome Python docstrings use reStructuredText
, one notable example being pandas. Here’s an example from that link:
def add(num1, num2):
"""
Add up two integer numbers.
This function simply wraps the `+` operator, and does not
do anything interesting, except for illustrating what is
the docstring of a very simple function.
Parameters
----------
num1 : int
First number to add
num2 : int
Second number to add
Returns
-------
int
The sum of `num1` and `num2`
See Also
--------
subtract : Subtract one integer from another
Examples
--------
>>> add(2, 2)
4
>>> add(25, 0)
25
>>> add(10, -10)
0
"""
return num1 + num2
This language server feeds these docstrings back directly to the client without any transformation into Markdown as expected by the LSP spec, so they don’t always render well when you do things like hovers. For example, the code block sections beginning with >>>
don’t look good.
The Microsoft language server has special parsing code in it to handle this; see https://github.com/microsoft/python-language-server/blob/master/src/LanguageServer/Impl/Documentation/DocstringConverter.cs.
Note: I copied this with from a very similar issue I filed on https://github.com/palantir/python-language-server/issues/760
Issue Analytics
- State:
- Created 3 years ago
- Comments:18 (12 by maintainers)
Top Results From Across the Web
restructuredText docstrings to .md files - python
Any .rst files can strictly be converted to .md (or any other format) ... similar to yours on Markdown output for Sphinx based...
Read more >Convert Python docstrings to GitHub markdown readmes
For this purpose, we will use Sphinx. Step 1: Sphinx-markdown-builder. Sphinx does not output markdown, but outputs HTML by default, so a Python ......
Read more >reStructuredText vs Markdown for documentation
In this post I am going to share my experience of using Markdown and reStructuredText (RST) for technical documentation.
Read more >[docs][discuss] Convert ReStructuredText docs to Markdown?
Hi all, Currently the documentation for the TVM site is written in ReStructuredText. However, just about everything else we do is in ...
Read more >docstring-to-markdown
Python 3.6+ · currently can recognise reStructuredText and convert multiple of its features to Markdown · in the future will be able to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@krassowski amazing, I can’t wait to play around with this!
Ok, I tried pyment and pypandoc too. They are not up to task. I hand-crafted https://github.com/krassowski/docstring-to-markdown for now. It’s does the job just about right for >90% of pandas and numpy documentation entries as retrieved by
jedi
. It is conservative in the way that if if cannot confirm that it is in reStructuredText that it knows it raises an error. I plan to add Google docstrings handling too. Just wanted to keep you in the loop. I originally written it in typescript but reverted to Python later today.