#!/bin/sh if ! ( ( [ "x$1" = "x--rst" ] && [ $# -eq 2 ] ) || ( [ "x$1" = "x--md" ] && [ $# -eq 3 ] ) ); then echo "Usage: edithtml.sh --rst " echo " or: edithtml.sh --md " exit fi if ! [ -f "$2" ]; then echo File not found: "$2" exit fi if [ "x$1" = "x--rst" ]; then 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 EOF cat "$2.prefix" - >"$2" < EOF rm -f "$2".prefix fi sed -i.sedbak 's|||g' "$2" sed -i.sedbak 's|<\(https:[^&]*\)>|\<\1\>|g' "$2" perl -i.sedbak -p0e 's|
\s*.?\s*([^<]*(?:[^<]*[^<]*)?)|
\3 |g' "$2" rm -f *.sedbak