forked from GitHub/gf-core
Use Pandoc instead of txt2tags binary, much more configurable
This commit is contained in:
@@ -3,38 +3,29 @@
|
||||
### This script finds all .t2t (txt2tags) files and updates the corresponding
|
||||
### .html file, if it is out-of-date.
|
||||
|
||||
config=".txt2tagsrc"
|
||||
pre="_pre.html"
|
||||
post="_post.html"
|
||||
tmp="tmp.html"
|
||||
# Path to this directory (not CWD)
|
||||
# https://stackoverflow.com/a/246128/98600
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
|
||||
|
||||
find . -name '*.t2t' | while read t2t ; do
|
||||
html="${t2t%.t2t}.html"
|
||||
if [ "$t2t" -nt "$html" ] ; then
|
||||
txt2tags --config-file="$config" --target=html "$t2t"
|
||||
cat $pre $html $post > $tmp
|
||||
mv $tmp $html
|
||||
head1=$(head -n 1 "$t2t")
|
||||
head2=$(tail -n+2 "$t2t" | head -n 1)
|
||||
head3=$(tail -n+3 "$t2t" | head -n 1)
|
||||
|
||||
# Replace "headers" from t2t in final HTML
|
||||
# Documentation here: https://txt2tags.org/userguide/headerarea
|
||||
if [ -n "$head1" ] ; then
|
||||
sed -i.bak "s/{{HEAD1}}/$head1/" "$html" && rm "$html.bak"
|
||||
echo "$t2t"
|
||||
relroot="$( dirname $t2t | sed -E 's/^.\///' | sed -E 's/[^/]+/../g' )"
|
||||
pandoc \
|
||||
--from=t2t \
|
||||
--to=html5 \
|
||||
--standalone \
|
||||
--template="$DIR/_template.html" \
|
||||
--css="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" \
|
||||
--variable="rel-root:$relroot" \
|
||||
"$t2t" \
|
||||
--output="$html"
|
||||
if [ -f "$html" ]; then
|
||||
sed -i.bak "s/<table>/<table class=\"table\">/" "$html" && rm "$html.bak"
|
||||
sed -i.bak -E "s/\`\`(.+)\`\`/<code>\1<\/code>/g" "$html" && rm "$html.bak"
|
||||
else
|
||||
sed -i.bak -E "s/<.+{{HEAD1}}.+>//" "$html" && rm "$html.bak"
|
||||
continue # empty headers
|
||||
fi
|
||||
if [ -n "$head2" ] ; then
|
||||
sed -i.bak "s/{{HEAD2}}/$head2/" "$html" && rm "$html.bak"
|
||||
else
|
||||
sed -i.bak -E "s/<.+{{HEAD2}}.+>//" "$html" && rm "$html.bak"
|
||||
fi
|
||||
if [ -n "$head3" ] ; then
|
||||
sed -i.bak "s/{{HEAD3}}/$head3/" "$html" && rm "$html.bak"
|
||||
else
|
||||
sed -i.bak -E "s/<.+{{HEAD3}}.+>//" "$html" && rm "$html.bak"
|
||||
echo "Error creating $html"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user