std/html

HTML as the WHATWG standard reads it and as a program writes it, in TorbScript. The package has two sides.

The writing side is the markup builder: Html is a page or a piece of one, Markup is the receiver of the blocks that write it, and fragment and document start one. Every element is a var fn of Markup, so td "text", td class: "amount" { ... } and tr { ... } are the three shapes of one declaration. What a program writes is escaped where it is written: text, attribute values and attribute names can not break out of their place, and a URL attribute takes a Link, never a String.

const page = fragment {
  p class: "note" {
    text "Fish & chips"
  }
}
assert(page.render() == "<p class=\"note\">Fish &amp; chips</p>")

The reading side is the document side of the package: the tokenizer and the character references. HtmlTokenizer turns a text into HtmlTokens and says what is wrong with it as a list of HtmlParseErrors; reading HTML never fails, because the standard defines what to do with every mistake.

const result = HtmlTokenizer.tokenize("<p class=intro>Fish &amp; chips")
for token in result.tokens {
  print token
}

The tree comes in a later step: the tokens are what the tree construction reads, and the tokenizer exposes the switches that construction needs (the state to read the content of <script>, <style>, <textarea> and the like in, and whether a CDATA section is allowed).

Modules

Everything