From 1d00e8997de1f6225d58f3838dc3a50e81fc4581 Mon Sep 17 00:00:00 2001 From: Greg Johnston Date: Wed, 5 Apr 2023 10:13:30 -0400 Subject: [PATCH 1/2] give access to closing tag in NodeElement --- src/node.rs | 2 ++ src/parser.rs | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/node.rs b/src/node.rs index 4d42494..268b04a 100644 --- a/src/node.rs +++ b/src/node.rs @@ -136,6 +136,8 @@ pub struct NodeElement { /// Note: This should cover the entire node in nightly, but is a "close /// enough" approximation in stable until [Span::join] is stabilized. pub span: Span, + /// Closing tag for the element, if it exists. + pub closing_tag: Option } impl fmt::Display for NodeElement { diff --git a/src/parser.rs b/src/parser.rs index 7d8336c..04e6303 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -192,6 +192,7 @@ impl Parser { let (name, attributes, self_closing, mut span) = self.tag_open(fork)?; let mut children = vec![]; + let mut closing_tag = None; if !self_closing { loop { if !self.element_has_children(&name, fork)? { @@ -201,8 +202,9 @@ impl Parser { children.append(&mut self.node(fork)?); } - let (_, closing_span) = self.tag_close(fork)?; + let (closing, closing_span) = self.tag_close(fork)?; span = span.join(closing_span).unwrap_or(span); + closing_tag = Some(closing); }; input.advance_to(fork); @@ -211,6 +213,7 @@ impl Parser { attributes, children, span, + closing_tag })) } From bc1cf17e5924b0782614e36d507958c6e046d9e5 Mon Sep 17 00:00:00 2001 From: Greg Johnston Date: Wed, 5 Apr 2023 10:17:12 -0400 Subject: [PATCH 2/2] `cargo fmt` --- src/node.rs | 2 +- src/parser.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/node.rs b/src/node.rs index 268b04a..3de3f44 100644 --- a/src/node.rs +++ b/src/node.rs @@ -137,7 +137,7 @@ pub struct NodeElement { /// enough" approximation in stable until [Span::join] is stabilized. pub span: Span, /// Closing tag for the element, if it exists. - pub closing_tag: Option + pub closing_tag: Option, } impl fmt::Display for NodeElement { diff --git a/src/parser.rs b/src/parser.rs index 04e6303..cd4f421 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -213,7 +213,7 @@ impl Parser { attributes, children, span, - closing_tag + closing_tag, })) }