H !# Include proxy title !# Insert fallback values ??a . !# Define self from file name //r !echo % .g/\.[[:alnum:]]*$/s/// .g/.*/s//&<\/SELF>/ !# IE-styled inclusion comments (+inline) g//s//\1/ g//s//\1/ g//d g//d g//d g//d !# Mark all the lines with end-of-line separator g/$/s//|||/ !# Var substitution: Duplicate var defintion !# to before all the var-containing lines 12,$g/SELF/??t. 12,$g/SUBTITLE/??t. 12,$g/[^B]TITLE/??t. 12,$g/DESCRIPTION/?<DESCRIPTION>?t. 12,$g/IMAGE[^_]/?<IMAGE>?t. 12,$g/IMAGE_ALT/?<IMAGE_ALT>?t. 12,$g/IMAGE-ALT/?<IMAGE-ALT>?t. !# No need for colors here !# Substitute all vars into the text 11,$g/<\([A-Z_-]*\)>.*<\/\1>/-1,.j\ s/\([A-Z_-]*\)\(.*\)||| *<\1>\([^|]*\)<\/\1>|||/\3\2|||/ !# Split lines (no longer necessary) g/|||$/s/// g/|||/s//\ /g !# Remove all the var definitions /<head>/,/<\/head/g/<\(SELF\)*\(SUBTITLE\)*\(DESCRIPTION\)*\(IMAGE\)*\([_-]ALT\)*>/d !# Remove all of the head /<head>/,/<\/head>/d !# Remove leading space at the start of the file 1g/^$/d !# Trivial non-text macros g/HYPERTEXTONLY(.*)/d g/GEMTEXTONLY(.*)/d g/LATEXONLY(.*)/d g/MANONLY(.*)/d g/EXCEPTHYPERTEXT(\(.*\))/s//\1/ g/EXCEPTGEMTEXT(\(.*\))/s//\1/ g/EXCEPTLATEX(\(.*\))/s//\1/ g/EXCEPTMAN(\(.*\))/s//\1/ g/END(DETAILS)/s//<\/details>/ g/DETAILS(\(.*\))/s//<details \1>/ g/END(.*)/d g/^<p[ >]/d g/^P(.*)/d g/FIG()/d g/INPUT(.*)/d !# Links g/A(\([^ ]*\), *\([^)]*\(([^)]*)\)*[^)]*)*\))/s//\2 <\1>/ g/AID(\([^ ]*\), *\([^ ]*\), \([^)]*\(([^)]*)\)*[^)]*)*\))/s//\3 <\1#\2>/ g/AHERE(\([^ ]*\), *\([^)]*\(([^)]*)\)*[^)]*)*\))/s//\2 <\1.txt>/ g/<a \([^:>=]*\)\.htm>\(.*\)<\/a>/s//\2 <\1.txt>/g g/<a \([^:>=]*\)\.htm#\([^>]*\)>\(.*\)<\/a>/s//\3 <\1.txt, #\2>/g g/<a href="*\(.*\)"*>\(.*\)<\/a>/s//\2 <\1>/g g|<a //\([^>]*\)>\(.*\)</a>|s||\2 <\1>|g g/<a #\([^>]*\)>\(.*\)<\/a>/s//\2 <#\1>/g g/<a \(...[^:=][^:=][^:=][^:=][^>]*\)>\(.*\)<\/a>/s//\2 <\1>/g !# Media g/<img.*src=\([^ ]*\).*alt=['"]\(.*\)['"]>/s//<\1> (\2)/ g/<img.*src=\([^ ]*\).*alt=\(.*\)>/s//<\1> (\2)/ g/<img \([^ ]*\) \(\([^"' ]* \)\{5,\}.*\)>/s//<\1> (\2)/ g/IMG(\([^ ]*\), *\(.*\))/s//<\1> (\2)/ g/PIC(\([^ ]*\), *\([^ ]*\), \(.*\))/s//<\1> (\3)/ g/AUDIO(\([^ ]*\), *\(.*\))/s//<\1>/ g/VIDEO(\([^ ]*\), *\(.*\))/s//<\1>/ !# Blocks g/FIGCAP(\(.*\))/s//— \1/ g/<\/figure \(.*\)>/s//— \1/ g/<figure/d g/<\/pre /s/<\/pre \(.*\)>/==================== \1 ====================/\ ?^<pre\(.*\)>?s//=================================== \1 ===================================/ g/PRE(\(.*\))/s//=================================== \1 ===================================/ g/PRECAP(\(.*\))/s//==================== \1 ====================/ g/BQ()/s//> / g/BQCAP(\(.*\))/s//— \1/ g/^<\/q \(.*\)>/?<q *\(.*\)>?,-1s/$/ /\ ?<q *\(.*\)>?,.j\ s/<q *\(.*\)> */> /\ s/ *$//\ +1s/<\/q *\(.*\)>/— \1/ !# Lists g/^ *D[DL](\(.*\))/s//\1:/g g/^ *[UO]*LI /s//• /g g/^ *[UO]L(\([^)]*\)) */s//• /g g/^\( *\)<[uo]l\([^>]*\)> *\(.\{1,\}\)/s//\1• \3/ g/^ *<dl\([^>]*\)> *\(.\{1,\}\)/s//\2:/ g/^ *<dt> *\(.*\)/s//\1:/ g/^ *<dd> */s// / g/<li[^>]*todo[^>]*checked[^>]*> */s//• [X] / g/<li[^>]*todo[^>]*> */s//• [ ] / g/^\( *\)<li[^>]*> */s//\1• / g/<\/*[uod]l>/d !# Minor markup g/CD(\([^)]*\(([^)]*)\)*[^)]*\))/s//`\1'/g g/VAR(\([^)]*\(([^)]*)\)*[^)]*\))/s//`\1'/g g/KBD(\([^)]*\(([^)]*)\)*[^)]*\))/s//<\1>/g g/EM(\([^)]*\(([^)]*)\)*[^)]*\))/s//*\1*/g g/<cd \([^>]*\)>/s//`\1'/g g/<c>\([^<]*\)<\/c>/s//`\1'/g g/<c>\([^ ,….!?—)]*\)/s//`\1'/g g/<del>\([^<]*\)<\/del>/s//+\1+/g g/<e \([^>]*\)>/s//*\1*/g g/<em>\([^<]*\)<\/em>/s//*\1*/g g/<spoiler>\([^<]*\)<\/spoiler>/s//(SPOILER!!! \1)/g !# Regular tables g/[[:space:]]*<tr> *<t[dh]> */s//| / g/[[:space:]]*<\/tr>[[:space:]]*/s/// g/ *<t[hd]> */s// | /g g/ *<caption>\(.*\)<\/caption>/s//— \1/ !# New tab-separated tables g/<table.* .*>/s/<table[[:space:]]*\(.*\)>$/<table >\ \1/ g/<table.* /.+1,/<\/table/-1s/^[[:space:]]*//g g/<table.* /.+1,/<\/table/-1s/ \{1,\}/ |/g g/<table.* /.+1,/<\/table/-1s/$/ |/g g/<table.* /.+1,/<\/table/-1s/^/|/g g/<\/table \(.*\)>/s//— \1/ g/<\/*table.*>/d !# Tables g/T[DH](\([^)]*\))/s//\1 |/ g/T[AR][OB](\(.*\))/s//|\1 |/ g/T[AR][OB]2(\([^,]*\), *\(.*\))/s//|\1 |\2 |/ g/T[AR][OB]3(\([^,]*\), *\([^,]*\), *\(.*\))/s//|\1 |\2 |\3 |/ g/T[AR][OB]4(\([^,]*\), *\([^,]*\), *\([^,]*\), *\(.*\))/s//|\1 |\2 |\3 |\4 |/ g/T[AR][OB]5(\([^,]*\), *\([^,]*\), *\([^,]*\), *\([^,]*\), *\(.*\))/s//|\1 |\2 |\3 |\4 |\5 |/ g/TABCAP(\(.*\))/s//— \1/ !# Sections g/SECTION2(\([^,]*\), *\(.*\))/s//<h2 \1>\2<\/h2>/ g/SECTION3(\([^,]*\), *\(.*\))/s//<h3 \1>\2<\/h3>/ g/SECTION4(\([^,]*\), *\(.*\))/s//<h4 \1>\2<\/h4>/ g/SECTION5(\([^,]*\), *\(.*\))/s//<h5 \1>\2<\/h5>/ g/SECTION6(\([^,]*\), *\(.*\))/s//<h6 \1>\2<\/h6> !# Headings with ID pre-capitalization: split ID g/<\(h[23456]\) *\([^ =>]\{1,\}\)>\(.*\)<\/\1>/s//<\1>\3\ (#\2)/ !# Headings: ALL CAPS g/<[Hh][23456]>.*š.*/s/š/Š/g g/<[Hh][23456]>.*č.*/s/č/Č/g g/<[Hh][23456]>.*ž.*/s/ž/Ž/g g/<[Hh][23456]>.*a.*/s/a/A/g g/<[Hh][23456]>.*b.*/s/b/B/g g/<[Hh][23456]>.*c.*/s/c/C/g g/<[Hh][23456]>.*d.*/s/d/D/g g/<[Hh][23456]>.*e.*/s/e/E/g g/<[Hh][23456]>.*f.*/s/f/F/g g/<[Hh][23456]>.*g.*/s/g/G/g g/<[Hh][23456]>.*i.*/s/i/I/g g/<[Hh][23456]>.*j.*/s/j/J/g g/<[Hh][23456]>.*k.*/s/k/K/g g/<[Hh][23456]>.*l.*/s/l/L/g g/<[Hh][23456]>.*m.*/s/m/M/g g/<[Hh][23456]>.*n.*/s/n/N/g g/<[Hh][23456]>.*o.*/s/o/O/g g/<[Hh][23456]>.*p.*/s/p/P/g g/<[Hh][23456]>.*q.*/s/q/Q/g g/<[Hh][23456]>.*r.*/s/r/R/g g/<[Hh][23456]>.*s.*/s/s/S/g g/<[Hh][23456]>.*t.*/s/t/T/g g/<[Hh][23456]>.*u.*/s/u/U/g g/<[Hh][23456]>.*v.*/s/v/V/g g/<[Hh][23456]>.*w.*/s/w/W/g g/<[Hh][23456]>.*x.*/s/x/X/g g/<[Hh][23456]>.*y.*/s/y/Y/g g/<[Hh][23456]>.*z.*/s/z/Z/g g/<[Hh][23456]>.*h.*/s/h/H/g g/^ (#[^)]*)/-1s/<[Hh][23456]>//\ j g|<details \([^=>]*\)>|.+1,/<\/details/-1s/^/ / g/<details \([^=>]*\)>/s//\1 {/ g/^[ ]\{1,\}$/s/.*// g/<\/details>/s//}/ g|<div class=note|.+1,/<\/div/-1s/^/ / g/<div class=note.*/s/<div class=note.*/note: {/\ /<\/div.*/s//}/ g/<hr>/s//HR()/ g/HR()/s//================================================================================/ !# Replace all kinds of char macros g/HASH()/s//#/g g/SQUOTE()/s//'/g g/DQUOTE()/s//"/g g/LT()/s//</g g/GT()/s//>/g g/AMP()/s//\&/g g/NUM()/s//#/g g/&[Nn][Uu][Mm];/s//#/g g/&[Aa][Pp][Oo][Ss];/s//'/g g/&[Qq][Uu][Oo][Tt];/s//"/g g/&[Ll][Tt];/s//</g g/&[Gg][Tt];/s//>/g g/&[Aa][Mm][Pp];/s//\&/g g/&[Pp][Ee][Rr][Cc][Nn][Tt];/s//\%/g g/<[Ww][Bb][Rr]>/s///g w Q