Parsers for HTML syntax #
Compliant with the HTML living standard to the extent that it makes sense. Departures are documented on the appropriate parsers.
We eschew Lean's standard mechanism of syntactic categories in favor of hand-rolled parsers, formatters, and parenthesizers for two reasons:
Lean parsers generally consume trailing whitespace, whereas certain HTML parsers (e.g. end tag
>symbols) should not do so, so that this whitespace is instead included in text content following those parsers.Category parsing inspects the leading token and dispatches to the appropriate parser whereas we allow text contents to begin with reserved symbols such as
'.
In content, all whitespace is preserved by parsers, and then collapsed in
Content.view.To simplify away special handling of
$, most parsers here cannot be antiquoted. Parsers that can be antiquoted are documented as such.The docstrings of certain parsers are shown in IDEs on hover. These parsers may contain additional, non-docstring comments describing non-user-facing implementation details.
Helpers #
Character references #
Decodes one character reference starting at i,
which must point at at the character & in s.
Returns the decoded string, and the position just after ;.
Errors are reported at refAt,
which should produce the subsyntax between two offsets into s.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Decodes HTML character references in ref, leaving other characters unchanged.
Equations
Instances For
Raw symbols #
Parses sym as an atom.
Unlike symbol, this parser does not consult the token table,
and sym is not registered as a token.
Trailing whitespace (including Lean-style comments) is consumed and stored in the atom
only if trailingWs is set; otherwise it is left to the next parser.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Interpolations #
Parses an interpolation: a Lean term between openSym and }.
Trailing whitespace is consumed only if trailingWs is set.
Equations
- Lean.Html.Syntax.interpWith kind openSym trailingWs = Lean.Parser.node kind (Lean.Html.Syntax.rawSymbol openSym true >> Lean.Parser.termParser >> Lean.Html.Syntax.rawSymbol "}" trailingWs)
Instances For
Equations
- Lean.Html.Syntax.interp trailingWs = Lean.Html.Syntax.interpWith `Lean.Html.Syntax.interp "{" trailingWs
Instances For
Equations
- Lean.Html.Syntax.interpMany trailingWs = Lean.Html.Syntax.interpWith `Lean.Html.Syntax.interpMany "{..." trailingWs
Instances For
Equations
- Lean.Html.Syntax.Interp isMany = Lean.TSyntax (Lean.Html.Syntax.interpKind isMany)
Instances For
Equations
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Equations
Equations
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Instances For
Text content #
Equations
- One or more equations did not get rendered due to their size.
Instances For
Instances For
Comments #
An HTML comment.
Equations
- Lean.Html.Syntax.comment = { info := Lean.Parser.nodeInfo `Lean.Html.Syntax.comment { }, fn := Lean.Parser.nodeFn `Lean.Html.Syntax.comment (Lean.Parser.rawFn Lean.Html.Syntax.commentFn✝) }
Instances For
Instances For
Text contents of an HTML comment, excluding start and end markers.
Equations
- x✝.view = match x✝ with | { raw := Lean.Syntax.node info kind #[Lean.Syntax.atom info_1 s] } => pure ((s.drop 4).dropEnd 3).toString | x => Lean.Elab.throwUnsupportedSyntax
Instances For
Tag names #
An HTML tag name:
an ASCII letter followed by characters other than ASCII whitespace, U+0000 NULL, /, >.
This includes custom element names.
Equations
- Lean.Html.Syntax.tagName = Lean.Html.Syntax.parseFirstMany✝ `Lean.Html.Syntax.tagName "tag name" Char.isAlpha Lean.Html.Syntax.tagName.isTagNameChar✝
Instances For
Instances For
Instances For
Attribute names #
An HTML attribute name.
Attribute names may not start with { (which would conflict with interpolation).
Equations
- Lean.Html.Syntax.attrName = Lean.Html.Syntax.parseFirstMany✝ `Lean.Html.Syntax.attrName "attribute name" Lean.Html.Syntax.attrName.isAttrNameFirstChar✝ Lean.Html.Syntax.attrName.isAttrNameChar✝
Instances For
Equations
- Lean.Html.Syntax.attrNameKind = `Lean.Html.Syntax.attrName
Instances For
Instances For
Instances For
Attribute values #
Equations
- Lean.Html.Syntax.attrVal = Lean.Parser.node `Lean.Html.Syntax.attrVal (Lean.Parser.strLit <|> Lean.Html.Syntax.interp true)
Instances For
Instances For
- str (stx : TSyntax `str) : AttrValView
A string literal. Character references in the literal must be decoded before use (via
decodeCharacterReferences). - interp (stx : Interp false) : AttrValView
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Equations
Equations
- Lean.Html.Syntax.instBEqAttrValView.beq (Lean.Html.Syntax.AttrValView.str a) (Lean.Html.Syntax.AttrValView.str b) = (a == b)
- Lean.Html.Syntax.instBEqAttrValView.beq (Lean.Html.Syntax.AttrValView.interp a) (Lean.Html.Syntax.AttrValView.interp b) = (a == b)
- Lean.Html.Syntax.instBEqAttrValView.beq x✝¹ x✝ = false
Instances For
Equations
Provides a view on the attribute value, decoding character references when the value is a string literal.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Instances For
Attributes #
An HTML attribute.
We support double-quoted attribute values <tag name="val">,
empty attributes <tag name>,
interpolations of one value <tag name={ term }>,
and interpolations of a sequence of attributes <tag {... term }/>.
Character references are decoded in double-quoted values.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Equations
Equations
Equations
Instances For
Equations
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Equations
Equations
- One or more equations did not get rendered due to their size.
- Lean.Html.Syntax.instBEqAttrView.beq (Lean.Html.Syntax.AttrView.val a) (Lean.Html.Syntax.AttrView.val b) = (a == b)
- Lean.Html.Syntax.instBEqAttrView.beq (Lean.Html.Syntax.AttrView.bool a) (Lean.Html.Syntax.AttrView.bool b) = (a == b)
- Lean.Html.Syntax.instBEqAttrView.beq x✝¹ x✝ = false
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Instances For
Elements and content #
Content is not a syntax category because a category parser starts by reading a Lean token,
which fails on text that begins with whitespace or, for example, '.
Instead, contentItemFn dispatches to item parsers based on the next character.
Instances For
A sequence of HTML text nodes, comments, elements, and interpolations.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Equations
Instances For
Equations
Equations
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Equations
Equations
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
An HTML element:
<tag attr*/> or <tag attr*>content</tag>.
Tags must be closed: void element syntax such as <br>,
and implied end tags such as <ul><li>item</ul>,
are not supported.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Equations
- Lean.Html.Syntax.instBEqTextCommentsView.beq { stxs := a } { stxs := b } = (a == b)
- Lean.Html.Syntax.instBEqTextCommentsView.beq x✝¹ x✝ = false
Instances For
Returns the normalized text contents of this sequence of text nodes and comments:
Whitespace that contains a newline (U+000A or U+000D), and is not surrounded by text on both sides, is removed.
Other consecutive whitespace is collapsed into a single space (U+0020).
HTML character references are decoded into the Unicode characters they represent.
Throws if an invalid character reference is encountered in the text.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A syntax spanning all nodes in this view. Useful for reporting elaboration errors.
Equations
Instances For
- element (stx : Element) : ContentItemView
- textComments (stx : TextCommentsView) : ContentItemView
- interp (isMany : Bool) (stx : Interp isMany) : ContentItemView
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Equations
- One or more equations did not get rendered due to their size.
- Lean.Html.Syntax.instBEqContentItemView.beq (Lean.Html.Syntax.ContentItemView.element a) (Lean.Html.Syntax.ContentItemView.element b) = (a == b)
- Lean.Html.Syntax.instBEqContentItemView.beq (Lean.Html.Syntax.ContentItemView.textComments a) (Lean.Html.Syntax.ContentItemView.textComments b) = (a == b)
- Lean.Html.Syntax.instBEqContentItemView.beq x✝¹ x✝ = false
Instances For
Returns the sequence of items in an HTML content node.
Runs of text interspersed with comments are merged into a single item.
This is because their text must be processed together into a single output
(see TextCommentsView.getText).
Equations
- One or more equations did not get rendered due to their size.
Instances For
An HTML literal.
Equations
- One or more equations did not get rendered due to their size.