use super::*;
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
pub struct TextNode<'a> {
pub text: &'a str,
#[cfg_attr(feature = "serde", serde(skip))]
pub span: Span,
}
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
pub struct CommentNode<'a> {
pub comment: &'a str,
#[cfg_attr(feature = "serde", serde(skip))]
pub span: Span,
}
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
pub struct DoctypeNode<'a> {
pub name: &'a str,
#[cfg_attr(feature = "serde", serde(skip))]
pub name_span: Span,
pub attributes: Vec<Attribute<'a>>,
#[cfg_attr(feature = "serde", serde(skip))]
pub span: Span,
}
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
pub struct ProcessingInstructionNode<'a> {
pub target: &'a str,
#[cfg_attr(feature = "serde", serde(skip))]
pub target_span: Span,
pub data: Vec<Attribute<'a>>,
#[cfg_attr(feature = "serde", serde(skip))]
pub span: Span,
}
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[cfg_attr(feature = "serde", serde(untagged))]
pub enum Node<'a> {
Text(TextNode<'a>),
Element(Element<'a>),
Comment(CommentNode<'a>),
Doctype(DoctypeNode<'a>),
ProcessingInstruction(ProcessingInstructionNode<'a>),
}
impl<'a> Node<'a> {
#[inline]
pub fn text(&self) -> Option<&TextNode<'a>> {
match self {
Node::Text(t) => Some(t),
_ => None,
}
}
#[inline]
pub fn element(&self) -> Option<&Element<'a>> {
match self {
Node::Element(e) => Some(e),
_ => None,
}
}
#[inline]
pub fn comment(&self) -> Option<&CommentNode<'a>> {
match self {
Node::Comment(t) => Some(t),
_ => None,
}
}
#[inline]
pub fn doctype(&self) -> Option<&DoctypeNode<'a>> {
match self {
Node::Doctype(d) => Some(d),
_ => None,
}
}
#[inline]
pub fn processing_instruction(&self) -> Option<&ProcessingInstructionNode<'a>> {
match self {
Node::ProcessingInstruction(pi) => Some(pi),
_ => None,
}
}
}