forked from aaronbloomfield/pdr
-
Notifications
You must be signed in to change notification settings - Fork 228
/
convert
executable file
·48 lines (47 loc) · 1.72 KB
/
convert
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
#!/bin/bash
#
# This program will do a first take at converting text files in Radeox
# wiki format (what all my labs and such were in previously) to
# Markdown. Note that this program assumes the cut-and-paste was done
# on a Mac (if done on a different OS, then there are different
# characters that are substituted for the non-ASCII characters).
#
# Most of the replacements are self-explanatory. The first 6 are:
# - replace long dash with --
# - replace left and right single quote with '
# - replace left and right double quotes with "
# - replace {code} tags with ```
for ARG in $*
do
echo processing $ARG...
cat $ARG | \
sed 's/\xe2\x80\x93/--/g' | \
sed "s/\xe2\x80\x98/\'/g" | \
sed "s/\xe2\x80\x99/\'/g" | \
sed 's/\xe2\x80\x9c/\"/g' | \
sed 's/\xe2\x80\x9d/\"/g' | \
sed 's/\xe2\x80\xa6/.../g' | \
sed "s/{code:[^}]*}/\x60\x60\x60/g" | \
sed "s/{code}/\x60\x60\x60/g" | \
sed "s/^# /1. /g" | \
sed "s/^##\ / 1. /g" | \
sed "s/^#/\\\\#/g" | \
sed "s/^h1 \(.*\)$/\1\n===============/g" | \
sed "s/^h2 \(.*\)$/\1\n---------------/g" | \
sed "s/^h3 \(.*\)$/### \1 ###/g" | \
sed "s/^h4 \(.*\)$/### \1 ###/g" | \
sed "s/~~/\*/g" | \
sed "s/__/\*\*/g" | \
sed "s/{link:url=worksite:\([^|]*\)|text=\([^}]*\)}/[\2](\1)/g" | \
sed "s/{link:url=\([^|]*\)|text=\([^}]*\)}/[\2](\1)/g" | \
sed "s/{link:text=worksite:\([^|]*\)|url=\([^}]*\)}/[\1](\2)/g" | \
sed "s/{link:text=\([^|]*\)|url=\([^}]*\)}/[\1](\2)/g" | \
sed "s/{image:img=worksite:\([^}]*\)}/![\1](\1)/g" |
sed "s_\\\u2026_..._g" | \
sed "s_\\\u2013_--_g" | \
sed "s_\\\u201c_\"_g" | \
sed "s_\\\u201d_\"_g" | \
sed "s_\\\u2018_\'_g" | \
sed "s_\\\u2019_\'_g" \
> $ARG.out
done