### Parsing HTML and Getting Element by ID (Rust) Source: https://github.com/y21/tl/blob/master/README.md Demonstrates parsing an HTML string using `tl::parse` and retrieving an element by its ID using `get_element_by_id`. It then accesses the element's inner text. ```Rust let dom = tl::parse(r#"
Hello
"#, tl::ParserOptions::default()).unwrap(); let parser = dom.parser(); let element = dom.get_element_by_id("text") .expect("Failed to find element") .get(parser) .unwrap(); assert_eq!(element.inner_text(parser), "Hello"); ``` -------------------------------- ### Mutating Anchor Tag href Attribute (Rust) Source: https://github.com/y21/tl/blob/master/README.md Demonstrates how to modify an attribute of a tag in the DOM. It finds an anchor tag using a query selector, gets a mutable reference to it, and updates its `href` attribute value. ```Rust let input = r#""#; let mut dom = tl::parse(input, tl::ParserOptions::default()) .expect("HTML string too long"); let anchor = dom.query_selector("a[href]") .expect("Failed to parse query selector") .next() .expect("Failed to find anchor tag"); let parser_mut = dom.parser_mut(); let anchor = anchor.get_mut(parser_mut) .expect("Failed to resolve node") .as_tag_mut() .expect("Failed to cast Node to HTMLTag"); let attributes = anchor.attributes_mut(); attributes.get_mut("href") .flatten() .expect("Attribute not found or malformed") .set("http://localhost/about"); assert_eq!(attributes.get("href").flatten(), Some(&"http://localhost/about".into())); ``` -------------------------------- ### Finding Tag Using Query Selector (Rust) Source: https://github.com/y21/tl/blob/master/README.md Shows how to use the CSS query selector API (`query_selector`) to find a specific tag (an `
