-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmd2html
executable file
·81 lines (66 loc) · 1.44 KB
/
md2html
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
#!/usr/bin/env bash
#
# md2html
# Part of: malte70/scripts
#
# Markdown to HTML converter powered by pandoc
#
SCRIPT_NAME="$(basename $0)"
SCRIPT_VERSION="0.20230118"
source $(dirname $0)/_base.inc.sh
usage() {
echo "Usage:"
echo " $SCRIPT_NAME"
echo " $SCRIPT_NAME [--version|--help]"
echo " $SCRIPT_NAME <filename.md>"
echo
echo "Options:"
echo " --version -V Show the version and exit"
echo " --help -h Show this help and exit"
echo
}
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
version
usage
exit 0
fi
if which pandoc &>/dev/null; then
true
else
echo "${SCRIPT_NAME}: Error: pandoc not found in \$PATH. Please install it."
exit 1
fi
if [[ $1 == "-v" ]]; then
VERBOSE=1
shift
else
VERBOSE=0
fi
_md2html() {
markdown="$1"
markdown_filename=$(basename "${markdown}")
html="$2"
title=$(grep '^# ' "$markdown" | head -n1 | cut -c3-)
[[ -z $title ]] && title="${markdown_filename}"
pandoc \
--from gfm \
--to html5 \
--standalone \
--metadata title="$title" \
--include-in-header ~/.local/share/pandoc/templates/html5-style.inc.html \
"$markdown" \
--output "$html"
# Table borders and cellpadding, the dirty way
sed -i 's|<table>|<table border="1" cellpadding="6">|g' "$html"
}
markdown="$1"
if [[ ! -f "$markdown" ]]
then
message_error "No such file or directory: $markdown"
exit 13
fi
html="${markdown%.*}.html"
if [[ $VERBOSE -eq 1 ]]; then
echo "$markdown -> $html"
fi
_md2html "$markdown" "$html"