///|
test "readme tokenize hello" {
let result = @tokenizer.tokenize("<p class='hi'>Hello</p>")
debug_inspect(
result.tokens,
content=(
#|[
#| Tag(
#| {
#| kind: StartTag,
#| name: "p",
#| attrs: { "class": Some("hi") },
#| self_closing: false,
#| },
#| ),
#| Characters("Hello"),
#| Tag({ kind: EndTag, name: "p", attrs: {}, self_closing: false }),
#| Eof,
#|]
),
)
}///|
pub(all) enum HtmlToken {
Tag(TagToken)
Characters(String)
CommentToken(String)
DoctypeToken(DoctypeInfo)
Eof
}///|
test "readme tokenize collect errors" {
let result = @tokenizer.tokenize("<div a=>", collect_errors=true)
debug_inspect(
result,
content=(
#|{
#| tokens: [
#| Tag(
#| {
#| kind: StartTag,
#| name: "div",
#| attrs: { "a": Some("") },
#| self_closing: false,
#| },
#| ),
#| Eof,
#| ],
#| errors: [
#| {
#| code: "missing-attribute-value",
#| line: Some(1),
#| column: Some(8),
#| category: "tokenizer",
#| message: "missing-attribute-value",
#| },
#| ],
#|}
),
)
}///|
test "readme decode entities" {
let decoded = @tokenizer.decode_entities(
"Tom & Jerry & friends",
in_attribute=false,
)
debug_inspect(
decoded,
content=(
#|"Tom & Jerry & friends"
),
)
}///|
test "readme tokenize_each counts tags" {
let mut start_tags = 0
@tokenizer.tokenize_each("<p>one</p><p>two</p>", token => {
match token {
Tag({ kind: StartTag, .. }) => start_tags = start_tags + 1
_ => ()
}
})
assert_eq(start_tags, 2)
}#deprecated("implicit derived-impl promotion; call the trait method directly")
fn DoctypeInfo::equal(DoctypeInfo, DoctypeInfo) -> Bool#deprecated("implicit derived-impl promotion; call the trait method directly")
fn DoctypeInfo::not_equal(x : DoctypeInfo, y : DoctypeInfo) -> Bool#deprecated("implicit derived-impl promotion; call the trait method directly")
fn DoctypeInfo::to_repr(DoctypeInfo) -> Reprpub(all) enum HtmlToken {
Tag(TagToken)
Characters(String)
CommentToken(String)
DoctypeToken(DoctypeInfo)
Eof
} derive(Eq, Debug)#deprecated("implicit derived-impl promotion; call the trait method directly")
fn TokenizedHtml::to_repr(TokenizedHtml) -> Reprfn decode_entities(input : StringView, in_attribute~ : Bool) -> StringInstall
Download zipMoonBit HTML parser and sanitizer ported from JustHTML.
Dependencies