std/html
import std/html to use it. Source: src/std/html.iyi at v0.18.0.
Provides escape for the five predefined entities and unescape for named, decimal numeric, and hexadecimal numeric references.
Named entity table decision: We implement the complete 253-entity standard HTML 4.01 and XML set (Latin-1, currency, Greek alphabet, mathematical symbols, punctuation, and markup). HTML5 expanded named entities to over 2,100 variants, predominantly duplicate obscure mathematical notation. The standard 253-entity set provides complete coverage for standard web documents and prose while remaining within the SPEC III footprint floor.
HTMLstruct
pub struct HTML
# Escapes the five predefined HTML characters:
# & -> &
# < -> <
# > -> >
# " -> "
# ' -> '
#
# Every other byte is copied as it is, by the run: writing each byte as a
# `Char` wrote a UTF-8 lead or continuation byte as the two-byte encoding
# of that code point, so "café" came out as "café".
def self.escape(string : String, io : IyiIO) : Nil
def self.escape(string : String) : String
def initialize
# Returns Unicode codepoint for standard HTML named entity, or -1 if unknown.
def self.named_entity_codepoint(name : String) : Int32
# Unescapes HTML character references.
# Handles:
# - 253 standard named entities (e.g. &, ©, €); only the
# legacy ones (&, ©, the other Latin-1 names) without the `;`
# - Decimal numeric entities (e.g. <)
# - Hexadecimal numeric entities (e.g. <, <)
# - Bare & that is not an entity is preserved unchanged
# - Unterminated entities are handled safely
# - Out of range numeric entities are replaced with U+FFFD
def self.unescape(string : String) : String
end
Standard HTML escaping and unescaping library for iyi.