Skip to content

Commit 8c24aa7

Browse files
add support for diagrams
1 parent 8cccfe5 commit 8c24aa7

File tree

13 files changed

+1263
-0
lines changed

13 files changed

+1263
-0
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ listed in `Dockerfile` should be installed.
6565

6666
You will also need the [Hack](https://github.com/source-foundry/Hack) font by `source-foundry`.
6767

68+
To render diagrams you will need to have installed the relevant diagram library:
69+
70+
- mermaid: `npm install -g @mermaid-js/mermaid-cli`
71+
- graphviz: ([consult docs](https://graphviz.org/download/))
72+
6873
## Versions
6974

7075
Inara is versioned using [SemVer](https://semver.org). Docker

data/defaults/shared.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ metadata:
88
# cannot be overwritten in the paper YAML.
99
lang: 'en-US'
1010

11+
engine:
12+
dot: true
13+
plantuml: false
14+
asymptote: false
15+
mermaid: true
16+
tikz: false
17+
1118
resource-path:
1219
- '/usr/local/share/openjournals'
1320
- '.'
@@ -25,6 +32,10 @@ filters:
2532
path: time.lua
2633
- type: lua
2734
path: normalize-author-names.lua
35+
- type: lua
36+
path: substitute-in-format.lua
37+
- type: lua
38+
path: diagram.lua
2839

2940
# ERROR, WARNING, or INFO
3041
verbosity: INFO

data/filters/diagram.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../vendor/diagram-1.0.0/_extensions/diagram/diagram.lua

example/paper.md

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,120 @@ Rendered:
279279
gained as heat, $Q$, less the thermodynamic work, $W$, done by the
280280
system on its surroundings. $$\Delta U = Q - W$$
281281

282+
### Code examples
283+
284+
Code examples can be written in fenced code blocks and highlighted with the provided language.
285+
286+
For example:
287+
288+
````
289+
```python
290+
import shutil
291+
292+
def hello_world():
293+
# shutil.rmtree('/')
294+
# on second thought
295+
print('hello world')
296+
```
297+
````
298+
299+
creates:
300+
301+
```python
302+
import shutil
303+
304+
def hello_world():
305+
# shutil.rmtree('/')
306+
# on second thought
307+
print('hello world')
308+
```
309+
310+
### Diagrams
311+
312+
Diagrams[^diagrams] can be written within fenced code blocks using:
313+
314+
[^diagrams]: Thanks to the [pandoc-ext/diagram](https://github.com/pandoc-ext/diagram/tree/main) pandoc filter
315+
316+
- [`mermaid`](https://mermaid.js.org/)
317+
- `dot` ([graphviz](https://graphviz.org/))
318+
319+
See the linked documentation for more information on available diagram types and syntax, particularly with mermaid which is under active development.
320+
321+
For example, using mermaid:
322+
323+
```` markdown
324+
``` mermaid
325+
%%| label: open_review
326+
%%| caption: Open Software Review: a state diagram
327+
stateDiagram-v2
328+
direction LR
329+
Ship: Ship It
330+
[*] --> Code
331+
Code --> Compile
332+
Compile --> Bug
333+
Bug --> Cry
334+
Cry --> Code
335+
Bug --> YOLO
336+
YOLO --> Ship
337+
Ship --> [*]
338+
```
339+
````
340+
341+
Creates:
342+
343+
``` mermaid
344+
%%| label: open_source
345+
%%| caption: Open Source: a state diagram
346+
stateDiagram-v2
347+
direction LR
348+
Ship: Ship It
349+
[*] --> Code
350+
Code --> Compile
351+
Compile --> Bug
352+
Bug --> Cry
353+
Cry --> Code
354+
Bug --> YOLO
355+
YOLO --> Ship
356+
Ship --> [*]
357+
```
358+
359+
Similarly, with dot/graphviz:
360+
361+
````markdown
362+
``` dot
363+
digraph {
364+
rankdir=LR
365+
submit -> read
366+
subgraph cluster_review {
367+
label="review"
368+
read -> issue
369+
issue -> PR
370+
PR -> read
371+
}
372+
read -> lgtm
373+
lgtm -> thanks[label="say thanks"]
374+
thanks -> friends[label="make friends!"]
375+
}
376+
```
377+
````
378+
379+
Creates:
380+
381+
``` dot
382+
digraph {
383+
rankdir=LR
384+
submit -> read
385+
subgraph cluster_review {
386+
label="review"
387+
read -> issue
388+
issue -> PR
389+
PR -> read
390+
}
391+
read -> lgtm
392+
lgtm -> thanks[label="say thanks"]
393+
thanks -> friends[label="make friends!"]
394+
}
395+
```
282396

283397
# Article metadata
284398

vendor/diagram-1.0.0/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sample.html
2+
tmp-latex

vendor/diagram-1.0.0/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# diagram
2+
3+
The diagram filter is versioned using [Semantic Versioning][].
4+
5+
[Semantic Versioning]: https://semver.org/
6+
7+
## v1.0.0
8+
9+
Released 2023-05-22.
10+
11+
- First release of the Lua filter; may it live long and prosper.

vendor/diagram-1.0.0/LICENSE

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
MIT License
2+
3+
Copyright © 2019-2023 Albert Krewinkel
4+
Copyright © 2019 Thorsten Sommer
5+
Copyright © 2018 Florian Schätzig
6+
Copyright © 2018 John MacFarlane
7+
8+
Permission is hereby granted, free of charge, to any person obtaining a copy
9+
of this software and associated documentation files (the "Software"), to deal
10+
in the Software without restriction, including without limitation the rights
11+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
copies of the Software, and to permit persons to whom the Software is
13+
furnished to do so, subject to the following conditions:
14+
15+
The above copyright notice and this permission notice shall be included in all
16+
copies or substantial portions of the Software.
17+
18+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24+
SOFTWARE.

vendor/diagram-1.0.0/Makefile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FILTER_FILE := $(wildcard *.lua)
2+
PANDOC ?= pandoc
3+
DIFF ?= diff
4+
5+
.PHONY: test
6+
test: test-asymptote test-dot test-mermaid test-plantuml test-tikz \
7+
test-no-alt-or-caption
8+
9+
test-%: test/test-%.yaml test/input-%.md $(FILTER_FILE)
10+
@$(PANDOC) --defaults test/test-$*.yaml | \
11+
$(DIFF) test/expected-$*.html -
12+
13+
sample.html: sample.md diagram.lua
14+
@$(PANDOC) --self-contained \
15+
--lua-filter=diagram.lua \
16+
--metadata=pythonPath:"python3" \
17+
--metadata=title:"README" \
18+
--output=$@ $<
19+
20+
clean:
21+
@rm -f sample.html
22+
@rm -rf tmp-latex

0 commit comments

Comments
 (0)