Skip to content

Commit 4565e4e

Browse files
committed
Initial commit
1 parent cabb106 commit 4565e4e

File tree

7 files changed

+821
-0
lines changed

7 files changed

+821
-0
lines changed

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,38 @@
11
# docstring-to-markdown
2+
23
On the fly conversion of Python docstrings to markdown
4+
5+
- Python 3.6+
6+
- currently can recognise reStructuredText and convert multiple of its features to Markdown
7+
- in the future will be able to convert Google docstrings too
8+
9+
### Installation
10+
11+
```bash
12+
pip install docstring-to-markdown
13+
```
14+
15+
16+
### Example
17+
18+
Convert reStructuredText:
19+
20+
```python
21+
>>> import docstring_to_markdown
22+
>>> docstring_to_markdown.convert(':math:`\\sum`')
23+
$\\sum$
24+
```
25+
26+
When given the format cannot be recognised an exception will be raised:
27+
28+
```python
29+
>>> docstring_to_markdown.convert('\\sum')
30+
UnknownFormatError()
31+
```
32+
33+
### Development
34+
35+
```bash
36+
pip install -e .
37+
pytest
38+
```

docstring_to_markdown/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from .rst import looks_like_rst, rst_to_markdown
2+
3+
4+
class UnknownFormatError(Exception):
5+
pass
6+
7+
8+
def convert(docstring: str) -> str:
9+
if looks_like_rst(docstring):
10+
return rst_to_markdown(docstring)
11+
raise UnknownFormatError()

0 commit comments

Comments
 (0)