/usr/share/elvis/scripts/makehtml.ex is in elvis-common 2.2.0-11.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | " Defines makehtml alias to convert plain text to HTLM source
alias makehtml {
"Convert plain text to HTML source
local report=0 m=text n=text b=false magic magicchar=^$.[* noignorecase
"
" m is current line mode -- one of "text", "pre", "ol", or "ul"
" n is next line mode
" b is a flag for detecting series of blank lines.
"
" For each line...
!%g /^/ {
" Protect characters which are special to HTML
try s/&/\&/g
try s/</\</g
try s/>/\>/g
"
" Convert uppercase lines into headings
try s/^[A-Z0-9][A-Z0-9-.) ]*$/<h1>&<\/h1>/
then set n=text
"
" Convert horizontal lines into <hr> tags
try s/^\s*[-=]\{10,}\s*$/<hr>/
then set n=text
"
" Try to be clever about finding links
try s/http:[^">, )]\+/<a href="&">&<\/a>/g
try s/ftp:[^">, )]\+/<a href="&">&<\/a>/g
try s/[a-zA-Z]\w*@[a-zA-Z][[:alnum:].-]\+/<a href="mailto:&">&<\/a>/g
"
" Convert asterisked lines into "ul" list items.
try s/^\s*\* */<li>
then set n=ul
else {
if m=="ul"
then try s/^[^* ]/set n=text/x
}
"
" Convert numbered lines (other than headings) into "ol" list items.
try s/^\s*\d\+[.)] */<li>
then set n=ol
else {
if m=="ol"
then try s/^[^0-9 ]/set n=text/x
}
"
" if in normal text, then assume indented text is preformatted.
if n=="text"
then try s/^\s/set n=pre/x
"
" if in preformatted mode, then unindented lines revert to text mode
if m=="pre" && n=="pre"
then try s/^\S/set n=text/x
"
" Any non-blank line turns off the "b" flag.
try s/./set b=false/x
"
" if not in preformatted text, then blank lines are paragraph breaks.
" Avoid consecutive <p> tags, though.
if m!="pre" && b=="false"
then {
try s/^$/<p>/
then set b=true
}
"
" if mode switched, then add tags for that.
if m!=n
then {
if m!="text"
then eval i </(m)>
if n!="text"
then eval i <(n)>
let m=n
set b=false
}
}
"
" if not in text mode, then terminate the mode
if m != "text"
then eval !> a </(m)>
"
" If converting the whole file, then add <html>...</html>
if "!%" == ""
then {
$a </body></html>
eval 1i <html><head><title>(htmlsafe(filename))</title></head><body>
"
" minor conveniences...
set bufdisplay=html mapmode=html
display html
if filename != "" && tolower(dirext(filename) << 4) != ".htm"
then eval file (dirdir(filename)/basename(filename)).html
}
}
|