Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give access to closing tag in NodeElement #52

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<NodeName>,
}

impl fmt::Display for NodeElement {
Expand Down
5 changes: 4 additions & 1 deletion src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)? {
Expand All @@ -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);
Expand All @@ -211,6 +213,7 @@ impl Parser {
attributes,
children,
span,
closing_tag,
}))
}

Expand Down