+++ /dev/null
-#!/bin/bash
-
-# NAME
-# reformat-html - reformat HTML files from emailselfdefense.fsf.org
-
-# SYNOPSIS
-# reformat-html /PATH/TO/NAME.html
-
-# GRAPHIC INTERFACE HOWTO
-# * Launch the script by double-clicking on it; a terminal will open.
-# * At the prompt, drag and drop the input file into the terminal.
-#
-# Alternatively (in Gnome, KDE, XFCE, etc.)
-# * create a launcher for the application menu;
-# * launch the script from the contextual menu of the HTML file.
-#
-# The reformatted file is created in the directory where the input file
-# resides, and its name is NAME-r.html.
-
-#==============================================================================
-
-set -e
-
-# Test whether the script is called from color-wdiff
-p=$(pidof -x color-wdiff) || true
-test "$p" == "$PPID" && called_from_color_wdiff=1
-
-function sleep_or_exit () {
-# turns off interactivity and lets the terminal close normally if the script
-# is called from color-wdiff.
-
-if test "$called_from_color_wdiff" == "1"; then
- exit $1
-else
- if test "$1" == "1"; then
- echo -e 1>&2 "\n!!! $input doesn't exist or is not HTML."
- sleep 3
- fi
- exit $1
-fi
-}
-
-# Get a valid HTML as input.
-input=$1
-if test ! -f "$input" -o ! -s "$input"; then
- echo -e "\n*** reformat-html - Please enter the HTML file."
- read input
- input=${input%\'}; input=${input#\'}
-fi
-test -f "$input" -a "${input%.html}" != "$input" || sleep_or_exit 1
-
-# Define the output file.
-if test "$called_from_color_wdiff" == "1"; then
- output=$2
-else
- output=${input%.html}-r.html
-fi
-
-tmp=$(mktemp -t ref.XXXXXX) || exit 1
-tmp1=$(mktemp -t ref.XXXXXX) || exit 1
-tmp2=$(mktemp -t ref.XXXXXX) || exit 1
-trap 'rm -f "$tmp" "$tmp1" "$tmp2"' EXIT
-
-# Don't touch the scripts.
-sed -n '/<script/,$p' $input > $tmp1
-sed '/<script/,$d' $input > $tmp
-
-# Clean up extra spaces and tabs; remove blank lines.
-sed -i -e 's,[[:space:]]\+, ,g' \
- -e 's,^ ,,' \
- -e 's, $,,' \
- -e 's,> <,><,g' \
- -e '/^$/d' $tmp
-
-# For the language list: fix the commented-out items (broken by po4a).
-sed -i -e '/<\/a>$/ {N; s,<\/a>\n<,<\/a><,}' $tmp
-sed -i -e '/^<li/ {N; s,>\n<a ,><a ,}' $tmp
-
-# </p> at the end of the line (much better to do it by hand).
-sed -i -e '/[>.]$/ {N;s,\n</strong,</strong,}' $tmp
-sed -i -e '/[>.]$/ {N;s,\n</p,</p,}' $tmp
-sed -i -e '/"$/ {N;s,\n</p,</p,}' $tmp
-
-# <p> and its attributes on the same line.
-sed -i -e '/<p$/ {N;s,\n, ,}' $tmp
-
-# Remove LF after opening tags.
-for tag in li p strong a h3; do
- sed -i "/<$tag[^>]*>$/ {N; s,\\n,,}" $tmp
-done
-
-# Single out paragraphs (fused with <noscript> in one instance), main
-# sections, and image links (e.g. infographic) when followed by text.
-# Separate truncated "~~~" comment from fused tag.
-# Fold img tags; Add a line after footer.
-sed -i -e 's,\([^t]>\)<p,\1\n<p,' \
- -e 's,><noscript,>\n<noscript,' \
- -e 's,<!-- ~~,\n<!-- ~~,' \
- -e 's,/></a> \([[:alnum:]]\),/></a>\n\1,' \
- -e 's,~~~[ ]\?[-]\?[-]\?[ ]\?<,~~~\n<,' \
- -e 's, src=",\nsrc=",' \
- -e 's, alt=",\nalt=",' \
- -e 's,<!-- End #footer -->,&\n,' $tmp
-
-# Fuse header, section and footer with the corresponding div.
-for tag in header section footer; do
- sed -i "/^<$tag/ {N; s,\\(<$tag[^>]*>\\)\\n<div>,\\1<div>,}" $tmp
- sed -i "/^<\\/div>$/ {N; s,<\\/div>\\n\\(<\\/$tag>\\),</div>\\1,}" $tmp
-done
-
-# Make the text more readable.
-sed -i 's,\(<link[^>]*>\)<,\1\n<,' $tmp
-sed -i 's,\(<meta[^>]*>\)<,\1\n<,' $tmp
-
-for tag in p dd li h1 h2 h3 form; do
- sed -i "/<\\/$tag>$/s,$,\\n," $tmp
-done
-for tag in p dl ul h1 h2 h3 h4 form body; do
- sed -i "/^<$tag/s,^,\\n," $tmp
-done
-sed -i '/^$/ {N; s,^\n</dl>,</dl>\n,}' $tmp
-sed -i '/^$/ {N; s,^\n</ul>,</ul>\n,}' $tmp
-
-# Remove blank lines in menus and image blocks.
-sed -i '/^$/ {N; s,^\n<li><img,<li><img,}' $tmp
-sed -i '/^$/ {N; s,^\n<li[^>]*><a ,<li><a ,}' $tmp
-sed -i '/JS enabled -->/ {N;N; s,\n\n,\n,}' $tmp
-
-# Unwrap the last item of the language list for easier
-# replacement.
-sed -i '/<li><a/ {N; s,\n\(.*Translation_Guide\), \1,}' $tmp
-
-# Wrap lines.
-fmt -s -w 80 $tmp > $tmp2
-
-# Suppress repeated empty lines.
-cat -s $tmp2 $tmp1 > $output
-
-sleep_or_exit 0