3 HTML Syntax Objects
An HTML syntax object encodes an HTML document as a human-readable shrubbery form represented by a Rhombus syntax object. The html.from_syntax function converts an HTML syntax object to a html.Document, and html.to_syntax goes in the other direction. HTML syntax objects can be produced from HTML directly with html.read_syntax, html.string_to_syntax, and html.bytes_to_syntax, and they can converted to XML directly with html.write_syntax, html.syntax_to_string, and html.syntax_to_bytes. HTML syntax objects are similar to XML syntax objects as supported by the xml library.
The html.syntax form is essentially an alias of '' (see #%quotes), but it checks that the result syntax object conforms to HTML syntax object constraints.
def my_doc:
html.syntax:
head:
title:
"Greeting"
body:
h1:
"Hello, World!"
div:
~class: "main"
"Today is sometime after "
> html.write_syntax(my_doc)
<head><title>Greeting</title></head
><body><h1>Hello, World!</h1
><div class="main">Today is sometime after 1970-01-01</div
></body
>
expression | ||||||||||||||||||||||||
| ||||||||||||||||||||||||
| ||||||||||||||||||||||||
| ||||||||||||||||||||||||
| ||||||||||||||||||||||||
| ||||||||||||||||||||||||
| ||||||||||||||||||||||||
|
An element corresponds to an html.Element. It always starts with an identifier, and it is followed by a block (possibly empty) for the element’s attributes and content. The attributes must appear first, where each attribute starts with a keyword and is followed by a block for the attribute’s value, together corresponding to html.Attribute.
Each content can be one the following:
string: Used directly as string content.
content ..., (content, ...), or [content, ...]: Content can be spliced from multiple content forms with a group, within parentheses, or within square brackets. Note that this splicing accommodates @ forms, as in the example below.
other: Any value that is satisfies html.Content is allowed. For example, a html.Comment value can appear here. Constructing such objects will require a $ escape with Syntax.inject.
> html.write_syntax(
html.syntax:
a: "hello <name>"
)
<a>hello <name></a>
> html.write_syntax(
html.syntax:
a: ("b", "c", [["d"], "e"])
)
<a>bcde</a>
> html.write_syntax(
html.syntax:
a: @{say this: "hello <name>"}
)
<a>say this: "hello <name>"</a>
> html.write_syntax(
html.syntax:
a: $(Syntax.inject(html.Comment(~data: "123")))
)
<a><!-- 123 --></a>
function | |||
| |||
| |||
function | |||
function | |||||
| |||||
| |||||
function | |||||
|
function | ||||
| ||||
| ||||
function | ||||
| ||||
| ||||
function | ||||
| ||||
| ||||
function | ||||
|