pub fn parse(input: &str, config: &ParserConfig) -> ParseResultExamples found in repository?
examples/basic.rs (line 25)
4fn main() {
5 let config = build_config();
6 let samples = vec![
7 ("Inline span", "We shipped <cite id=\"1\">last week</cite>."),
8 (
9 "Retroactive cite",
10 "We shipped last week <cite id=1>. More info <note>soon",
11 ),
12 (
13 "Forward token",
14 "Risks: <risk level=high> load tests are late. <risk level=low>Docs slipping",
15 ),
16 (
17 "Self-closing markers",
18 "Todo list: <todo id=7/>finish rollout <todo/> update docs.",
19 ),
20 ];
21
22 for (label, input) in samples {
23 println!("=== {} ===", label);
24 println!("Original text:\n{}\n", input);
25 let parsed = parse(input, &config);
26 println!("Parsed text:\n{}\nSegments:", parsed.text);
27
28 for segment in &parsed.segments {
29 if segment.annotations.is_empty() {
30 println!("- '{}'", segment.text);
31 } else {
32 let anns: Vec<String> = segment
33 .annotations
34 .iter()
35 .map(|ann| {
36 let attrs = format_attrs(&ann.attrs);
37 if attrs.is_empty() {
38 ann.tag.clone()
39 } else {
40 format!("{} [{}]", ann.tag, attrs)
41 }
42 })
43 .collect();
44 println!("- '{}' ({})", segment.text, anns.join("; "));
45 }
46 }
47
48 if !parsed.markers.is_empty() {
49 println!("Markers:");
50 for marker in &parsed.markers {
51 let attrs = format_attrs(&marker.annotation.attrs);
52 let tag = if attrs.is_empty() {
53 marker.annotation.tag.clone()
54 } else {
55 format!("{} [{}]", marker.annotation.tag, attrs)
56 };
57 println!("- @{} {}", marker.pos, tag);
58 }
59 }
60
61 println!();
62 }
63}