@@ -243,25 +243,18 @@ if [ "${table_rules}" == "yes" ]; then
243
243
extra_pandoc_options+=" --lua-filter=table-rules.lua"
244
244
fi
245
245
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
+
256
250
# \newpage is rendered as the string "\newpage" in GitHub markdown.
257
251
# Transform horizontal rules into \newpages.
258
252
# 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} "
260
254
261
- # Transform 3
262
255
# Transform sections before the table of contents into section*, which does not number them.
263
256
# 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} "
265
258
266
259
if test " ${do_gitversion} " == " yes" ; then
267
260
# If using the git information for versioning, grab the date from there
@@ -288,13 +281,21 @@ RESULT=0
288
281
# Generate the pdf
289
282
if [ -n " ${pdf_output} " ]; then
290
283
echo " Generating PDF Output"
284
+ # workaround to make mermaid and crossref play nice together: https://github.com/raghur/mermaid-filter/issues/39#issuecomment-1703911386
291
285
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 \
293
296
--embed-resources \
294
297
--standalone \
295
298
--template=eisvogel.latex \
296
- --filter=mermaid-filter \
297
- --lua-filter=center-images.lua \
298
299
--lua-filter=parse-html.lua \
299
300
--filter=pandoc-crossref \
300
301
--lua-filter=divide-code-blocks.lua \
@@ -303,9 +304,6 @@ if [ -n "${pdf_output}" ]; then
303
304
--top-level-division=section \
304
305
--variable=block-headings \
305
306
--variable=numbersections \
306
- --metadata=date:" ${DATE} " \
307
- --metadata=date-english:" ${DATE_ENGLISH} " \
308
- --metadata=year:" ${YEAR} " \
309
307
--metadata=titlepage:true \
310
308
--metadata=titlepage-background:/resources/img/cover.png \
311
309
--metadata=crossrefYaml:/resources/filters/pandoc-crossref.yaml \
@@ -316,7 +314,6 @@ if [ -n "${pdf_output}" ]; then
316
314
--from=markdown+implicit_figures+grid_tables+table_captions-markdown_in_html_blocks \
317
315
${extra_pandoc_options} \
318
316
--to=pdf \
319
- " ${build_dir} /${input_file} .3" \
320
317
--output=" ${pdf_output} "
321
318
echo " PDF Output Generated to file: ${pdf_output} "
322
319
if [ $? -ne 0 ]; then
327
324
# Generate the LaTeX output
328
325
if [ -n " ${latex_output} " ]; then
329
326
echo " Generating LaTeX Output"
327
+ # workaround to make mermaid and crossref play nice together: https://github.com/raghur/mermaid-filter/issues/39#issuecomment-1703911386
330
328
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 \
332
339
--embed-resources \
333
340
--standalone \
334
341
--template=eisvogel.latex \
335
- --filter=mermaid-filter \
336
- --lua-filter=center-images.lua \
337
342
--lua-filter=parse-html.lua \
338
343
--filter=pandoc-crossref \
339
344
--lua-filter=divide-code-blocks.lua \
@@ -342,8 +347,6 @@ if [ -n "${latex_output}" ]; then
342
347
--top-level-division=section \
343
348
--variable=block-headings \
344
349
--variable=numbersections \
345
- --metadata=date-english:" ${DATE_ENGLISH} " \
346
- --metadata=year:" ${YEAR} " \
347
350
--metadata=titlepage:true \
348
351
--metadata=titlepage-background:/resources/img/cover.png \
349
352
--metadata=crossrefYaml:/resources/filters/pandoc-crossref.yaml \
@@ -354,7 +357,6 @@ if [ -n "${latex_output}" ]; then
354
357
--from=markdown+implicit_figures+grid_tables+table_captions-markdown_in_html_blocks \
355
358
${extra_pandoc_options} \
356
359
--to=latex \
357
- " ${build_dir} /${input_file} .3" \
358
360
--output=" ${latex_output} "
359
361
echo " LaTeX Output Generated to file: ${latex_output} "
360
362
if [ $? -ne 0 ]; then
365
367
# Generate the docx output
366
368
if [ -n " ${docx_output} " ]; then
367
369
echo " Generating DOCX Output"
370
+ # workaround to make mermaid and crossref play nice together: https://github.com/raghur/mermaid-filter/issues/39#issuecomment-1703911386
368
371
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 \
370
382
--embed-resources \
371
383
--standalone \
372
384
--filter=/resources/filters/info.py \
373
- --filter=mermaid-filter \
374
- --lua-filter=center-images.lua \
375
385
--lua-filter=parse-html.lua \
376
386
--filter=pandoc-crossref \
377
387
--resource-path=.:/resources \
@@ -380,7 +390,6 @@ if [ -n "${docx_output}" ]; then
380
390
--reference-doc=/resources/templates/tcg_template.docx \
381
391
${extra_pandoc_options} \
382
392
--to=docx \
383
- " ${build_dir} /${input_file} .3" \
384
393
--output=" ${docx_output} "
385
394
echo " DOCX Output Generated to file: ${docx_output} "
386
395
if [ $? -ne 0 ]; then
@@ -393,16 +402,24 @@ export MERMAID_FILTER_FORMAT="svg"
393
402
# Generate the html output
394
403
if [ -n " ${html_output} " ]; then
395
404
echo " Generating html Output"
405
+ # workaround to make mermaid and crossref play nice together: https://github.com/raghur/mermaid-filter/issues/39#issuecomment-1703911386
396
406
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 \
397
416
--toc \
398
417
-V colorlinks=true \
399
418
-V linkcolor=blue \
400
419
-V urlcolor=blue \
401
420
-V toccolor=blue \
402
421
--embed-resources \
403
422
--standalone \
404
- --filter=mermaid-filter \
405
- --lua-filter=center-images.lua \
406
423
--lua-filter=parse-html.lua \
407
424
--filter=pandoc-crossref \
408
425
--lua-filter=divide-code-blocks.lua \
@@ -411,8 +428,6 @@ if [ -n "${html_output}" ]; then
411
428
--top-level-division=section \
412
429
--variable=block-headings \
413
430
--variable=numbersections \
414
- --metadata=date-english:" ${DATE_ENGLISH} " \
415
- --metadata=year:" ${YEAR} " \
416
431
--metadata=titlepage:true \
417
432
--metadata=titlepage-background:/resources/img/cover.png \
418
433
--metadata=crossrefYaml:/resources/filters/pandoc-crossref.yaml \
@@ -423,7 +438,6 @@ if [ -n "${html_output}" ]; then
423
438
--from=markdown+implicit_figures+grid_tables+table_captions-markdown_in_html_blocks \
424
439
${extra_pandoc_options} \
425
440
--to=html \
426
- " ${build_dir} /${input_file} .3" \
427
441
--output=" ${html_output} "
428
442
echo " HTML Output Generated to file: ${html_output} "
429
443
if [ $? -ne 0 ]; then
438
452
# on success remove this output
439
453
rm -f mermaid-filter.err
440
454
rm -f .puppeteer.json
455
+ rm " ${build_dir} /${input_file} .bak"
441
456
442
457
exit 0
0 commit comments