Debian Codegraph @

docs/troubleshooting.md

raw
1 # Troubleshooting
2
3 ## Code blocks in admonitions (in docstrings or else) are not rendered correctly
4
5 To render code blocks in admonitions, you need to add the `pymdownx.superfences` extensions to the list of
6 Markdown extensions in `mkdocs.yml`. For example:
7
8 ```markdown
9 !!! note
10 Some text.
11
12 ```bash
13 echo "some code"
14 ```
15 ```
16
17 ```yaml title="mkdocs.yml"
18 markdown_extensions:
19 - admonition
20 - codehilite
21 - pymdownx.superfences
22 ```
23
24 For code blocks in docstrings, make sure to escape newlines (`\n` -> `\\n`),
25 or prefix the entire docstring with 'r' to make it a raw-docstring: `r"""`.
26 Indeed, docstrings are still strings and therefore subject to how Python parses strings.
27
28 ## Footnotes are duplicated or overridden
29
30 Before version 0.14, footnotes could be duplicated over a page.
31 Please upgrade to version 0.14 or higher.
32
33 See also:
34
35 - [Issue #186](https://github.com/mkdocstrings/mkdocstrings/issues/186)
36 - [Tabs in docstrings (from `pymdownx.tabbed`) are not working properly](#tabs-in-docstrings-from-pymdownxtabbed-are-not-working-properly).
37
38 ## MkDocs warns me about links to unfound documentation files
39
40 A warning like this one:
41
42 > WARNING - Documentation file 'reference/parsers/docstrings.md'
43 contains a link to 'reference/parsers/pytkdocs.parsers.docstrings.Section'
44 which is not found in the documentation files.
45
46 ...generally means you used parentheses `()` instead of brackets `[]` for a cross-reference.
47 Notice the dots in `reference/parsers/pytkdocs.parsers.docstrings.Section`?
48 It shows that it's probably a cross-reference, not a direct link.
49 It's probably written like `[Section](pytkdocs.parsers.docstrings.Section)` in the docs,
50 when it should be `[Section][pytkdocs.parsers.docstrings.Section]`.
51
52 ## Some objects are not rendered (they do not appear in the generated docs)
53
54 - Make sure the configuration options of the handler are correct.
55 Check the documentation for [Handlers](usage/handlers.md) to see the available options for each handler.
56 - Also make sure your documentation in your source code is formatted correctly.
57 For Python code, check the [supported docstring styles](https://mkdocstrings.github.io/python/usage/#supported-docstrings-styles) page.
58 - Re-run the Mkdocs command with `-v`, and carefully read any traceback.
59
60 ## Tabs in docstrings (from `pymdownx.tabbed`) are not working properly
61
62 Before version 0.14, multiple tab blocks injected on the same page
63 would result in broken links: clicking on a tab would bring the user to the wrong one.
64 Please upgrade to version 0.14 or higher.
65
66 See also:
67
68 - [Issue #193](https://github.com/mkdocstrings/mkdocstrings/issues/193)
69 - [Footnotes are duplicated or overridden](#footnotes-are-duplicated-or-overridden).
70
71 If you are stuck on a version before 0.14,
72 and want to use multiple tab blocks in one page,
73 use this workaround.
74
75 ??? example "JavaScript workaround"
76
77 Put the following code in a .js file,
78 and list it in MkDocs' `extra_javascript`:
79
80 ```javascript
81 // Credits to Nikolaos Zioulis (@zuru on GitHub)
82 function setID(){
83 var tabs = document.getElementsByClassName("tabbed-set");
84 for (var i = 0; i < tabs.length; i++) {
85 children = tabs[i].children;
86 var counter = 0;
87 var iscontent = 0;
88 for(var j = 0; j < children.length;j++){
89 if(typeof children[j].htmlFor === 'undefined'){
90 if((iscontent + 1) % 2 == 0){
91 // check if it is content
92 if(iscontent == 1){
93 btn = children[j].childNodes[1].getElementsByTagName("button");
94 }
95 }
96 else{
97 // if not change the id
98 children[j].id = "__tabbed_" + String(i + 1) + "_" + String(counter + 1);
99 children[j].name = "__tabbed_" + String(i + 1);
100 // make default tab open
101 if(j == 0)
102 children[j].click();
103 }
104 iscontent++;
105 }
106 else{
107 // link to the correct tab
108 children[j].htmlFor = "__tabbed_" + String(i+1) + "_" + String(counter + 1);
109 counter ++;
110 }
111 }
112 }
113 }
114 setID();
115 ```
116
117 This code will correctly reset the IDs for tabs on a same page.
118
119 ## The generated documentation does not look good
120
121 Please open an ticket on the [bugtracker][bugtracker] with a detailed
122 explanation and screenshots of the bad-looking parts.
123 Note that you can always [customize the look](usage/theming.md) of *mkdocstrings* blocks -- through both HTML and CSS.
124
125 ## Warning: could not find cross-reference target
126
127 TIP: **New in version 0.15.**
128 Cross-linking used to include any Markdown heading, but now it's only for *mkdocstrings* identifiers by default.
129 See [Cross-references to any Markdown heading](usage/index.md#cross-references-to-any-markdown-heading) to opt back in.
130
131 Make sure the referenced object is properly rendered: verify your configuration options.
132
133 For false-positives, you can wrap the text in backticks (\`) to prevent `mkdocstrings` from trying to process it.
134
135 ---
136
137 ## Python specifics
138
139 ### Nothing is rendered at all
140
141 Is your package available in the Python path?
142
143 See [Python handler: Finding modules](https://mkdocstrings.github.io/python/usage/#finding-modules).
144
145 ### LaTeX in docstrings is not rendered correctly
146
147 If you are using a Markdown extension like
148 [Arithmatex Mathjax](https://squidfunk.github.io/mkdocs-material/setup/extensions/python-markdown-extensions/#arithmatex)
149 or [`markdown-katex`][markdown-katex] to render LaTeX,
150 add `r` in front of your docstring to make sure nothing is escaped.
151 You'll still maybe have to play with escaping to get things right.
152
153 Example:
154
155 ```python
156 def math_function(x, y):
157 r"""
158 Look at these formulas:
159
160 ```math
161 f(x) = \int_{-\infty}^\infty
162 \hat f(\xi)\,e^{2 \pi i \xi x}
163 \,d\xi
164 ```
165 """
166 ```
167
168 ### My docstrings in comments (`#:`) are not picked up
169
170 We only support docstrings in comments through the [griffe-sphinx](https://mkdocstrings.github.io/griffe-sphinx) extension.
171
172 Alternatively, instead of:
173
174 ```python
175 import enum
176
177
178 class MyEnum(enum.Enum):
179 v1 = 1 #: The first choice.
180 v2 = 2 #: The second choice.
181 ```
182
183 You can use:
184
185 ```python
186 import enum
187
188
189 class MyEnum(enum.Enum):
190 v1 = 1
191 """The first choice."""
192
193 v2 = 2
194 """The second choice."""
195 ```
196
197 Or:
198
199 ```python
200 import enum
201
202
203 class MyEnum(enum.Enum):
204 """My enum.
205
206 Attributes:
207 v1: The first choice.
208 v2: The second choice.
209 """
210
211 v1 = 1
212 v2 = 2
213 ```
214
215 ### My wrapped function shows documentation/code for its wrapper instead of its own
216
217 Use [`functools.wraps()`](https://docs.python.org/3.6/library/functools.html#functools.wraps):
218
219 ```python
220 from functools import wraps
221
222
223 def my_decorator(function):
224 """The decorator docs."""
225
226 @wraps(function)
227 def wrapped_function(*args, **kwargs):
228 print("hello")
229 function(*args, **kwargs)
230 print("bye")
231
232 return wrapped_function
233
234
235 @my_decorator
236 def my_function(*args, **kwargs):
237 """The function docs."""
238 print(*args, **kwargs)
239 ```
240
241 ### Footnotes do not render
242
243 The library that parses docstrings, [Griffe](https://mkdocstrings.github.io/griffe/), splits docstrings in several "sections" (example: [Google-style sections syntax](https://mkdocstrings.github.io/griffe/reference/docstrings/#google-syntax)). If a footnote is used in a section, while referenced in another, mkdocstrings won't be able to render it correctly. The footnote and its reference must appear in the same section.
244
245 ```python
246 def my_function():
247 """Summary.
248
249 This is the first section[^1].
250
251 Note:
252 This is the second section[^2].
253
254 Note:
255 This is the third section[^3].
256
257 References at the end are part of yet another section (fourth here)[^4].
258
259 [^1]: Some text.
260 [^2]: Some text.
261 [^3]: Some text.
262 [^4]: Some text.
263 """
264 ```
265
266 Here only the fourth footnote will work, because it is the only one that appear in the same section as its reference. To fix this, make sure all footnotes appear in the same section as their references:
267
268 ```python
269 def my_function():
270 """Summary.
271
272 This is the first section[^1].
273
274 [^1]: Some text.
275
276 Note:
277 This is the second section[^2].
278
279 [^2]: Some text.
280
281 Note:
282 This is the third section[^3].
283
284 [^3]: Some text.
285
286 References at the end are part of yet another section (fourth here)[^4].
287
288 [^4]: Some text.
289 """
290 ```
291
292 ### Submodules are not rendered
293
294 In previous versions of mkdocstrings-python, submodules were rendered by default. This was changed and you now need to set the following option:
295
296 ```yaml title="mkdocs.yml"
297 plugins:
298 - mkdocstrings:
299 handlers:
300 python:
301 options:
302 show_submodules: true
303 ```
304
305 [bugtracker]: https://github.com/mkdocstrings/mkdocstrings
306 [markdown-katex]: https://gitlab.com/mbarkhau/markdown-katex