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
|
2020-06-15 05:14:16 -07:00
|
|
|
cat - "$2" >"$2".prefix <<EOF
|
2020-05-26 15:03:45 -07:00
|
|
|
<!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
|
2020-06-15 05:14:16 -07:00
|
|
|
cat "$2.prefix" - >"$2" <<EOF
|
2020-05-26 15:03:45 -07:00
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
EOF
|
2020-06-15 05:14:16 -07:00
|
|
|
rm -f "$2".prefix
|
2020-05-26 15:03:45 -07:00
|
|
|
fi
|
|
|
|
|
2021-02-28 13:24:26 -08:00
|
|
|
sed -i.sedbak 's|<a \(class=[^ ]* \)*href="\([^":]*\)\.rst\(\#[^"]*\)*">|<a \1href="\2\3">|g' "$2"
|
2020-09-14 06:06:31 -07:00
|
|
|
sed -i.sedbak 's|<\(https:[^&]*\)>|\<<a href="\1">\1</a>\>|g' "$2"
|
2020-05-26 15:03:45 -07:00
|
|
|
|
2020-06-15 05:19:22 -07:00
|
|
|
perl -i.sedbak -p0e 's|<section id="([^"]*)">\s*.?\s*<h([1-9])>([^<]*(?:<code>[^<]*</code>[^<]*)?)</h([1-9])>|<section id="\1"><h\2><span class="section-heading">\3</span><span class="section-anchor"> <a rel="bookmark" href="#\1"><img width="24" height="24" src="assets/images/section-anchor.png" alt=""></a></span></h\4>|g' "$2"
|
2020-02-25 06:59:08 -08:00
|
|
|
|
2020-02-25 04:42:17 -08:00
|
|
|
rm -f *.sedbak
|