about summary refs log tree commit diff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorgennyble <gen@nyble.dev>2024-12-18 00:27:34 -0600
committergennyble <gen@nyble.dev>2024-12-18 00:27:34 -0600
commit5ea6a13ead2a5cab0f578c8af5f0e0be88c3a08c (patch)
treef8ab97a0abeb03142da4c7a8ed859d6a408cd16a /src/lib.rs
parentf6b441fe53dd75af5933c4456d92070ccb7bd8af (diff)
downloadcutie-5ea6a13ead2a5cab0f578c8af5f0e0be88c3a08c.tar.gz
cutie-5ea6a13ead2a5cab0f578c8af5f0e0be88c3a08c.zip
Ahhhhh HEAD main
Diffstat (limited to 'src/lib.rs')
-rwxr-xr-x[-rw-r--r--]src/lib.rs29
1 files changed, 25 insertions, 4 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 8b5c47d..bc8b629 100644..100755
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -87,6 +87,31 @@ impl Html {
 		None
 	}
 
+	pub fn get_by_id(&self, id: &str) -> Option<&Tag> {
+		// depth first
+		fn find_node<'a>(tag: &'a Tag, id: &str) -> Option<&'a Tag> {
+			if tag.id().unwrap_or_default() == id {
+				return Some(tag);
+			}
+
+			for child in tag.child_tags() {
+				if let Some(tag) = find_node(child, id) {
+					return Some(tag);
+				}
+			}
+
+			None
+		}
+
+		for child in self.child_tags() {
+			if let Some(tag) = find_node(child, id) {
+				return Some(tag);
+			}
+		}
+
+		None
+	}
+
 	fn parse_node(raw: &str) -> Consumed {
 		match Self::is_tag(raw) {
 			Some(_) => {
@@ -133,14 +158,11 @@ impl Html {
 			};
 		}
 
-		println!("Looking for {}", root_tag.name);
-
 		loop {
 			// Special case <script> and <style>
 			if root_tag.name == "script" && tag.get_attribute("src").is_none()
 				|| root_tag.name == "style"
 			{
-				println!("\tparse special");
 				let special = Self::special_parse(rest.unwrap(), root_tag.name);
 
 				match special {
@@ -166,7 +188,6 @@ impl Html {
 			// Find the closing end of out root_tag
 			if let Some((parsed, remaining)) = Self::is_tag(rest.unwrap()) {
 				if parsed.closing && parsed.name == root_tag.name {
-					println!("\tclosed {}", parsed.name);
 					break Consumed {
 						node: Node::Tag(tag),
 						remaining,