// Utilities for HTML manipulation.
HTMLEncode[line] :=
{
line =~ %s/&/&/g;
line =~ %s/</g;
line =~ %s/>/>/g;
return line
}
// Decodes the hex-encoded parts of an argument.
URLDecode[arg] :=
{
return arg =~ %s/%([0-9a-fA-F]{2})/char[parseInt[$1, 16]]/ge
}
// Make the tags for an HTML list, with the specified
// item selected.
// makeselect[list, selected]
makeSelect[list, selected] :=
{
for [name, val] list
{
if (val != undef) // Has value
{
vs = "$val" // Coerce to string
valStr = (val != undef) ? " VALUE=\"" + HTMLEncode[vs] + "\"" : ""
sel = (vs == selected ? " SELECTED" : "")
} else
sel = (name == selected ? " SELECTED" : "")
println[" " + HTMLEncode["$name"]]
}
}
// Format a Frink expression into a prettier HTML equivalent.
formatExpression[expr] :=
{
expr =~ %s/\^([\/\d\w\.\-]+)/$1<\/SUP>/g // Draw superscripts
expr =~ %s/\+(\s*)-\s*1\s+/-$1/g; // "+ -1" goes to "-"
expr =~ %s/\+(\s*)-/-$1/g; // "+ -" goes to "-"
return expr
}
// Format an expression using some symbolic rules.
formatExpressionSymbolic[expr] :=
{
expr = formatExpression[expr]
return removeApproximations[expr]
}
// Remove approximations
removeApproximations[expr] :=
{
expr =~ %s/\s*\((approx\.|exactly).*?\)//g
return expr
}