Skip to content

Add support for PlantUML diagrams #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ data/defaults.yaml
data/csl.json
data/annex-f
deps/pandoc
deps/plantuml
deps/python
plantuml-images
23 changes: 19 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ override PANDOC_VER := $(shell cat $(DEPSDIR)/pandoc.ver)
override PANDOC_DIR := $(DEPSDIR)/pandoc/$(PANDOC_VER)
override PYTHON_DIR := $(DEPSDIR)/python
override PYTHON_BIN := $(PYTHON_DIR)/bin/python3
override PLANTUML_DIR := $(DEPSDIR)/plantuml
override PLANTUML_BIN := java -jar $(PLANTUML_DIR)/plantuml.jar

export SHELL := bash
export PATH := $(PANDOC_DIR):$(PYTHON_DIR)/bin:$(PATH)
export PATH := $(PANDOC_DIR):$(PYTHON_DIR)/bin:$(PLANTUML_DIR):$(PATH)
export PLANTUML_BIN := $(PLANTUML_BIN)

override DEPS := $(PANDOC_DIR) $(PYTHON_DIR)
override DEPS := $(PANDOC_DIR) $(PLANTUML_DIR) $(PYTHON_DIR)

override DATADIR := $(ROOTDIR)data

Expand Down Expand Up @@ -56,12 +59,16 @@ pdf: $(PDF)
ifneq ($(SRCDIR), $(OUTDIR))
.PHONY: clean
clean:
rm -rf $(DEPSDIR)/pandoc $(DEPS) $(OUTDIR)
rm -rf $(DEPSDIR)/pandoc $(DEPS) $(OUTDIR) plantuml-images

.PHONY: $(HTML) $(LATEX) $(PDF)
$(HTML) $(LATEX) $(PDF): $(SRCDIR)/%: $(OUTDIR)/%
endif

.PHONY: update-dependencies
update-dependencies:
@$(MAKE) --always-make $(DEPS)

.PHONY: update
update:
@$(MAKE) --always-make $(DATADIR)/csl.json $(DATADIR)/annex-f
Expand All @@ -72,6 +79,11 @@ $(OUTDIR):
$(PANDOC_DIR):
PANDOC_VER=$(PANDOC_VER) PANDOC_DIR=$@ $(DEPSDIR)/install-pandoc.sh

$(PLANTUML_DIR):
mkdir -p $@
curl -L -o $@/plantuml.jar https://github.com/plantuml/plantuml/releases/latest/download/plantuml.jar
chmod -R u+x $@

$(PYTHON_DIR): $(DEPSDIR)/requirements.txt
python3 -m venv $(PYTHON_DIR)
$@/bin/pip3 install --upgrade pip -r $<
Expand All @@ -86,5 +98,8 @@ $(DATADIR)/csl.json: $(DATADIR)/refs.py $(PYTHON_DIR)
$(DATADIR)/annex-f:
curl -sSL https://timsong-cpp.github.io/cppwp/annex-f -o $@

$(OUTDIR)/%.html $(OUTDIR)/%.latex $(OUTDIR)/%.pdf: $(SRCDIR)/%.md $(DEPS) | $(OUTDIR)
plantuml-images/%.svg plantuml-images/%.tex plantuml-images/%.png: plantuml-images/%.uml $(DEPS) | plantuml-images
$(PANDOC) --bibliography $(DATADIR)/csl.json

