module HTML
¶
Provides HTML escaping and unescaping methods.
For HTML parsing see module XML, especially XML.parse_html
.
Class methods¶
.escape(string : String, io : IO) : Nil
¶
(string : String, io : IO) : Nil
Same as escape(string)
but outputs the result to
the given io.
require "html"
io = IO::Memory.new
HTML.escape("Crystal & You", io) # => nil
io.to_s # => "Crystal & You"
.escape(string : String) : String
¶
(string : String) : String
Escapes special characters in HTML, namely
&
, <
, >
, "
and '
.
require "html"
HTML.escape("Crystal & You") # => "Crystal & You"
.unescape(string : String) : String
¶
(string : String) : String
Returns a string where named and numeric character references (e.g. >, >, >) in string are replaced with the corresponding unicode characters. This method decodes all HTML5 entities including those without a trailing semicolon (such as "©").
require "html"
HTML.unescape("Crystal & You") # => "Crystal & You"