Skip to content

Commit 50eba94

Browse files
authored
📚 DOCS: Add API documentation (#24)
1 parent 459afbb commit 50eba94

File tree

9 files changed

+95
-35
lines changed

9 files changed

+95
-35
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- run:
2424
name: Build docs to store
2525
command: |
26-
sphinx-build -b html docs/ docs/_build/html
26+
sphinx-build -nW --keep-going -b html docs/ docs/_build/html
2727
2828
- store_artifacts:
2929
path: docs/_build/html/

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,5 @@ apidoc/
137137
__pycache__/
138138
.ropeproject/
139139
*.egg-info/
140+
141+
docs/api/

docs/conf.py

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@
2727
# Add any Sphinx extension module names here, as strings. They can be
2828
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
2929
# ones.
30-
extensions = ["myst_nb", "sphinx_copybutton"]
30+
extensions = [
31+
"sphinx.ext.autodoc",
32+
"sphinx.ext.viewcode",
33+
"sphinx.ext.intersphinx",
34+
"myst_nb",
35+
"sphinx_copybutton",
36+
]
3137

3238
# Add any paths that contain templates here, relative to this directory.
3339
templates_path = ["_templates"]
@@ -55,4 +61,48 @@
5561
# Add any paths that contain custom static files (such as style sheets) here,
5662
# relative to this directory. They are copied after the builtin static files,
5763
# so a file named "default.css" will overwrite the builtin "default.css".
58-
html_static_path = ["_static"]
64+
# html_static_path = ["_static"]
65+
66+
67+
intersphinx_mapping = {
68+
"python": ("https://docs.python.org/3.7", None),
69+
}
70+
71+
72+
def run_apidoc(app):
73+
""" generate apidoc
74+
75+
See: https://github.com/rtfd/readthedocs.org/issues/1139
76+
"""
77+
import os
78+
import shutil
79+
import sphinx
80+
from sphinx.ext import apidoc
81+
82+
logger = sphinx.util.logging.getLogger(__name__)
83+
logger.info("running apidoc")
84+
# get correct paths
85+
this_folder = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
86+
api_folder = os.path.join(this_folder, "api")
87+
module_path = os.path.normpath(os.path.join(this_folder, "../"))
88+
ignore_paths = ["../setup.py", "../conftest.py", "../tests", "../benchmark_samples"]
89+
ignore_paths = [
90+
os.path.normpath(os.path.join(this_folder, p)) for p in ignore_paths
91+
]
92+
93+
if os.path.exists(api_folder):
94+
shutil.rmtree(api_folder)
95+
os.mkdir(api_folder)
96+
97+
argv = ["-M", "--separate", "-o", api_folder, module_path] + ignore_paths
98+
99+
apidoc.main(argv)
100+
101+
# we don't use this
102+
if os.path.exists(os.path.join(api_folder, "modules.rst")):
103+
os.remove(os.path.join(api_folder, "modules.rst"))
104+
105+
106+
def setup(app):
107+
"""Add functions to the Sphinx setup."""
108+
app.connect("builder-inited", run_apidoc)

docs/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
```
33

44
```{toctree}
5+
:maxdepth: 2
6+
57
using
68
architecture
79
development
810
security
11+
api/markdown_it
912
```

markdown_it/common/normalize_url.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ def unescape_normalize_uri(x):
6868

6969

7070
def normalizeLink(url):
71-
"""Normalize destination URLs in links::
71+
"""Normalize destination URLs in links
72+
73+
::
7274
7375
[label]: destination 'title'
7476
^^^^^^^^^^^
@@ -116,7 +118,9 @@ def unescape_unquote(x):
116118

117119

118120
def normalizeLinkText(link):
119-
"""Normalize autolink content::
121+
"""Normalize autolink content
122+
123+
::
120124
121125
<destination>
122126
~~~~~~~~~~~

markdown_it/common/utils.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,12 @@ def fromCodePoint(c):
114114

115115

116116
def replaceEntityPattern(match, name):
117-
"""
117+
"""Convert HTML entity patterns
118+
118119
::
119-
In [2]: from markdown_it import MarkdownIt
120-
...: md = MarkdownIt()
121-
...: md.render("![](https://www.google.com)")
122-
Out[2]: '<p><img src="https%3A//www.google.com" alt=""></p>\n'
120+
121+
https://www.google.com -> https%3A//www.google.com
122+
123123
"""
124124
code = 0
125125

@@ -275,12 +275,15 @@ def isPunctChar(ch):
275275
def isMdAsciiPunct(ch: str):
276276
"""Markdown ASCII punctuation characters.
277277
278-
!, ", #, $, %, &, ', (, ), *, +, ,, -, ., /, :, ;, <, =, >, ?, @, [, \\, ], ^, _, `, {, |, }, or ~
279-
http://spec.commonmark.org/0.15/#ascii-punctuation-character
278+
::
280279
281-
Don't confuse with unicode punctuation !!! It lacks some chars in ascii range.
280+
!, ", #, $, %, &, ', (, ), *, +, ,, -, ., /, :, ;, <, =, >, ?, @, [, \\, ], ^, _, `, {, |, }, or ~
282281
283-
"""
282+
See http://spec.commonmark.org/0.15/#ascii-punctuation-character
283+
284+
Don't confuse with unicode punctuation !!! It lacks some chars in ascii range.
285+
286+
""" # noqa: E501
284287
return ch in MD_ASCII_PUNCT
285288

286289

markdown_it/renderer.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,30 @@ class Renderer
1515
class RendererHTML:
1616
"""Contains render rules for tokens. Can be updated and extended.
1717
18-
##### Example
18+
Example:
1919
2020
Each rule is called as independent static function with fixed signature:
2121
22-
```python
23-
class Renderer:
24-
def token_type_name(self, tokens, idx, options, env) {
25-
# ...
26-
return renderedHTML
27-
```
22+
::
2823
29-
example:
24+
class Renderer:
25+
def token_type_name(self, tokens, idx, options, env) {
26+
# ...
27+
return renderedHTML
3028
31-
```python
32-
class CustomRenderer(RendererHTML):
33-
def strong_open(self, tokens, idx, options, env):
34-
return '<b>'
35-
def strong_close(self, tokens, idx, options, env):
36-
return '</b>'
29+
::
3730
38-
md = MarkdownIt(renderer=CustomRenderer)
31+
class CustomRenderer(RendererHTML):
32+
def strong_open(self, tokens, idx, options, env):
33+
return '<b>'
34+
def strong_close(self, tokens, idx, options, env):
35+
return '</b>'
3936
40-
result = md.render(...)
41-
```
37+
md = MarkdownIt(renderer=CustomRenderer)
4238
43-
See [source code](https://github.com/markdown-it/markdown-it/blob/master/lib/renderer.js)
39+
result = md.render(...)
40+
41+
See https://github.com/markdown-it/markdown-it/blob/master/lib/renderer.js
4442
for more details and examples.
4543
"""
4644

markdown_it/rules_inline/text_collapse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def text_collapse(state: StateInline, *args):
66
Clean up tokens after emphasis and strikethrough postprocessing:
77
merge adjacent text nodes into one and re-calculate all token levels
88
9-
This is necessary because initially emphasis delimiter markers (*, _, ~)
9+
This is necessary because initially emphasis delimiter markers (``*, _, ~``)
1010
are treated as their own separate text tokens. Then emphasis rule either
1111
leaves them as text (needed to merge with adjacent text) or turns them
1212
into opening/closing tags (which messes up levels inside).

markdown_it/token.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ def as_dict(self, children=True, filter=None, dict_factory=dict):
8787
"""Return the token as a dict.
8888
8989
:param bool children: Also convert children to dicts
90-
:param callable filter: A callable whose return code determines whether an
90+
:param filter: A callable whose return code determines whether an
9191
attribute or element is included (``True``) or dropped (``False``). Is
9292
called with the `attr.Attribute` as the first argument and the
9393
value as the second argument.
94-
:param callable dict_factory: A callable to produce dictionaries from. For
94+
:param dict_factory: A callable to produce dictionaries from. For
9595
example, to produce ordered dictionaries instead of normal Python
9696
dictionaries, pass in ``collections.OrderedDict``.
9797

0 commit comments

Comments
 (0)