-
Notifications
You must be signed in to change notification settings - Fork 0
/
greeker.sh
174 lines (164 loc) · 5.01 KB
/
greeker.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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/bin/bash
# Function to print usage information
print_usage() {
echo "Usage: $0 input_file [output_file] [--pdf]"
echo "Example: $0 input.txt output.md"
echo "Optional: Use '--pdf' flag to also convert the output to a PDF file."
echo "Example: $0 input.txt output.md --pdf"
}
# Check if input file is provided
if [[ $# -lt 1 || "$1" == "--help" || "$1" == "-h" ]]; then
print_usage
exit 0
fi
input_file="$1"
output_file="${2:-${input_file%.*}_converted.md}"
convert_to_pdf_flag=false
# Check if the --pdf flag is set
if [[ "$#" -eq 3 && "$3" == "--pdf" ]]; then
convert_to_pdf_flag=true
elif [[ "$#" -gt 3 ]]; then
print_usage
exit 1
fi
# Check if input file exists and is readable
if [ ! -r "$input_file" ]; then
echo "Error: Input file '$input_file' not found or not readable."
exit 1
fi
# Define a function to perform replacements
replace_greek_and_cyrillic_letters() {
sed -e 's/Α/\Α/g' \
-e 's/α/\α/g' \
-e 's/Β/\Β/g' \
-e 's/β/\β/g' \
-e 's/Γ/\Γ/g' \
-e 's/γ/\γ/g' \
-e 's/Δ/\Δ/g' \
-e 's/δ/\δ/g' \
-e 's/Ε/\Ε/g' \
-e 's/ε/\ε/g' \
-e 's/Ζ/\Ζ/g' \
-e 's/ζ/\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/g' \
-e 's/Ш/\Ш/g' \
-e 's/Щ/\Щ/g' \
-e 's/Ъ/\Ъ/g' \
-e 's/Ы/\Ы/g' \
-e 's/Ь/\Ь/g' \
-e 's/Э/\Э/g' \
-e 's/Ю/\Ю/g' \
-e 's/Я/\Я/g' \
-e 's/а/\а/g' \
-e 's/б/\б/g' \
-e 's/в/\в/g' \
-e 's/г/\г/g' \
-e 's/д/\д/g' \
-e 's/е/\е/g' \
-e 's/ё/\ё/g' \
-e 's/ж/\ж/g' \
-e 's/з/\з/g' \
-e 's/и/\и/g' \
-e 's/й/\й/g' \
-e 's/к/\к/g' \
-e 's/л/\л/g' \
-e 's/м/\м/g' \
-e 's/н/\н/g' \
-e 's/о/\о/g' \
-e 's/п/\п/g' \
-e 's/р/\р/g' \
-e 's/с/\с/g' \
-e 's/т/\т/g' \
-e 's/у/\у/g' \
-e 's/ф/\ф/g' \
-e 's/х/\х/g' \
-e 's/ц/\ц/g' \
-e 's/ч/\ч/g' \
-e 's/ш/\ш/g' \
-e 's/щ/\щ/g' \
-e 's/ъ/\ъ/g' \
-e 's/ы/\ы/g' \
-e 's/ь/\ь/g' \
-e 's/э/\э/g' \
-e 's/ю/\ю/g' \
-e 's/я/\я/g'
}
# Function to convert Markdown to PDF
convert_to_pdf() {
local input_file="$1"
local output_file="${input_file%.md}.pdf"
if command -v pandoc >/dev/null 2>&1; then
pandoc "$input_file" -o "$output_file" --pdf-engine=xelatex -V mainfont="FreeSerif"
echo "PDF conversion complete. Output saved to '$output_file'"
else
echo "Pandoc is not installed. Please install pandoc to use the PDF conversion feature."
fi
}
# Perform replacements and save output to the specified or default file
replace_greek_and_cyrillic_letters < "$input_file" > "$output_file"
echo "Conversion complete. Output saved to '$output_file'"
# Convert to PDF if the flag is set
if [ "$convert_to_pdf_flag" = true ]; then
convert_to_pdf "$output_file"
fi