Method deprecated or moved
This method is deprecated or moved on the latest stable version.
The last existing version (v1_9_3_392) is shown here.
pretty(string, shift = " ")
public
Prettify (indent) an HTML string.
string is the HTML string
to indent. shift is the indentation unit to use; it defaults to
two spaces.
print CGI::pretty("<HTML><BODY></BODY></HTML>")
print CGI::pretty("<HTML><BODY></BODY></HTML>", "\t")
# File lib/cgi/util.rb, line 184
def CGI::pretty(string, shift = " ")
lines = string.gsub(/(?!\A)<.*?>/, "\n\\0").gsub(/<.*?>(?!\n)/, "\\0\n")
end_pos = 0
while end_pos = lines.index(/^<\/(\w+)/, end_pos)
element = $1.dup
start_pos = lines.rindex(/^\s*<#{element}/, end_pos)
lines[start_pos ... end_pos] = "__" + lines[start_pos ... end_pos].gsub(/\n(?!\z)/, "\n" + shift) + "__"
end
lines.gsub(/^((?:#{Regexp::quote(shift)})*)__(?=<\/?\w)/, '\1')
end