sphinx-d2lang/README.md

84 lines
900 B
Markdown
Raw Normal View History

2023-12-11 16:11:48 +01:00
# sphinxcontrib-d2lang
2023-12-09 22:12:11 +01:00
2023-12-11 16:11:48 +01:00
This is a Sphinx extension fori [d2lang](https://d2lang.com/).
2023-12-09 22:12:11 +01:00
2023-12-11 16:11:48 +01:00
## Usage
2023-12-09 22:12:11 +01:00
2023-12-11 16:11:48 +01:00
### Install
2023-12-09 22:12:11 +01:00
2023-12-11 16:11:48 +01:00
```bash
$ pip install sphinxcontrib-d2lang
```
2023-12-09 22:12:11 +01:00
2023-12-11 16:11:48 +01:00
### Adding the extension
2023-12-09 22:12:11 +01:00
2023-12-11 16:11:48 +01:00
`conf.py`
2023-12-09 22:12:11 +01:00
2023-12-11 16:13:04 +01:00
```python
2023-12-11 16:11:48 +01:00
extensions = [
"sphinxcontrib.d2lang",
]
2023-12-09 22:12:11 +01:00
```
2023-12-11 16:11:48 +01:00
### Adding a diagram (inline)
2023-12-09 22:12:11 +01:00
2023-12-11 16:11:48 +01:00
You can use d2lang in sphinx directive
2023-12-09 22:12:11 +01:00
2023-12-11 16:42:33 +01:00
`source/index.rst`
2023-12-09 22:12:11 +01:00
2023-12-11 16:42:33 +01:00
```
2023-12-11 16:11:48 +01:00
Hello World
===========
2023-12-09 22:12:11 +01:00
2023-12-11 16:11:48 +01:00
.. d2lang::
2023-12-09 22:12:11 +01:00
2023-12-11 16:11:48 +01:00
hello -> world
```
2023-12-09 22:12:11 +01:00
2023-12-11 16:11:48 +01:00
### Adding a diagram (external file)
2023-12-09 22:12:11 +01:00
2023-12-11 16:11:48 +01:00
You can use an external file like this
2023-12-09 22:12:11 +01:00
2023-12-11 16:42:33 +01:00
```
2023-12-11 16:11:48 +01:00
Hello World
===========
2023-12-09 22:12:11 +01:00
2023-12-11 16:11:48 +01:00
.. d2lang:: helloworld.d2
2023-12-09 22:12:11 +01:00
2023-12-11 16:11:48 +01:00
```
2023-12-09 22:12:11 +01:00
2023-12-11 16:11:48 +01:00
### Options
2023-12-09 22:12:11 +01:00
2023-12-11 16:11:48 +01:00
There is two options you can use
2023-12-09 22:12:11 +01:00
2023-12-11 16:11:48 +01:00
- layout
- filename
2023-12-09 22:12:11 +01:00
2023-12-11 16:11:48 +01:00
#### Layout engine
2023-12-09 22:12:11 +01:00
2023-12-11 16:11:48 +01:00
You can specify layout engine to use
2023-12-09 22:12:11 +01:00
2023-12-11 16:33:37 +01:00
```rest
2023-12-11 16:11:48 +01:00
Hello World
===========
2023-12-09 22:12:11 +01:00
2023-12-11 16:11:48 +01:00
.. d2lang::
:layout: elk
2023-12-09 22:12:11 +01:00
2023-12-11 16:11:48 +01:00
hello -> world
```
2023-12-09 22:12:11 +01:00
2023-12-11 16:11:48 +01:00
#### Output filename
2023-12-09 22:12:11 +01:00
2023-12-11 16:33:37 +01:00
```rest
2023-12-11 16:11:48 +01:00
Hello World
===========
2023-12-09 22:12:11 +01:00
2023-12-11 16:11:48 +01:00
.. d2lang::
:filename: d2lang_files/helloworld.svg
2023-12-09 22:12:11 +01:00
2023-12-11 16:11:48 +01:00
hello -> world
```
2023-12-09 22:12:11 +01:00