///|
pub(all) enum StreamEvent {
StreamStart(StreamStartEvent) // open tag with name + attrs
StreamText(String) // decoded text (entities expanded)
StreamEnd(String) // close tag with name
StreamComment(String) // comment data, no delimiters
StreamDoctype(StreamDoctypeEvent)
}///|
test "readme stream basic" {
let events = @stream.stream("<p>Hello <b>World</b></p>")
debug_inspect(
events,
content=(
#|[
#| StreamStart({ name: "p", attrs: {} }),
#| StreamText("Hello "),
#| StreamStart({ name: "b", attrs: {} }),
#| StreamText("World"),
#| StreamEnd("b"),
#| StreamEnd("p"),
#|]
),
)
}///|
test "readme stream void and unmatched" {
debug_inspect(
@stream.stream("<br></div>"),
content=(
#|[StreamStart({ name: "br", attrs: {} }), StreamEnd("div")]
),
)
}///|
test "readme stream_bytes fallback" {
debug_inspect(
@stream.stream_bytes(b"<p>\x80</p>"),
content=(
#|[
#| StreamStart({ name: "p", attrs: {} }),
#| StreamText("€"),
#| StreamEnd("p"),
#|]
),
)
}///|
test "readme stream_each counts text events" {
let mut text_events = 0
@stream.stream_each("<p>a<b>b</b>c</p>", event => {
match event {
StreamText(_) => text_events = text_events + 1
_ => ()
}
})
assert_eq(text_events, 3)
}#deprecated("implicit derived-impl promotion; call the trait method directly")
fn StreamDoctypeEvent::equal(StreamDoctypeEvent, StreamDoctypeEvent) -> Bool#deprecated("implicit derived-impl promotion; call the trait method directly")
fn StreamDoctypeEvent::not_equal(x : StreamDoctypeEvent, y : StreamDoctypeEvent) -> Bool#deprecated("implicit derived-impl promotion; call the trait method directly")
fn StreamDoctypeEvent::to_repr(StreamDoctypeEvent) -> Reprpub(all) enum StreamEvent {
StreamStart(StreamStartEvent)
StreamText(String)
StreamEnd(String)
StreamComment(String)
StreamDoctype(StreamDoctypeEvent)
} derive(Eq, Debug)#deprecated("implicit derived-impl promotion; call the trait method directly")
fn StreamEvent::equal(StreamEvent, StreamEvent) -> Bool#deprecated("implicit derived-impl promotion; call the trait method directly")
fn StreamEvent::not_equal(x : StreamEvent, y : StreamEvent) -> Bool#deprecated("implicit derived-impl promotion; call the trait method directly")
fn StreamEvent::to_repr(StreamEvent) -> Repr#deprecated("implicit derived-impl promotion; call the trait method directly")
fn StreamSink::to_repr(StreamSink) -> Repr#deprecated("implicit derived-impl promotion; call the trait method directly")
fn StreamStartEvent::equal(StreamStartEvent, StreamStartEvent) -> Bool#deprecated("implicit derived-impl promotion; call the trait method directly")
fn StreamStartEvent::not_equal(x : StreamStartEvent, y : StreamStartEvent) -> Bool#deprecated("implicit derived-impl promotion; call the trait method directly")
fn StreamStartEvent::to_repr(StreamStartEvent) -> ReprInstall
Download zipMoonBit HTML parser and sanitizer ported from JustHTML.
Dependencies