2020-05-27 07:29:01 -07:00
|
|
|
#!/bin/sh
|
2020-02-25 04:42:17 -08:00
|
|
|
|
2020-05-27 07:29:01 -07:00
|
|
|
if ! ( ( [ "x$1" = "x--rst" ] && [ $# -eq 2 ] ) || ( [ "x$1" = "x--md" ] && [ $# -eq 3 ] ) ); then
|
2020-05-26 15:03:45 -07:00
|
|
|
echo "Usage: edithtml.sh --rst <htmlfile>"
|
|
|
|
echo " or: edithtml.sh --md <htmlfile> <title>"
|
|
|
|
exit
|
|
|
|
fi
|
2020-02-25 06:59:08 -08:00
|
|
|
|
2020-05-27 07:29:01 -07:00
|
|
|
if ! [ -f "$2" ]; then
|
|
|
|
echo File not found: "$2"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "x$1" = "x--rst" ]; then
|
2020-05-26 15:03:45 -07:00
|
|
|
sed -i.sedbak 's|</head>|<meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" href="css/style.css"></head>|' $2
|
|
|
|
sed -i.sedbak 's|http://cdn.mathjax.org/mathjax/latest/MathJax.js|https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js|' $2
|
|
|
|
else
|
|
|
|
cat - $2 >$2.prefix <<EOF
|
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>$3</title>
|
|
|
|
<meta charset="utf-8" />
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js?config=TeX-AMS-MML_HTMLorMML"></script>
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" href="css/style.css">
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
EOF
|
|
|
|
cat $2.prefix - >$2 <<EOF
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
EOF
|
|
|
|
rm -f $2.prefix
|
|
|
|
fi
|
|
|
|
|
|
|
|
sed -i.sedbak 's|<a href="\([^":]*\).rst">|<a href="\1">|g' $2
|
|
|
|
|
|
|
|
# Put <section id="..."> and <hN>...</hN> on the same line. <https://unix.stackexchange.com/a/337399/82702>
|
|
|
|
sed -i.sedbak -n '$!N;s|<section id="\([^"]*\)">\s*\n\s*<h|<section id="\1"><h|;P;D' $2
|
|
|
|
sed -i.sedbak 's|<section id="\([^"]*\)"><h\([1-9]\)>\([^<]*\)</h\([1-9]\)>|<section id="\1"><h\2><span class="section-heading">\3</span><span class="section-anchor"> <a href="#\1"><img width="24" height="24" src="assets/images/section-anchor.png" alt=""></a></span></h\4>|' $2
|
2020-02-25 06:59:08 -08:00
|
|
|
|
2020-02-25 04:42:17 -08:00
|
|
|
rm -f *.sedbak
|