2022-06-02 05:11:40 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# copies an .html file to an equivalent .xhtml file, but replaces
|
|
|
|
# the meta charset with an XML declaration for compatibility with some
|
|
|
|
# XML tooling.
|
|
|
|
# Expects polygot XHTML(5) markup.
|
|
|
|
# Formats both the .html and .xhtml file.
|
|
|
|
# this means that every index.html file has an equivalent index.xhtml file.
|
|
|
|
# content negotiation allows an agent to pick html or xhtml.
|
|
|
|
|
|
|
|
# use xmllint to do the formatting.
|
|
|
|
# xmllint ruins inline CSS so delete the inline CSS and re-insert it.
|
|
|
|
# xmllint also adds extra whitespace around <pre><code> which we remove
|
|
|
|
# with "sd". I chose sd since it handles newlines well.
|
|
|
|
|
|
|
|
set -e -u
|
|
|
|
|
|
|
|
export html_file="$1"
|
2022-06-03 00:18:13 +00:00
|
|
|
export tmp_file="$html_file.tmp"
|
2022-06-02 05:11:40 +00:00
|
|
|
export xhtml_file=${html_file%*.html}.xhtml
|
|
|
|
|
|
|
|
cleanup() {
|
|
|
|
rm -f "$tmp_file"
|
|
|
|
}
|
|
|
|
trap cleanup EXIT
|
|
|
|
|
|
|
|
trap cleanup EXIT
|
|
|
|
sed 7d "$html_file" | xmllint --format --encode UTF-8 --noent - -o "$tmp_file"
|
2022-06-03 00:18:13 +00:00
|
|
|
{
|
|
|
|
head -n7 "$tmp_file"
|
|
|
|
cat tmp.css
|
|
|
|
tail -n +8 "$tmp_file" \
|
|
|
|
| sd '<pre(?: tabindex="0")?>\n\t*<code ' '<pre tabindex="0"><code ' \
|
2022-06-03 03:01:50 +00:00
|
|
|
| sd '(?:\n)?</code>\n(?:[\t\s]*)?</pre>' '</code></pre>' \
|
2022-06-03 04:48:23 +00:00
|
|
|
| sd '</span>.span itemprop="familyName"' '</span> <span itemprop="familyName"' \
|
2022-06-03 22:47:14 +00:00
|
|
|
| sd '(<img itemprop="image" class="u-photo photo"[^>]*/>)<span' '$1 <span' \
|
2022-06-03 04:48:23 +00:00
|
|
|
| sd '([a-z])<(data|time)' '$1 <$2'
|
2022-06-03 00:18:13 +00:00
|
|
|
} >>"$xhtml_file"
|
|
|
|
|
|
|
|
# replace the html file with the formatted xhtml5 file, excluding the xml declaration
|
2022-06-02 05:11:40 +00:00
|
|
|
tail -n +2 "$xhtml_file" > "$html_file"
|
|
|
|
|
2022-06-03 00:18:13 +00:00
|
|
|
# remove the redundant charset declaration from the xhtml file. It's the
|
|
|
|
# first thing in the <head>
|
|
|
|
sed -i 5d "$xhtml_file" # busybox sed supports "-i"
|