module HTML

Overview

Handles encoding and decoding of HTML entities.

Defined in:

html.cr

Constant Summary

SUBSTITUTIONS = {'!' => "&#33;", '"' => "&quot;", '$' => "&#36;", '%' => "&#37;", '&' => "&amp;", '\'' => "&#39;", '(' => "&#40;", ')' => "&#41;", '=' => "&#61;", '>' => "&gt;", '<' => "&lt;", '+' => "&#43;", '@' => "&#64;", '[' => "&#91;", ']' => "&#93;", '`' => "&#96;", '{' => "&#123;", '}' => "&#125;", ' ' => "&nbsp;"}

Class Method Summary

Class Method Detail

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

Encodes a string to HTML, but writes to the IO instance provided.

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

View source
def self.escape(string : String) : String #

Encodes a string with HTML entity substitutions.

require "html"

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

View source
def self.unescape(string : String) #

Decodes a string that contains HTML entities.

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

View source