-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport.sh
More file actions
executable file
·87 lines (73 loc) · 2.08 KB
/
Copy pathexport.sh
File metadata and controls
executable file
·87 lines (73 loc) · 2.08 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
# export.sh — Export bilingual markdown to PDF and/or DOCX
# Usage:
# ./export.sh document.md # both PDF + DOCX (redline if CriticMarkup present)
# ./export.sh document.md --pdf # PDF only
# ./export.sh document.md --docx # DOCX only
# ./export.sh document.md --accept # both, accept all changes (clean version)
# ./export.sh document.md --pdf --accept # PDF only, clean version
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
FILTER="$SCRIPT_DIR/filter/bilingual.lua"
CRITIC_FILTER="$SCRIPT_DIR/filter/criticmarkup.lua"
TEMPLATE="$SCRIPT_DIR/templates/bilingual.latex"
OUTPUT_DIR="$HOME/Documents/bilingual-exports"
if [ $# -lt 1 ]; then
echo "Usage: $0 <file.md> [--pdf|--docx] [--accept]"
exit 1
fi
INPUT="$1"
shift
DO_PDF=false
DO_DOCX=false
CRITIC_MODE="redline"
for arg in "$@"; do
case "$arg" in
--pdf) DO_PDF=true ;;
--docx) DO_DOCX=true ;;
--accept) CRITIC_MODE="accept" ;;
esac
done
# If neither --pdf nor --docx specified, do both
if ! $DO_PDF && ! $DO_DOCX; then
DO_PDF=true
DO_DOCX=true
fi
if [ ! -f "$INPUT" ]; then
echo "Error: file not found: $INPUT"
exit 1
fi
mkdir -p "$OUTPUT_DIR"
BASENAME="$(basename "$INPUT" .md)"
do_pdf() {
echo "Exporting PDF${1:+ ($1)}..."
pandoc "$INPUT" \
-f markdown-strikeout-subscript \
-M critic-mode="$CRITIC_MODE" \
--lua-filter="$CRITIC_FILTER" \
--lua-filter="$FILTER" \
--template="$TEMPLATE" \
--pdf-engine=lualatex \
-V mainfont="PT Serif" \
-V sansfont="Helvetica Neue" \
-V monofont="Menlo" \
-o "$OUTPUT_DIR/$BASENAME.pdf"
echo " -> $OUTPUT_DIR/$BASENAME.pdf"
}
do_docx() {
echo "Exporting DOCX${1:+ ($1)}..."
pandoc "$INPUT" \
-f markdown-strikeout-subscript \
-M critic-mode="$CRITIC_MODE" \
--lua-filter="$CRITIC_FILTER" \
--lua-filter="$FILTER" \
-o "$OUTPUT_DIR/$BASENAME.docx"
echo " -> $OUTPUT_DIR/$BASENAME.docx"
}
MODE_LABEL=""
if [ "$CRITIC_MODE" = "accept" ]; then
MODE_LABEL="clean"
fi
$DO_PDF && do_pdf "$MODE_LABEL"
$DO_DOCX && do_docx "$MODE_LABEL"
echo "Done."