iyi

Standard library, 0.18.0

std/html

Standard HTML escaping and unescaping library for iyi.

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

std/htmliyi doc src/std/html.iyi
pub struct HTML
  # Escapes the five predefined HTML characters:
  # &  -> &
  # <  -> &lt;
  # >  -> &gt;
  # "  -> &quot;
  # ' -> &#39;
  #
  # 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. &amp;, &copy;, &euro;); only the
  #   legacy ones (&amp, &copy, the other Latin-1 names) without the `;`
  # - Decimal numeric entities (e.g. &#60;)
  # - Hexadecimal numeric entities (e.g. &#x3c;, &#X3C;)
  # - 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