From 7b29f709893598d760fe2d4938e9bdc76423fb5d Mon Sep 17 00:00:00 2001 From: gennyble Date: Wed, 27 Dec 2023 15:50:30 -0600 Subject: refactor Tag to it's own struct --- src/lib.rs | 146 +++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 83 insertions(+), 63 deletions(-) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index 36a9075..b766109 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -39,8 +39,20 @@ impl Html { fn parse_tag(raw: &str) -> Consumed { let (root_tag, mut rest) = Self::is_tag(raw).unwrap(); + let mut tag = if root_tag.body.is_empty() { + Tag { + name: root_tag.name.to_owned(), + body: None, + children: vec![], + } + } else { + Tag { + name: root_tag.name.into(), + body: Some(root_tag.body.to_owned()), + children: vec![], + } + }; - //println!("- {raw}"); if root_tag.closing { panic!( "found closing tag when not expected! {:?}\n{raw}", @@ -48,17 +60,11 @@ impl Html { ) } else if root_tag.self_closing { return Consumed { - node: Node::Tag { - self_closing: true, - name: root_tag.name.into(), - children: vec![], - }, + node: Node::Tag(tag), remaining: rest, }; } - let mut children = vec![]; - loop { // Special case