-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathgitbook_to_pdf.sh
41 lines (37 loc) · 1.54 KB
/
gitbook_to_pdf.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# #!/bin/bash
GITBOOK_REP=$1
SUMMARY_FILE="SUMMARY.md"
echo $OUTPUT_FILE
if [ -d "$GITBOOK_REP" ]; then
echo "Entering directory '$GITBOOK_REP'..."
cd $GITBOOK_REP
if [ -f "$SUMMARY_FILE" ]; then
# read summary and get texts by order in a single big file
# we replace:
# hint tip and working by --- markdown block
# $$ -> $ (for latex math mode)
pandoc $SUMMARY_FILE -t html | \
grep -o '<a href=['"'"'"][^"'"'"']*['"'"'"]' | \
sed -e 's/^<a href=["'"'"']//' -e 's/["'"'"']$//'| \
xargs cat | \
sed 's/\$\$/\$/g' | \
perl -pe "s/{% hint style='tip' %}/***\n**_Tip:_** /g" | \
perl -pe "s/{% hint style='working' %}/***\n**_TODO:_** /g" | \
perl -pe 's/{% endhint %}/\n***/g' | \
perl -pe 's/{% include "\/includes\/youtube.md" %}//g' | \
perl -pe 's/{% set video_id = "([A-Za-z0-9-_]*)" %}/***\nWatch our video on YouTube:\n\nhttp:\/\/www.youtube.com\/embed\/\1\n\n***/g' | \
pandoc -f markdown \
--variable fontsize=11pt \
--variable=geometry:b5paper \
--variable mainfont="Georgia" \
--variable documentclass=book \
-H latex-conf/head.tex \
-V subparagraph \
--resource-path="chapters/getting-started/:chapters/intelligent-testing:chapters/pragmatic-testing:chapters/testing-techniques:chapters/appendix" \
--toc --toc-depth=3 --pdf-engine=xelatex -o book.pdf
else
echo "File '$SUMMARY_FILE' does not exist"
fi
else
echo "Directory '$GITBOOK_REP' does not exist"
fi