W3cubDocs

/Crystal 0.31

module HTML

Overview

Provides HTML escaping and unescaping methods.

For HTML parsing see module XML, especially XML.parse_html.

Defined in:

html/entities.cr
html.cr

Class Method Summary

Class Method Detail

def self.escape(string : String, io : IO) : NilSource

Same as .escape(string) but ouputs the result to the given io.

require "html"

io = IO::Memory.new
HTML.escape("Crystal & You", io) # => nil
io.to_s                          # => "Crystal & You"

def self.escape(string : String) : StringSource

Escapes special characters in HTML, namely &, <, >, " and '.

require "html"

HTML.escape("Crystal & You") # => "Crystal &amp; You"

def self.unescape(string : String) : StringSource

Returns a string where named and numeric character references (e.g. >, >, &x3e;) in string are replaced with the corresponding unicode characters. This method decodes all HTML5 entities including those without a trailing semicolon (such as &copy).

require "html"

HTML.unescape("Crystal &amp; You") # => "Crystal & You"

© 2012–2019 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/0.31.1/HTML.html