Skip to content

Commit 2f1f58b

Browse files
authored
Fix several minor issues with the tools. (#63)
1 parent 690cb0b commit 2f1f58b

File tree

6 files changed

+56
-25
lines changed

6 files changed

+56
-25
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ RUN pip install pandocfilters
7878
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \
7979
PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
8080

81-
81+
8282

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

build.sh

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ print_usage() {
4343
}
4444

4545

46-
if ! options=$(getopt --longoptions=help,puppeteer,notmp,gitversion,gitstatus,pdf:,latex:,docx:,resourcedir: --options="" -- "$@"); then
46+
if ! options=$(getopt --longoptions=help,puppeteer,notmp,gitversion,gitstatus,table_rules,pdf:,latex:,docx:,resourcedir: --options="" -- "$@"); then
4747
echo "Incorrect options provided"
4848
print_usage
4949
exit 1
@@ -242,9 +242,11 @@ fi
242242
# Transform 1
243243
# GitHub Mermaid doesn't recognize the full ```{.mermaid ...} attributes-form
244244
# Pandoc doesn't recognized mixed ```mermaid {...} form
245-
# Hack: use sed to transform the former to the latter so everyone is happy
246-
sed 's/```mermaid *{/```{.mermaid /g' "${input_file}" > "${build_dir}/${input_file}.1"
247-
245+
# Hack: use sed to transform the latter to the former so everyone is happy
246+
# Only transform if there is exactly one space after ```mermaid
247+
# Instructional documentation may use more than one space in the source code to suppress this.
248+
sed 's/```mermaid {/```{.mermaid /g' "${input_file}" > "${build_dir}/${input_file}.1"
249+
sed 's/```mermaid *{/```mermaid {/g' "${input_file}" > "${build_dir}/${input_file}.1"
248250

249251
# Transform 2
250252
# \newpage is rendered as the string "\newpage" in GitHub markdown.
@@ -273,14 +275,15 @@ RESULT=0
273275
if [ -n "${pdf_output}" ]; then
274276
echo "Generating PDF Output"
275277
pandoc \
276-
--dpi 300 \
277278
--pdf-engine=lualatex \
278279
--embed-resources \
279280
--standalone \
280281
--template=eisvogel.latex \
281282
--filter=mermaid-filter \
283+
--lua-filter=center-images.lua \
282284
--lua-filter=parse-html.lua \
283285
--filter=pandoc-crossref \
286+
--lua-filter=divide-code-blocks.lua \
284287
--resource-path=.:/resources \
285288
--data-dir=/resources \
286289
--top-level-division=section \
@@ -312,14 +315,15 @@ fi
312315
if [ -n "${latex_output}" ]; then
313316
echo "Generating LaTeX Output"
314317
pandoc \
315-
--dpi 300 \
316318
--pdf-engine=lualatex \
317319
--embed-resources \
318320
--standalone \
319321
--template=eisvogel.latex \
320322
--filter=mermaid-filter \
323+
--lua-filter=center-images \
321324
--lua-filter=parse-html.lua \
322325
--filter=pandoc-crossref \
326+
--lua-filter=divide-code-blocks.lua \
323327
--resource-path=.:/resources \
324328
--data-dir=/resources \
325329
--top-level-division=section \
@@ -351,12 +355,12 @@ fi
351355
if [ -n "${docx_output}" ]; then
352356
echo "Generating DOCX Output"
353357
pandoc \
354-
--dpi 150 \
355358
--pdf-engine=lualatex \
356359
--embed-resources \
357360
--standalone \
358361
--filter=/resources/filters/info.py \
359362
--filter=mermaid-filter \
363+
--lua-filter=center-images.lua \
360364
--lua-filter=parse-html.lua \
361365
--filter=pandoc-crossref \
362366
--resource-path=.:/resources \

filter/center-images.lua

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
-- Center images (i.e., those produced by Mermaid): https://pandoc.org/lua-filters.html#center-images-in-latex-and-html-output
2+
3+
function string:hassuffix(suffix)
4+
return self:sub(-#suffix) == suffix
5+
end
6+
7+
if FORMAT:match 'latex' then
8+
function Image (elem)
9+
return elem.src:hassuffix(".pdf")
10+
-- Surround all pdf images with image-centering raw LaTeX.
11+
and {
12+
pandoc.RawInline('latex', '\\hfill\\break{\\centering'),
13+
elem,
14+
pandoc.RawInline('latex', '\\par}')
15+
}
16+
or elem
17+
end
18+
end

filter/divide-code-blocks.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- draw horizontal rules above and below code blocks to separate them nicely
2+
3+
function CodeBlock(block)
4+
return {
5+
pandoc.RawInline('latex', '\\noindent\\textcolor{gray}{\\rule{\\textwidth}{0.25pt}}'),
6+
block,
7+
pandoc.RawInline('latex', '\\noindent\\textcolor{gray}{\\rule{\\textwidth}{0.25pt}}'),
8+
}
9+
end

guide.md

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ You can create a repository from scratch, or you can use
106106
to get started a little more quickly. There's a little green "Use this template" button in the top right
107107
(see @fig:use-template-button).
108108

109-
![The "Use this template" button](use_template.jpg){#fig:use-template-button}
109+
![The "Use this template" button](use_template.jpg){#fig:use-template-button width=50%}
110110

111111
## GitHub Actions
112112

@@ -183,7 +183,7 @@ The trickiest section is the YAML front matter at the very top of the Markdown f
183183
It looks like this:
184184
185185
```md
186-
---
186+
---
187187
title: "TCG Markdown User's Guide"
188188
version: 0.1
189189
revision: 1
@@ -308,7 +308,7 @@ clicking on them.
308308
From this view, there is an "Edit" (pencil) button in the upper right-hand corner, pictured in
309309
@fig:edit-file-button:
310310

311-
![GitHub Edit Button](edit_this_file.jpg){#fig:edit-file-button}
311+
![GitHub Edit Button](edit_this_file.jpg){#fig:edit-file-button width=30%}
312312

313313
This will take you to a view where you can edit the file. There is a "Preview" button that you can use
314314
to see roughly how the changes will look when viewed from GitHub. Most everyday changes to TCG docs
@@ -317,7 +317,7 @@ can be previewed in high enough fidelity with this tool.
317317
When you're satisfied with your changes, use the green "Commit changes..." button. This will bring up
318318
the dialog box pictured in @fig:propose-changes:
319319

320-
![Propose Changes Dialog](propose_changes.jpg){#fig:propose-changes}
320+
![Propose Changes Dialog](propose_changes.jpg){#fig:propose-changes width=60%}
321321

322322
Include a descriptive commit message, extended description, and new branch name for your change,
323323
then click the green "Propose changes" button.
@@ -340,7 +340,7 @@ which looks like @fig:plus-button:
340340
After you've gone through all the changed files and provided your comments, you can click "Review changes"
341341
to finish the review. This dialog looks like @fig:finish-review:
342342

343-
![Finish Review](finish_review.jpg){#fig:finish-review}
343+
![Finish Review](finish_review.jpg){#fig:finish-review width=60%}
344344

345345
Here, you can provide summary comments and mark your review as one of:
346346

@@ -359,13 +359,9 @@ The structure of the document is guided by lines that begin with `#`:
359359

360360
```md
361361
# Section Titles
362-
```
363362

364-
```md
365363
## Subsection Titles
366-
```
367364

368-
```md
369365
### Sub-subsection Titles
370366
```
371367

@@ -519,18 +515,20 @@ to the branch for the PR that reference the image, or you can do it in a subsequ
519515
Markdown syntax for including an image looks like `![Figure Title](filename)`. For example:
520516

521517
```md
522-
![Adding an Image](add_plus_button.jpg){#fig:add-plus-button}
518+
![Adding an Image](add_plus_button.jpg){#fig:add-plus-button width=60%}
523519
```
524520

525521
becomes:
526522

527-
![Adding an Image](add_plus_button.jpg){#fig:add-plus-button}
523+
![Adding an Image](add_plus_button.jpg){#fig:add-plus-button width=60%}
528524

529525
The `{#fig:add-plus-button}` attribute (note there are no spaces between the `)` and the `{`!) does two things:
530526

531527
1. Includes the figure in the List of Figures (if you used `\listoffigures` as described in @sec:toc).
532528
2. Numbers the figure so you can reference it as @fig:add-plus-button by just typing `@fig:add-plus-button`.
533529

530+
Including `width=60%` here specifies that the image should take up 60% of the page's width.
531+
534532
## Mermaid Charts
535533

536534
[Mermaid](http://mermaid.js.org) is a language for text-based diagrams for inclusion in Markdown documents.
@@ -541,7 +539,7 @@ See the Mermaid website for a more exhaustive list of types of diagrams.
541539
Mermaid supports swim-lane digrams like the below with the following notation:
542540

543541
````md
544-
```mer​maid {caption="Startup Sequence"}
542+
```mermaid {caption="Startup Sequence"}
545543
sequenceDiagram
546544
Host->>TPM: TPM2_Startup
547545
loop Measurements
@@ -569,7 +567,7 @@ Crossreferences to Mermaid diagrams are not currently supported.
569567
Mermaid supports flow-charts like the below with the following notation:
570568

571569
````md
572-
```mer​maid {caption="Flowchart"}
570+
```mermaid {caption="Flowchart"}
573571
graph TD;
574572
A-->B;
575573
A-->C;

template/eisvogel.latex

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ $endif$
6060
\documentclass[
6161
paper=letter,
6262
captions=tableheading,
63-
toc=sectionentrywithdots
63+
toc=sectionentrywithdots,
64+
numbers=noenddot
6465
]{scrartcl}
6566

6667
\usepackage{amsmath,amssymb}
@@ -363,17 +364,17 @@ $endif$
363364
\vskip 0.5em
364365
\begin{customblockquote}
365366
\list{}{\rightmargin=0em\leftmargin=0em}
366-
\item\color{blockquote-text}\textbf{\textit{Start of informative comment}}
367+
\item\color{blockquote-text}\textbf{\textit{\textcolor{gray}{\small Start of informative comment}}}
367368
\item\relax\color{blockquote-text}\ignorespaces
368369
}{
369-
\item\color{blockquote-text}\textbf{\textit{End of informative comment}}
370+
\item\color{blockquote-text}\textbf{\textit{\textcolor{gray}{\small End of informative comment}}}
370371
\unskip\unskip\endlist\end{customblockquote}
371372
}
372373

373374
\usepackage{fontspec}
374375
\setmainfont{Arial}
375376
\setsansfont{Arial}
376-
\setmonofont{Source Code Pro}
377+
\setmonofont[Scale=0.9]{Source Code Pro}
377378

378379
\usepackage{newunicodechar}
379380
% Use Arial Unicode to display various unicode symbols that might be present
@@ -698,6 +699,7 @@ $endif$
698699
% Allow TCG documents to use '\beginappendices' to easily mark the transition to appendices.
699700
\usepackage{appendix}
700701
\newcommand{\beginappendices}{
702+
\newpage
701703
\appendix
702704
\appendixpage
703705
\addappheadtotoc

0 commit comments

Comments
 (0)