|
| 1 | +# Configuration |
| 2 | + |
| 3 | +This page lists the available configuration options and what they achieve. |
| 4 | + |
| 5 | +[](){#setting-options} |
| 6 | +## `options` |
| 7 | + |
| 8 | +You can specify a few configuration options under the `options` key: |
| 9 | + |
| 10 | +```yaml title="mkdocs.yml" |
| 11 | +plugins: |
| 12 | +- mkdocstrings: |
| 13 | + handlers: |
| 14 | + shell: |
| 15 | + options: |
| 16 | + # some configuration |
| 17 | +``` |
| 18 | + |
| 19 | +[](){#option-extra} |
| 20 | +### `extra` |
| 21 | + |
| 22 | +- **:octicons-package-24: Type [`dict`][] :material-equal: `{}`{ title="default value" }** |
| 23 | + |
| 24 | +The `extra` option lets you inject additional variables into the Jinja context used when rendering templates. You can then use this extra context in your [overridden templates](https://mkdocstrings.github.io/usage/theming/#templates). |
| 25 | + |
| 26 | +Local `extra` options will be merged into the global `extra` option: |
| 27 | + |
| 28 | +```yaml title="in mkdocs.yml (global configuration)" |
| 29 | +plugins: |
| 30 | +- mkdocstrings: |
| 31 | + handlers: |
| 32 | + shell: |
| 33 | + options: |
| 34 | + extra: |
| 35 | + hello: world |
| 36 | +``` |
| 37 | +
|
| 38 | +```md title="in docs/some_page.md (local configuration)" |
| 39 | +::: your_package.your_module.your_func |
| 40 | + handler: shell |
| 41 | + options: |
| 42 | + extra: |
| 43 | + foo: bar |
| 44 | +``` |
| 45 | +
|
| 46 | +...will inject both `hello` and `foo` into the Jinja context when rendering `your_package.your_module.your_func`. |
| 47 | + |
| 48 | +[](){#option-heading_level} |
| 49 | +### `heading_level` |
| 50 | + |
| 51 | +- **:octicons-package-24: Type [`int`][] :material-equal: `2`{ title="default value" }** |
| 52 | + |
| 53 | +The initial heading level to use. |
| 54 | + |
| 55 | +When injecting documentation for an object, |
| 56 | +the object itself and its members are rendered. |
| 57 | +For each layer of objects, we increase the heading level by 1. |
| 58 | + |
| 59 | +The initial heading level will be used for the first layer. |
| 60 | +If you set it to 3, then headings will start with `<h3>`. |
| 61 | + |
| 62 | +If the [heading for the root object][show_root_heading] is not shown, |
| 63 | +then the initial heading level is used for its members. |
| 64 | + |
| 65 | +```yaml title="in mkdocs.yml (global configuration)" |
| 66 | +plugins: |
| 67 | +- mkdocstrings: |
| 68 | + handlers: |
| 69 | + shell: |
| 70 | + options: |
| 71 | + heading_level: 2 |
| 72 | +``` |
| 73 | + |
| 74 | +```md title="or in docs/some_page.md (local configuration)" |
| 75 | +::: path.to.module |
| 76 | + handler: shell |
| 77 | + options: |
| 78 | + heading_level: 3 |
| 79 | +``` |
| 80 | + |
| 81 | +/// admonition | Preview |
| 82 | + type: preview |
| 83 | + |
| 84 | +//// tab | With level 3 and root heading |
| 85 | +<h3><code>module</code> (3)</h3> |
| 86 | +<p>Docstring of the module.</p> |
| 87 | +<h4><code>ClassA</code> (4)</h4> |
| 88 | +<p>Docstring of class A.</p> |
| 89 | +<h4><code>ClassB</code> (4)</h4> |
| 90 | +<p>Docstring of class B.</p> |
| 91 | +<h5><code>method_1</code> (5)</h5> |
| 92 | +<p>Docstring of the method.</p> |
| 93 | +//// |
| 94 | + |
| 95 | +//// tab | With level 3, without root heading |
| 96 | +<p>Docstring of the module.</p> |
| 97 | +<h3><code>ClassA</code> (3)</h3> |
| 98 | +<p>Docstring of class A.</p> |
| 99 | +<h3><code>ClassB</code> (3)</h3> |
| 100 | +<p>Docstring of class B.</p> |
| 101 | +<h4><code>method_1</code> (4)</h4> |
| 102 | +<p>Docstring of the method.</p> |
| 103 | +//// |
| 104 | +/// |
| 105 | + |
| 106 | +[](){#option-show_root_heading} |
| 107 | +### `show_root_heading` |
| 108 | + |
| 109 | +- **:octicons-package-24: Type [`bool`][] :material-equal: `False`{ title="default value" }** |
| 110 | + |
| 111 | +Show the heading of the object at the root of the documentation tree |
| 112 | +(i.e. the object referenced by the identifier after `:::`). |
| 113 | + |
| 114 | +While this option defaults to false for backwards compatibility, we recommend setting it to true. Note that the heading of the root object can be a level 1 heading (the first on the page): |
| 115 | + |
| 116 | +```md |
| 117 | +# ::: path.to.object |
| 118 | +``` |
| 119 | + |
| 120 | +```yaml title="in mkdocs.yml (global configuration)" |
| 121 | +plugins: |
| 122 | +- mkdocstrings: |
| 123 | + handlers: |
| 124 | + shell: |
| 125 | + options: |
| 126 | + show_root_heading: false |
| 127 | +``` |
| 128 | + |
| 129 | +```md title="or in docs/some_page.md (local configuration)" |
| 130 | +::: path.to.Class |
| 131 | + handler: shell |
| 132 | + options: |
| 133 | + show_root_heading: true |
| 134 | +``` |
| 135 | + |
| 136 | +[](){#option-show_root_toc_entry} |
| 137 | +### `show_root_toc_entry` |
| 138 | + |
| 139 | +- **:octicons-package-24: Type [`bool`][] :material-equal: `True`{ title="default value" }** |
| 140 | +<!-- - **:octicons-project-template-24: Template :material-null:** (N/A) --> |
| 141 | + |
| 142 | +If the root heading is not shown, at least add a ToC entry for it. |
| 143 | + |
| 144 | +If you inject documentation for an object in the middle of a page, |
| 145 | +after long paragraphs, and without showing the [root heading][show_root_heading], |
| 146 | +then you will not be able to link to this particular object |
| 147 | +as it won't have a permalink and will be "lost" in the middle of text. |
| 148 | +In that case, it is useful to add a hidden anchor to the document, |
| 149 | +which will also appear in the table of contents. |
| 150 | + |
| 151 | +In other cases, you might want to disable the entry to avoid polluting the ToC. |
| 152 | +It is not possible to show the root heading *and* hide the ToC entry. |
| 153 | + |
| 154 | +```yaml title="in mkdocs.yml (global configuration)" |
| 155 | +plugins: |
| 156 | +- mkdocstrings: |
| 157 | + handlers: |
| 158 | + shell: |
| 159 | + options: |
| 160 | + show_root_heading: false |
| 161 | + show_root_toc_entry: true |
| 162 | +``` |
| 163 | + |
| 164 | +```md title="or in docs/some_page.md (local configuration)" |
| 165 | +## Some heading |
| 166 | +
|
| 167 | +Lots of text. |
| 168 | +
|
| 169 | +::: path.to.object |
| 170 | + handler: shell |
| 171 | + options: |
| 172 | + show_root_heading: false |
| 173 | + show_root_toc_entry: false |
| 174 | +
|
| 175 | +## Other heading. |
| 176 | +
|
| 177 | +More text. |
| 178 | +``` |
| 179 | + |
| 180 | +/// admonition | Preview |
| 181 | + type: preview |
| 182 | + |
| 183 | +//// tab | With ToC entry |
| 184 | +**Table of contents**<br> |
| 185 | +[Some heading](#permalink-to-some-heading){ title="#permalink-to-some-heading" }<br> |
| 186 | +[`object`](#permalink-to-object){ title="#permalink-to-object" }<br> |
| 187 | +[Other heading](#permalink-to-other-heading){ title="#permalink-to-other-heading" } |
| 188 | +//// |
| 189 | + |
| 190 | +//// tab | Without ToC entry |
| 191 | +**Table of contents**<br> |
| 192 | +[Some heading](#permalink-to-some-heading){ title="#permalink-to-some-heading" }<br> |
| 193 | +[Other heading](#permalink-to-other-heading){ title="#permalink-to-other-heading" } |
| 194 | +//// |
| 195 | +/// |
0 commit comments