question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

reStructuredText in docstrings not converted to Markdown

See original GitHub issue

Some 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:closed
  • Created 3 years ago
  • Comments:18 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
pappasamcommented, Feb 8, 2021

@krassowski amazing, I can’t wait to play around with this!

1reaction
krassowskicommented, Feb 7, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found