///|
test "readme parse hello" {
let doc = @parser.parse("<p>hi</p>")
inspect(
@ser.to_html(doc.root, pretty=true),
content=(
#|<html>
#| <head></head>
#| <body>
#| <p>hi</p>
#| </body>
#|</html>
),
)
}///|
test "readme parse head routing" {
let doc = @parser.parse("<meta charset=utf-8><title>T</title><p>x</p>")
inspect(
@ser.to_html(doc.root, pretty=true),
content=(
#|<html>
#| <head>
#| <meta charset="utf-8">
#| <title>T</title>
#| </head>
#| <body>
#| <p>x</p>
#| </body>
#|</html>
),
)
}///|
test "readme parse_fragment basic" {
let doc = @parser.parse_fragment("<p>hello <b>world</b></p>")
inspect(
@ser.to_html(doc.root, pretty=false),
content=(
#|<p>hello <b>world</b></p>
),
)
}///|
///|
test "readme parse_fragment table context" {
let doc = @parser.parse_fragment(
"<tr><td>x</td></tr>",
context=FragmentContext("table"),
)
inspect(
@ser.to_html(doc.root, pretty=true),
content=(
#|<tbody>
#| <tr>
#| <td>x</td>
#| </tr>
#|</tbody>
),
)
}///|
test "readme parse_bytes fallback" {
let doc = @parser.parse_bytes(b"<p>\x80</p>")
debug_inspect(
(doc.encoding, @ser.to_html(doc.root, pretty=false)),
content=(
#|(
#| Some("windows-1252"),
#| "<html><head></head><body><p>€</p></body></html>",
#|)
),
)
}///|
test "readme parse collect_errors" {
let doc = @parser.parse_fragment("<p>hi</span></p>", collect_errors=true)
debug_inspect(
doc.errors,
content=(
#|[
#| {
#| code: "unexpected-end-tag",
#| line: Some(1),
#| column: Some(12),
#| category: "treebuilder",
#| message: "unexpected-end-tag",
#| },
#|]
),
)
}///|
test "readme parsed query and to_markdown" {
let doc = @parser.parse_fragment(
"<h1>Title</h1><p class='lede'>Hello <b>MoonBit</b></p>",
)
inspect(
doc.query(".lede").length(),
content=(
#|1
),
)
inspect(
doc.to_markdown(),
content=(
#|# Title
#|
#|Hello **MoonBit**
),
)
}#deprecated("implicit derived-impl promotion; call the trait method directly")
fn FragmentContext::equal(FragmentContext, FragmentContext) -> Bool#deprecated("implicit derived-impl promotion; call the trait method directly")
fn FragmentContext::not_equal(x : FragmentContext, y : FragmentContext) -> Bool#deprecated("implicit derived-impl promotion; call the trait method directly")
fn FragmentContext::to_repr(FragmentContext) -> Reprfn ParsedHtml::to_html(self : ParsedHtml, pretty? : Bool, indent_size? : Int, context? : HtmlContext, quote? : Char) -> String raise HtmlError#deprecated("implicit derived-impl promotion; call the trait method directly")
fn ParsedHtml::to_repr(ParsedHtml) -> Reprfn ParsedHtml::to_text(self : ParsedHtml, separator? : String, strip? : Bool, separator_blocks_only? : Bool) -> Stringfn parse(html : StringView, sanitize? : Bool, collect_errors? : Bool, strict? : Bool, scripting_enabled? : Bool, xml_coercion? : Bool, track_node_locations? : Bool, iframe_srcdoc? : Bool) -> ParsedHtml raise HtmlErrorfn parse_bytes(input : BytesView, encoding? : String, sanitize? : Bool, collect_errors? : Bool, strict? : Bool, scripting_enabled? : Bool, xml_coercion? : Bool, track_node_locations? : Bool, iframe_srcdoc? : Bool) -> ParsedHtml raise HtmlErrorfn parse_fragment(html : StringView, context? : FragmentContext, sanitize? : Bool, collect_errors? : Bool, strict? : Bool, scripting_enabled? : Bool, xml_coercion? : Bool, track_node_locations? : Bool, iframe_srcdoc? : Bool) -> ParsedHtml raise HtmlErrorInstall
Download zipMoonBit HTML parser and sanitizer ported from JustHTML.
Dependencies