aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/spans.rs13
1 files changed, 8 insertions, 5 deletions
diff --git a/examples/spans.rs b/examples/spans.rs
index c1fe23b..b8d5283 100644
--- a/examples/spans.rs
+++ b/examples/spans.rs
@@ -4,14 +4,14 @@ use codespan_reporting::{
term,
term::termcolor::{ColorChoice, StandardStream},
};
-use html5tokenizer::{offset::PosTrackingReader, NaiveParser, Token, TracingEmitter};
+use html5tokenizer::{offset::PosTrackingReader, trace::Trace, NaiveParser, Token, TracingEmitter};
fn main() {
let html = r#"<img src=example.jpg alt="some description">"#;
let parser =
NaiveParser::new_with_emitter(PosTrackingReader::new(html), TracingEmitter::default());
- let Token::StartTag(tag) = parser.flatten().next().unwrap() else {
+ let (Token::StartTag(tag), Trace::StartTag(trace)) = parser.flatten().next().unwrap() else {
panic!()
};
@@ -20,11 +20,14 @@ fn main() {
let mut labels = Vec::new();
- labels.push(Label::primary(file_id, tag.name_span).with_message("tag name"));
+ labels.push(Label::primary(file_id, trace.name_span).with_message("tag name"));
for attr in &tag.attributes {
- labels.push(Label::primary(file_id, attr.name_span()).with_message("attr name"));
- labels.push(Label::primary(file_id, attr.value_span().unwrap()).with_message("attr value"));
+ let attr_trace = &trace.attribute_traces[attr.trace_idx().unwrap()];
+ labels.push(Label::primary(file_id, attr_trace.name_span()).with_message("attr name"));
+ labels.push(
+ Label::primary(file_id, attr_trace.value_span().unwrap()).with_message("attr value"),
+ );
}
let diagnostic = Diagnostic::note().with_labels(labels);