-
Notifications
You must be signed in to change notification settings - Fork 0
/
gfm
executable file
·48 lines (33 loc) · 1014 Bytes
/
gfm
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
# Hack to convert GitHub-Flavored Markdown to HTML without
# using GitHub's API (works offline)
set -u
requires marked
requires-file ~/.gfm/{head.html,tail.html,subs.dat}
usage.sh "gfm [FILES]..." $@ && exit
CONFDIR="$HOME/.gfm"
if [[ $# -lt 1 ]]; then
# no file specified - run on all markdown files
files="*.md"
else
files="$@"
fi
for f in $files; do
gfmfile="$f"
#echo $gfmfile && continue
[ ! -f "$gfmfile" ] && echo "File not found: $gfmfile" && continue
htmlfile="$gfmfile.html"
cat "$CONFDIR/head.html" > "$htmlfile"
# Replace title
title=${gfmfile%.md}
sed -i 's/<title><\/title>/<title>'"$title"'<\/title>/' "$htmlfile"
html=$(marked "$gfmfile")
# http://stackoverflow.com/questions/10929453/bash-scripting-read-file-line-by-line
while IFS='' read -r line || [[ -n $line ]]; do
dbg "sed: $line"
html="`echo "$html" | sed 's,'"$line"',g'`"
done < "$CONFDIR/subs.dat"
echo "$html" >> "$htmlfile"
cat "$CONFDIR/tail.html" >> "$htmlfile"
echo "$htmlfile"
done