|
1 | 1 | # Sphinx Tree View |
2 | 2 |
|
3 | | -A lightweight Sphinx extension that provides a customizable tree view for documentation. |
4 | | -A tree view can have an associated decorator type, which can be used to add custom icons to the tree view. |
5 | | -By default, the extension provides a decorator type "dir" with file and folder icons. |
| 3 | +<!-- start-include-here --> |
| 4 | + |
| 5 | +A lightweight Sphinx extension that provides a customizable, filesystem-like tree view for your documentation. |
6 | 6 |
|
7 | 7 | ## Installation |
8 | 8 |
|
| 9 | +Install the extension via PyPI: |
| 10 | + |
9 | 11 | ```sh |
10 | 12 | pip install sphinx-treeview |
11 | 13 | ``` |
12 | 14 |
|
13 | | -## Basic Usage |
14 | | - |
15 | | -Add the extension to your Sphinx `conf.py`: |
| 15 | +Then, add it to the `extensions` list in your `conf.py`: |
16 | 16 |
|
17 | 17 | ```python |
18 | | -extensions = [ |
19 | | - 'sphinx_treeview' |
20 | | -] |
21 | | -``` |
22 | | - |
23 | | -Use the directive in your RST files: |
24 | | - |
25 | | -```rst |
26 | | -:::{treeview} |
27 | | -- {<decorator name>}`<icon1>` foo |
28 | | - - {<decorator name>}`<icon2>` bar |
29 | | -- <decorator>`<icon1>` baz |
30 | | -::: |
31 | | -``` |
32 | | - |
33 | | -For example, with the default decorator "dir": |
34 | | - |
35 | | -```rst |
36 | | -:::{treeview} |
37 | | -- {dir}`<folder>` folder |
38 | | - - {dir}`<file>` file.jpeg |
39 | | - - {dir}`<file>` file.png |
40 | | -::: |
| 18 | +extensions = ["sphinx_treeview"] |
41 | 19 | ``` |
42 | 20 |
|
43 | | -The rendered tree view will look like this: |
44 | | - |
45 | | - |
46 | | - |
47 | | -## Configuration Options |
48 | | - |
49 | | -The following options can be configured in your `conf.py`: |
| 21 | +If you are using [MyST Parser](https://github.com/executablebooks/myst-parser) to write Markdown documentation, it’s recommended to enable the `colon_fence` syntax extension: |
50 | 22 |
|
51 | 23 | ```python |
52 | | -# Add custom decorators |
53 | | -stv_decorators = [ |
54 | | - DecoratorType(name="custom", icons=[DecoratorIcon(path="path/to/icon.svg", sphinx_static_path="icon/path/for/sphinx/", width=1.3, height=1.3, css_properties={...})]) |
55 | | -] |
56 | | - |
57 | | -# Disable default decorators (dir decorator) |
58 | | -stv_disable_default_decorators = False |
| 24 | +extensions = ["myst_parser", "sphinx_treeview"] |
| 25 | +myst_enable_extensions = ["colon_fence"] |
59 | 26 | ``` |
60 | 27 |
|
61 | | -A decorator icon is defined by a `path` to the icon file, and the path where the icon will be copied to in the Sphinx static folder. |
62 | | -This second path is used in the CSS to load the icon. |
63 | | -`width` and `height` are the dimensions of the icon in `em`, and `css_properties` is a dictionary of CSS properties to be applied to the icon. |
64 | | -The name used for the icon in the tree view is the name of the icon file without the extension. |
| 28 | +<!-- end-include-here --> |
65 | 29 |
|
66 | | -If you want to load all images of a folder as icons, you can use the `imagesToDecoratorIcons` function: |
| 30 | +## Example |
67 | 31 |
|
68 | | -```python |
69 | | -icons = imagesToDecoratorIcons(path="path/to/folder", sphinx_static_path="path/to/sphinx/folder") |
70 | | -``` |
| 32 | + |
71 | 33 |
|
72 | | -By default, the dimensions of the icons are 1.3em × 1.3em. |
| 34 | +```md |
| 35 | +:::{treeview} |
| 36 | +- {dir}`folder` folder |
| 37 | + - {dir}`file` file.jpeg |
| 38 | + - {dir}`file` file.png |
| 39 | +::: |
| 40 | +``` |
73 | 41 |
|
74 | 42 | # License |
75 | 43 |
|
76 | 44 | This project is licensed under the MPL-2.0 License. See the [LICENSE](LICENSE) file for details. |
77 | | -Images came from [pictogrammers](https://pictogrammers.com/library/mdi/) and are under [Apache-2.0 License](https://pictogrammers.com/docs/general/license/). |
| 45 | +Images came from [pictogrammers](https://pictogrammers.com/library/mdi/) and are under [Apache-2.0 License](https://pictogrammers.com/docs/general/license/). |
0 commit comments