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 & 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 & 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
std/html/elementsThe elements of the HTML standard as members of [Markup]: 110 of them, each with the global attributes and its own, typed.std/html/errorHtmlParseError: a recoverable error of the HTML standard, as the tokenizer reports it beside the tokens.std/html/html[fragment] and [document]: the two ways a block of markup becomes an [Html], and thescriptelement, which takes a file of the package and never aString.std/html/link[Link]: what an attribute that holds a URL takes (href,src,action,formaction,poster,cite).std/html/markup[Html], [Markup] and the pieces the generated element table writes with (docs/design/WEB.md section 4.2).std/html/stateThe states of the HTML tokenizer, [HtmlTokenizerState]: the 80 states of section 13.2.5 of the standard.std/html/tokenThe tokens of the HTML tokenizer: [HtmlToken] and the [HtmlAttribute] of a tag.std/html/tokenizer[HtmlTokenizer]: the tokenization stage of the HTML standard (section 13.2.5), as a state machine over the characters of a document.
Everything
- fn
documentA whole page:<!doctype html>, thenhtmlwith the language, aheadwith the character set, the viewport and the title, and abodythat holds what the block writes. - fn
fragmentThe markup the block writes, without a document around it: a part of a page, a component, the answer to a request for a piece of one. - type
HtmlA page, or part of one, rendered: the pieces of its markup. - type
HtmlAttributeOne attribute of a tag, in the order the document wrote it. - type
HtmlParseErrorA parse error of the HTML standard. - type
HtmlTokenOne token of the HTML standard's tokenizer (section 13.2.5), which the tree construction reads. - type
HtmlTokenizerThe tokenizer of the HTML standard. - type
HtmlTokenizerStateA state of the tokenizer, named as the standard names it with the words joined. - trait
LinkWhere a link points, as text that is safe to put into a URL attribute. - extend
Markup<Message>The elements of the HTML standard, onevar fneach; see the comment of this file. - extend
Markup<Message>The one element that is written by hand:script, whose source can not be aString. - type
MarkupThe receiver of the builder: the elements are its members (td "text",tr { ... }), andtextwrites text. - extend
Uri with LinkA [Uri] is a link when its scheme ishttp,httpsormailto; any other scheme isabout:invalid. - extend
UriReference with LinkA [UriReference] is a link when it is relative or its scheme ishttp,httpsormailto.