Skip to content

Commit 750dee0

Browse files
authored
update to latest mermaid, remove workaround, fix crossrefs, and improve code font (#68)
1 parent 94ff128 commit 750dee0

File tree

4 files changed

+64
-50
lines changed

4 files changed

+64
-50
lines changed

Dockerfile

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,16 @@ RUN apk --no-cache add msttcorefonts-installer fontconfig && \
6767
RUN wget https://github.com/kaienfr/Font/raw/master/font/ARIALUNI.TTF -P /usr/share/fonts/TTF/ && \
6868
fc-cache -f
6969

70-
# Install Source Code Pro
71-
RUN wget https://github.com/adobe-fonts/source-code-pro/archive/refs/tags/2.042R-u/1.062R-i/1.026R-vf.zip && \
72-
unzip 1.026R-vf.zip && \
73-
cp source-code-pro-2.042R-u-1.062R-i-1.026R-vf/TTF/*.ttf /usr/share/fonts/TTF/ && \
70+
# Install Noto Sans Mono
71+
RUN apk --no-cache add font-noto && \
7472
fc-cache -f
7573

7674
RUN pip install pandocfilters
7775

7876
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \
7977
PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
8078

81-
RUN npm install --global --unsafe-perm [email protected] puppeteer@19.8.5 imgur@2.2.0 [email protected] typescript@5.0.4
79+
RUN npm install --global --unsafe-perm puppeteer@21.7.0 imgur@2.3.0 [email protected] typescript@5.3.3
8280

8381
# Install latest pandiff, which has not been released in a while
8482
# This pre-release build has --reference-doc support for docx output

build.sh

Lines changed: 50 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -243,25 +243,18 @@ if [ "${table_rules}" == "yes" ]; then
243243
extra_pandoc_options+=" --lua-filter=table-rules.lua"
244244
fi
245245

246-
# Transform 1
247-
# GitHub Mermaid doesn't recognize the full ```{.mermaid ...} attributes-form
248-
# Pandoc doesn't recognized mixed ```mermaid {...} form
249-
# Hack: use sed to transform the latter to the former so everyone is happy
250-
# Only transform if there is exactly one space after ```mermaid
251-
# Instructional documentation may use more than one space in the source code to suppress this.
252-
sed 's/```mermaid {/```{.mermaid /g' "${input_file}" > "${build_dir}/${input_file}.1"
253-
sed 's/```mermaid *{/```mermaid {/g' "${input_file}" > "${build_dir}/${input_file}.1"
254-
255-
# Transform 2
246+
cp "${input_file}" "${build_dir}/${input_file}"
247+
248+
# Hacks
249+
256250
# \newpage is rendered as the string "\newpage" in GitHub markdown.
257251
# Transform horizontal rules into \newpages.
258252
# Exception: the YAML front matter of the document, so undo the instance on the first line.
259-
sed 's/^---$/\\newpage/g;1s/\\newpage/---/g' "${build_dir}/${input_file}.1" > "${build_dir}/${input_file}.2"
253+
sed -i.bak 's/^---$/\\newpage/g;1s/\\newpage/---/g' "${build_dir}/${input_file}"
260254

261-
# Transform 3
262255
# Transform sections before the table of contents into section*, which does not number them.
263256
# While we're doing this, transform the case to all-caps.
264-
sed '0,/\\tableofcontents/s/^# \(.*\)/\\section*\{\U\1\}/g' "${build_dir}/${input_file}.2" > "${build_dir}/${input_file}.3"
257+
sed -i.bak '0,/\\tableofcontents/s/^# \(.*\)/\\section*\{\U\1\}/g' "${build_dir}/${input_file}"
265258

266259
if test "${do_gitversion}" == "yes"; then
267260
# If using the git information for versioning, grab the date from there
@@ -288,13 +281,21 @@ RESULT=0
288281
# Generate the pdf
289282
if [ -n "${pdf_output}" ]; then
290283
echo "Generating PDF Output"
284+
# workaround to make mermaid and crossref play nice together: https://github.com/raghur/mermaid-filter/issues/39#issuecomment-1703911386
291285
pandoc \
292-
--pdf-engine=lualatex \
286+
--filter=mermaid-filter \
287+
--standalone \
288+
--metadata=date:"${DATE}" \
289+
--metadata=date-english:"${DATE_ENGLISH}" \
290+
--metadata=year:"${YEAR}" \
291+
--from=markdown \
292+
"${build_dir}/${input_file}" \
293+
--to=markdown \
294+
| pandoc \
295+
--pdf-engine=lualatex \
293296
--embed-resources \
294297
--standalone \
295298
--template=eisvogel.latex \
296-
--filter=mermaid-filter \
297-
--lua-filter=center-images.lua \
298299
--lua-filter=parse-html.lua \
299300
--filter=pandoc-crossref \
300301
--lua-filter=divide-code-blocks.lua \
@@ -303,9 +304,6 @@ if [ -n "${pdf_output}" ]; then
303304
--top-level-division=section \
304305
--variable=block-headings \
305306
--variable=numbersections \
306-
--metadata=date:"${DATE}" \
307-
--metadata=date-english:"${DATE_ENGLISH}" \
308-
--metadata=year:"${YEAR}" \
309307
--metadata=titlepage:true \
310308
--metadata=titlepage-background:/resources/img/cover.png \
311309
--metadata=crossrefYaml:/resources/filters/pandoc-crossref.yaml \
@@ -316,7 +314,6 @@ if [ -n "${pdf_output}" ]; then
316314
--from=markdown+implicit_figures+grid_tables+table_captions-markdown_in_html_blocks \
317315
${extra_pandoc_options} \
318316
--to=pdf \
319-
"${build_dir}/${input_file}.3" \
320317
--output="${pdf_output}"
321318
echo "PDF Output Generated to file: ${pdf_output}"
322319
if [ $? -ne 0 ]; then
@@ -327,13 +324,21 @@ fi
327324
# Generate the LaTeX output
328325
if [ -n "${latex_output}" ]; then
329326
echo "Generating LaTeX Output"
327+
# workaround to make mermaid and crossref play nice together: https://github.com/raghur/mermaid-filter/issues/39#issuecomment-1703911386
330328
pandoc \
331-
--pdf-engine=lualatex \
329+
--filter=mermaid-filter \
330+
--standalone \
331+
--metadata=date:"${DATE}" \
332+
--metadata=date-english:"${DATE_ENGLISH}" \
333+
--metadata=year:"${YEAR}" \
334+
--from=markdown \
335+
"${build_dir}/${input_file}" \
336+
--to=markdown \
337+
| pandoc \
338+
--pdf-engine=lualatex \
332339
--embed-resources \
333340
--standalone \
334341
--template=eisvogel.latex \
335-
--filter=mermaid-filter \
336-
--lua-filter=center-images.lua \
337342
--lua-filter=parse-html.lua \
338343
--filter=pandoc-crossref \
339344
--lua-filter=divide-code-blocks.lua \
@@ -342,8 +347,6 @@ if [ -n "${latex_output}" ]; then
342347
--top-level-division=section \
343348
--variable=block-headings \
344349
--variable=numbersections \
345-
--metadata=date-english:"${DATE_ENGLISH}" \
346-
--metadata=year:"${YEAR}" \
347350
--metadata=titlepage:true \
348351
--metadata=titlepage-background:/resources/img/cover.png \
349352
--metadata=crossrefYaml:/resources/filters/pandoc-crossref.yaml \
@@ -354,7 +357,6 @@ if [ -n "${latex_output}" ]; then
354357
--from=markdown+implicit_figures+grid_tables+table_captions-markdown_in_html_blocks \
355358
${extra_pandoc_options} \
356359
--to=latex \
357-
"${build_dir}/${input_file}.3" \
358360
--output="${latex_output}"
359361
echo "LaTeX Output Generated to file: ${latex_output}"
360362
if [ $? -ne 0 ]; then
@@ -365,13 +367,21 @@ fi
365367
# Generate the docx output
366368
if [ -n "${docx_output}" ]; then
367369
echo "Generating DOCX Output"
370+
# workaround to make mermaid and crossref play nice together: https://github.com/raghur/mermaid-filter/issues/39#issuecomment-1703911386
368371
pandoc \
369-
--pdf-engine=lualatex \
372+
--filter=mermaid-filter \
373+
--standalone \
374+
--metadata=date:"${DATE}" \
375+
--metadata=date-english:"${DATE_ENGLISH}" \
376+
--metadata=year:"${YEAR}" \
377+
--from=markdown \
378+
"${build_dir}/${input_file}" \
379+
--to=markdown \
380+
| pandoc \
381+
--pdf-engine=lualatex \
370382
--embed-resources \
371383
--standalone \
372384
--filter=/resources/filters/info.py \
373-
--filter=mermaid-filter \
374-
--lua-filter=center-images.lua \
375385
--lua-filter=parse-html.lua \
376386
--filter=pandoc-crossref \
377387
--resource-path=.:/resources \
@@ -380,7 +390,6 @@ if [ -n "${docx_output}" ]; then
380390
--reference-doc=/resources/templates/tcg_template.docx \
381391
${extra_pandoc_options} \
382392
--to=docx \
383-
"${build_dir}/${input_file}.3" \
384393
--output="${docx_output}"
385394
echo "DOCX Output Generated to file: ${docx_output}"
386395
if [ $? -ne 0 ]; then
@@ -393,16 +402,24 @@ export MERMAID_FILTER_FORMAT="svg"
393402
# Generate the html output
394403
if [ -n "${html_output}" ]; then
395404
echo "Generating html Output"
405+
# workaround to make mermaid and crossref play nice together: https://github.com/raghur/mermaid-filter/issues/39#issuecomment-1703911386
396406
pandoc \
407+
--filter=mermaid-filter \
408+
--standalone \
409+
--metadata=date:"${DATE}" \
410+
--metadata=date-english:"${DATE_ENGLISH}" \
411+
--metadata=year:"${YEAR}" \
412+
--from=markdown \
413+
"${build_dir}/${input_file}" \
414+
--to=markdown \
415+
| pandoc \
397416
--toc \
398417
-V colorlinks=true \
399418
-V linkcolor=blue \
400419
-V urlcolor=blue \
401420
-V toccolor=blue \
402421
--embed-resources \
403422
--standalone \
404-
--filter=mermaid-filter \
405-
--lua-filter=center-images.lua \
406423
--lua-filter=parse-html.lua \
407424
--filter=pandoc-crossref \
408425
--lua-filter=divide-code-blocks.lua \
@@ -411,8 +428,6 @@ if [ -n "${html_output}" ]; then
411428
--top-level-division=section \
412429
--variable=block-headings \
413430
--variable=numbersections \
414-
--metadata=date-english:"${DATE_ENGLISH}" \
415-
--metadata=year:"${YEAR}" \
416431
--metadata=titlepage:true \
417432
--metadata=titlepage-background:/resources/img/cover.png \
418433
--metadata=crossrefYaml:/resources/filters/pandoc-crossref.yaml \
@@ -423,7 +438,6 @@ if [ -n "${html_output}" ]; then
423438
--from=markdown+implicit_figures+grid_tables+table_captions-markdown_in_html_blocks \
424439
${extra_pandoc_options} \
425440
--to=html \
426-
"${build_dir}/${input_file}.3" \
427441
--output="${html_output}"
428442
echo "HTML Output Generated to file: ${html_output}"
429443
if [ $? -ne 0 ]; then
@@ -438,5 +452,6 @@ fi
438452
# on success remove this output
439453
rm -f mermaid-filter.err
440454
rm -f .puppeteer.json
455+
rm "${build_dir}/${input_file}.bak"
441456

442457
exit 0

guide.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ are expected to use this macro.
271271

272272
Users familiar with Git and who prefer to use their own tools may choose to skip this section.
273273

274-
```mermaid {caption="GitHub Collaboration workflow"}
274+
```mermaid {caption="GitHub Collaboration Workflow" #fig:collaboration-workflow}
275275
gitGraph
276276
commit id: "head"
277277
branch proposed-edits-1
@@ -288,7 +288,7 @@ Users familiar with Git and who prefer to use their own tools may choose to skip
288288
merge proposed-edits-2
289289
```
290290

291-
As visualized above, proposed changes to a GitHub Markdown repository take the form of
291+
As visualized in @fig:collaboration-workflow, proposed changes to a GitHub Markdown repository take the form of
292292
"Pull Requests" (PRs). A *proposer* of a change proposes a PR that changes some files in the repository.
293293
This PR contains an initial *commit*, which is a unit of change to files.
294294
*Reviewers* can provide comments and suggestions on the proposed edits. The *proposer* can respond to
@@ -531,10 +531,10 @@ See the Mermaid website for a more exhaustive list of types of diagrams.
531531

532532
### Sequence Diagrams
533533

534-
Mermaid supports swim-lane digrams like the below with the following notation:
534+
Mermaid supports swim-lane digrams like @fig:startup with the following notation:
535535

536536
````md
537-
```mermaid {caption="Startup Sequence"}
537+
```mermaid {caption="Startup Sequence" #fig:startup}
538538
sequenceDiagram
539539
Host->>TPM: TPM2_Startup
540540
loop Measurements
@@ -545,7 +545,7 @@ TPM->>Host: <quoted PCRs>
545545
```
546546
````
547547

548-
```mermaid {caption="Startup Sequence"}
548+
```mermaid {caption="Startup Sequence" #fig:startup}
549549
sequenceDiagram
550550
Host->>TPM: TPM2_Startup
551551
loop Measurements
@@ -555,14 +555,15 @@ Host->>TPM: TPM2_Quote
555555
TPM->>Host: <quoted PCRs>
556556
```
557557

558-
Crossreferences to Mermaid diagrams are not currently supported.
558+
Crossreferences to Mermaid diagrams are supported by providing both `caption`
559+
and `#fig:xxxxx` classes in curly braces.
559560

560561
### Flow Charts
561562

562-
Mermaid supports flow-charts like the below with the following notation:
563+
Mermaid supports flow-charts like @fig:flowchart with the following notation:
563564

564565
````md
565-
```mermaid {caption="Flowchart"}
566+
```mermaid {caption="Flowchart" #fig:flowchart}
566567
graph TD;
567568
A-->B;
568569
A-->C;
@@ -571,7 +572,7 @@ graph TD;
571572
```
572573
````
573574

574-
```mermaid {caption="Flowchart"}
575+
```mermaid {caption="Flowchart" #fig:flowchart}
575576
graph TD;
576577
A-->B;
577578
A-->C;

template/eisvogel.latex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ $endif$
389389
\usepackage{fontspec}
390390
\setmainfont{Arial}
391391
\setsansfont{Arial}
392-
\setmonofont[Scale=0.9]{Source Code Pro}
392+
\setmonofont{Noto Sans Mono}
393393

394394
\usepackage{newunicodechar}
395395
% Use Arial Unicode to display various unicode symbols that might be present

0 commit comments

Comments
 (0)