$(OUTDIR)/%.html $(OUTDIR)/%.latex $(OUTDIR)/%.pdf : $(SRCDIR)/%.md $(DEPS) | $(OUTDIR)
$(PANDOC) --bibliography $(DATADIR)/csl.json
54 changes: 52 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,51 @@ inspect (x) {

![](img/cmptable-3.png)

### PlantUML Diagrams

PlantUML diagrams are supported as code-blocks.

``````md
```plantuml
title Omits Connect & Start
caption sequence diagram for set_next()
autonumber
hide footbox
participant consumer as cnm
participant producer as pdc
participant transformer as trn
activate cnm
group connect/start sequence
activate trn
activate pdc
end
loop values 0..N
pdc --> trn : processValN = set_next(produceValN)
activate pdc
activate trn
trn --> cnm : consumeValN = set_next(transformValN)
activate cnm
group connect/start valueN
end
pdc --> trn : set_value(transformValNRcvr, ValN...)
trn --> cnm : set_value(consumeValNRcvr, transformValN...)
cnm --> pdc : set_value(produceValN+1Rcvr)
deactivate pdc
deactivate trn
deactivate cnm
end
group end sequence
pdc --> trn : set_value(transformRcvr)
trn --> cnm : set_value(consumeRcvr)
deactivate pdc
deactivate trn
end
deactivate cnm
```
``````

![](img/plantuml.png)

### Proposed Wording

#### Paragraph Numbers
Expand Down Expand Up @@ -458,17 +503,22 @@ If you want the list of available fonts on your system, most supported systems w

- `python3`
- `xelatex`
- `plantuml`

### OS X

```bash
brew cask install mactex
brew install --cask mactex
```

```bash
brew install plantuml
```

### Ubuntu

```bash
sudo apt-get install texlive-latex-base
sudo apt-get install texlive-latex-base plantuml
```

### Debian
Expand Down
1 change: 1 addition & 0 deletions data/defaults.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ data-dir: ${DATADIR}
filters:
- citeproc
- wg21.py
- pandoc_plantuml_filter.py

template: wg21

Expand Down
62 changes: 62 additions & 0 deletions data/filters/pandoc_plantuml_filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env python

from __future__ import print_function

"""
Pandoc filter to process code blocks with class "plantuml" into
plant-generated images.
Needs `plantuml.jar` from http://plantuml.com/.
"""

import os
import sys
import subprocess
import re

from pandocfilters import toJSONFilter, Para, Image, RawBlock
from pandocfilters import get_filename4code, get_caption, get_extension

PLANTUML_BIN = os.environ.get('PLANTUML_BIN', 'plantuml')

pattern = re.compile('%{(.*)\}$')

def plantuml(key, value, format_, meta):

if key == 'CodeBlock':
if os.getenv("DEBUG", "f").lower() in ("1", "true"):
print("plantuml", key, value, format_, meta)

[[ident, classes, keyvals], code] = value

if "plantuml" in classes:
caption, typef, keyvals = get_caption(keyvals)

filename = get_filename4code("plantuml", code)
filetype = get_extension(format_, "png", html="svg", latex="tex", beamer="tex")
outputtype = filetype
if filetype.startswith("tex"):
outputtype = "latex:nopreamble"

src = filename + '.uml'
dest = filename + '.' + filetype

if not os.path.isfile(dest):
txt = code.encode(sys.getfilesystemencoding())
if not txt.startswith(b"@start"):
txt = b"@startuml\n" + txt + b"\n@enduml\n"
with open(src, "wb") as f:
f.write(txt)
subprocess.check_call(PLANTUML_BIN.split() + ["-t" + outputtype, src])
sys.stderr.write('Created image ' + dest + '\n')
if outputtype.startswith("latex:nopreamble"):
latex = open(dest).read()
return RawBlock('latex', "\\begin{adjustbox}{max width=\\textwidth, max height=\\textheight}\n" + latex + "\n\\end{adjustbox}\n")
else:
return Para([Image([ident, [], keyvals], caption, [dest, typef])])

def main():
toJSONFilter(plantuml)


if __name__ == "__main__":
main()
5 changes: 4 additions & 1 deletion data/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ header-includes:
```{=latex}
% adjust quote indent
\renewenvironment{quote}{\list{}{\leftmargin=0.2in}\item[]}{\endlist}
\providecommand{\CSLBlock}[1]{#1\hfill\break}
\renewcommand{\CSLBlock}[1]{\hfill\break#1\hfill\break}

% https://github.com/cplusplus/draft/blob/97b615a5a6ab0598b624ee05402c531d0421cff6/source/styles.tex#L127-L133
\renewcommand{\labelitemi}{---}
\renewcommand{\labelitemii}{---}
Expand All @@ -48,4 +48,7 @@ header-includes:
\hspace{\@totalleftmargin}\quad%
}}\ignorespaces}
\makeatother

\usepackage{tikz}
\usepackage{adjustbox}
```
8 changes: 8 additions & 0 deletions data/templates/wg21.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,23 @@ <h1 class="title" style="text-align:center">$title$</h1>
<h3 class="subtitle" style="text-align:center">$subtitle$</h3>
$endif$
<table style="border:none;float:right">
$if(document)$
<tr>
<td>Document #:</td>
<td>$document$</td>
</tr>
$endif$
<tr>
<td>Date:</td>
<td>$date$</td>
</tr>
$if(document)$
<tr>
<td style="vertical-align:top">Project:</td>
<td>Programming Language C++</td>
</tr>
$endif$
$if(audience)$
<tr>
<td style="vertical-align:top">Audience:</td>
<td>
Expand All @@ -80,12 +85,14 @@ <h3 class="subtitle" style="text-align:center">$subtitle$</h3>
$endfor$
</td>
</tr>
$endif$
$if(revises)$
<tr>
<td>Revises: </td>
<td>$revises$</td>
</tr>
$endif$
$if(author)$
<tr>
<td style="vertical-align:top">Reply-to:</td>
<td>
Expand All @@ -94,6 +101,7 @@ <h3 class="subtitle" style="text-align:center">$subtitle$</h3>
$endfor$
</td>
</tr>
$endif$
</table>
</header>
$endif$
Expand Down
8 changes: 8 additions & 0 deletions data/templates/wg21.latex
Original file line number Diff line number Diff line change
Expand Up @@ -415,14 +415,22 @@ $endif$
\vskip 1.5em
\begin{flushright}
\begin{tabular}{ll}
$if(document)$
Document \#:&$document$\\
$endif$
Date: &\@date\\
$if(document)$
Project: &Programming Language C++\\
$endif$
$if(audience)$
Audience: $for(audience)$&$audience$\\$endfor$
$endif$
$if(revises)$
Revises: &$revises$\\
$endif$
$if(author)$
Reply-to: \@author
$endif$
\end{tabular}
\end{flushright}
}
Expand Down
1 change: 1 addition & 0 deletions deps/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
panflute~=2.1.3
pandocfilters
beautifulsoup4
lxml
requests
Expand Down
Binary file added img/plantuml.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 52 additions & 0 deletions plantuml.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
title: "Asynchronous Value Sequences"
subtitle: "Draft Proposal"
document: D0000R0
date: today
audience:
- "SG1 - parallelism and concurrency"
author:
- name: Kirk Shoop
email: <kirk.shoop@gmail.com>
toc: true
---

Introduction
============

```plantuml
title Omits Connect & Start
caption sequence diagram for set_next()
autonumber
hide footbox
participant consumer as cnm
participant producer as pdc
participant transformer as trn
activate cnm
group connect/start sequence
activate trn
activate pdc
end
loop values 0..N
pdc --> trn : processValN = set_next(produceValN)
activate pdc
activate trn
trn --> cnm : consumeValN = set_next(transformValN)
activate cnm
group connect/start valueN
end
pdc --> trn : set_value(transformValNRcvr, ValN...)
trn --> cnm : set_value(consumeValNRcvr, transformValN...)
cnm --> pdc : set_value(produceValN+1Rcvr)
deactivate pdc
deactivate trn
deactivate cnm
end
group end sequence
pdc --> trn : set_value(transformRcvr)
trn --> cnm : set_value(consumeRcvr)
deactivate pdc
deactivate trn
end
deactivate cnm
```