Skip to content

Commit d00f8d9

Browse files
committed
support drawio
1 parent 07ab587 commit d00f8d9

File tree

5 files changed

+97
-12
lines changed

5 files changed

+97
-12
lines changed

Dockerfile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,17 @@ RUN tlmgr update --self && tlmgr install \
196196
zref
197197

198198
RUN apt install -y \
199-
imagemagick
199+
dbus \
200+
imagemagick \
201+
libxss1 \
202+
openbox \
203+
wget \
204+
xorg \
205+
xvfb
206+
207+
RUN wget https://github.com/jgraph/drawio-desktop/releases/download/v23.0.2/drawio-amd64-23.0.2.deb && \
208+
dpkg -i drawio-amd64-23.0.2.deb && \
209+
rm drawio-amd64-23.0.2.deb
200210

201211
# https://stackoverflow.com/questions/52998331/imagemagick-security-policy-pdf-blocking-conversion
202212
RUN sed -i '/disable ghostscript format types/,+6d' /etc/ImageMagick-6/policy.xml
@@ -208,6 +218,7 @@ COPY ./filter/* /resources/filters/
208218
# mktexpk gets executed and needs a home dir, build one
209219
RUN mkdir -m 0777 /home/user
210220
ENV HOME="/home/user"
221+
ENV DBUS_SESSION_BUS_ADDRESS="unix:path=/var/run/dbus/system_bus_socket"
211222

212223
COPY ./filter/pandoc-crossref.yaml /home/user/.pandoc-crossref/config.yaml
213224

build.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ pdflog_output=""
1212
table_rules="no"
1313
block_quotes_are_informative_text="no"
1414

15+
# Start up the dbus daemon (drawio will use it later)
16+
dbus-daemon --system || echo "Failed to start dbus daemon"
17+
1518
# Setup an EXIT handler
1619
on_exit() {
1720
if [[ "${is_tmp}" == "yes" && -e "${build_dir}" ]]; then
@@ -321,10 +324,12 @@ cp "${input_file}" "${build_dir}/${input_file}"
321324
# \newpage is rendered as the string "\newpage" in GitHub markdown.
322325
# Transform horizontal rules into \newpages.
323326
# Exception: the YAML front matter of the document, so undo the instance on the first line.
327+
# TODO: Turn this into a Pandoc filter.
324328
sed -i.bak 's/^---$/\\newpage/g;1s/\\newpage/---/g' "${build_dir}/${input_file}"
325329

326330
# Transform sections before the table of contents into section*, which does not number them.
327331
# While we're doing this, transform the case to all-caps.
332+
# TODO: Turn this into a Pandoc filter.
328333
sed -i.bak '0,/\\tableofcontents/s/^# \(.*\)/\\section*\{\U\1\}/g' "${build_dir}/${input_file}"
329334

330335
if test "${do_gitversion}" == "yes"; then

filter/convert-images.lua

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
11
-- Convert a variety of image formats to PDF
22

3+
4+
-- Wrap calls to drawio in xvfb-run. Note that --no-sandbox has to be the last argument.
5+
-- https://github.com/jgraph/drawio-desktop/issues/249
6+
function drawio(source, dest)
7+
if not os.execute(string.format("xvfb-run -a drawio -x -f pdf -o %s %s --no-sandbox", dest, source)) then
8+
print(string.format('failed to convert %s to %s using drawio, falling back to letting latex try to pick it up', img.src, new_filename))
9+
return false
10+
end
11+
return true
12+
end
13+
14+
function imagemagick(source, dest)
15+
if not os.execute(string.format("convert -density 300 %s %s", source, dest)) then
16+
print(string.format('failed to convert %s to %s using imagemagick, falling back to letting latex try to pick it up', img.src, new_filename))
17+
return false
18+
end
19+
return true
20+
end
21+
22+
local converters = {
23+
['.jpg'] = imagemagick,
24+
['.png'] = imagemagick,
25+
['.svg'] = imagemagick,
26+
['.drawio'] = drawio
27+
}
28+
329
function string:hassuffix(suffix)
430
return self:sub(-#suffix) == suffix
531
end
@@ -9,15 +35,15 @@ if FORMAT:match 'latex' then
935
-- Try to convert anything that is not a pdf, jpg, or png.
1036
-- This allows us to support file types that latex doesn't (e.g., SVG),
1137
-- as well as speed up the latex render iterations.
12-
if not img.src or img.src:hassuffix('pdf') or img.src:hassuffix('jpg') or img.src:hassuffix('png') then
13-
return img
14-
end
15-
local new_filename = pandoc.sha1(img.src) .. '.temp.pdf'
16-
if not os.execute(string.format("convert -density 300 %s %s", img.src, new_filename)) then
17-
print(string.format('failed to convert %s to %s, falling back to letting latex try to pick it up', img.src, new_filename))
18-
return img
38+
local file_ext = img.src:match("^.+(%..+)$")
39+
if file_ext and converters[file_ext] then
40+
local new_filename = pandoc.sha1(img.src) .. '.temp.pdf'
41+
if converters[file_ext](img.src, new_filename) then
42+
img.src = new_filename
43+
end
44+
else
45+
print(string.format("not converting %s (extension %s)", img.src, file_ext))
1946
end
20-
img.src = new_filename
2147
return img
2248
end
2349
end

guide.tcg

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -615,9 +615,6 @@ Host->>TPM: TPM2_Quote
615615
TPM->>Host: <quoted PCRs>
616616
```
617617

618-
Crossreferences to Mermaid diagrams are supported by providing both `caption`
619-
and `#fig:xxxxx` classes in curly braces.
620-
621618
### Flow Charts
622619

623620
Mermaid supports flow-charts like @fig:flowchart with the following notation:
@@ -640,6 +637,24 @@ graph TD;
640637
C-->D;
641638
```
642639

640+
Crossreferences to Mermaid diagrams are supported by providing both `caption`
641+
and `#fig:xxxxx` classes in curly braces.
642+
643+
## DrawIO Diagrams
644+
645+
Some diagrams can't easily be represented in (human-maintained) code.
646+
647+
[Draw.io](https://app.diagrams.net/) is a tool for creating sophisticated
648+
diagrams. There is a Visual Studio Code extension for it.
649+
650+
Check in and add draw.io diagrams to your document like in @fig:sample-drawio:
651+
652+
```md
653+
![Sample DrawIO Diagram](sample.drawio){#fig:sample-drawio width=50%}
654+
```
655+
656+
![Sample DrawIO Diagram](sample.drawio){#fig:sample-drawio width=50%}
657+
643658
# Tables {#sec:tables}
644659

645660
We support several notation styles for tables.

sample.drawio

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<mxfile host="65bd71144e">
2+
<diagram id="ZsT7yVSXCH5zRSQvvg-b" name="Page-1">
3+
<mxGraphModel dx="1441" dy="1380" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="0" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0">
4+
<root>
5+
<mxCell id="0"/>
6+
<mxCell id="1" parent="0"/>
7+
<mxCell id="2" value="Process?" style="shape=process;whiteSpace=wrap;html=1;backgroundOutline=1;" vertex="1" parent="1">
8+
<mxGeometry x="20" y="150" width="120" height="60" as="geometry"/>
9+
</mxCell>
10+
<mxCell id="3" value="&lt;b&gt;DB&lt;/b&gt;" style="shape=cylinder3;whiteSpace=wrap;html=1;boundedLbl=1;backgroundOutline=1;size=15;" vertex="1" parent="1">
11+
<mxGeometry x="190" y="140" width="60" height="80" as="geometry"/>
12+
</mxCell>
13+
<mxCell id="4" value="" style="endArrow=classic;startArrow=classic;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;entryPerimeter=0;" edge="1" parent="1" source="2" target="3">
14+
<mxGeometry width="50" height="50" relative="1" as="geometry">
15+
<mxPoint x="350" y="500" as="sourcePoint"/>
16+
<mxPoint x="400" y="450" as="targetPoint"/>
17+
</mxGeometry>
18+
</mxCell>
19+
<mxCell id="5" value="Test&lt;br&gt;&lt;ol&gt;&lt;li&gt;One&lt;/li&gt;&lt;li&gt;Two&lt;/li&gt;&lt;li&gt;Three&lt;/li&gt;&lt;/ol&gt;" style="whiteSpace=wrap;html=1;aspect=fixed;" vertex="1" parent="1">
20+
<mxGeometry x="30" y="-10" width="120" height="120" as="geometry"/>
21+
</mxCell>
22+
<mxCell id="7" value="Text" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="1">
23+
<mxGeometry x="170" y="50" width="50" height="30" as="geometry"/>
24+
</mxCell>
25+
</root>
26+
</mxGraphModel>
27+
</diagram>
28+
</mxfile>

0 commit comments

Comments
 (0)