use super::Element;
use super::attribute::AttributeMap;
use super::clone::elements_to_owned;
use strum_macros::IntoStaticStr;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "kebab-case", tag = "item-type")]
pub enum ListItem<'t> {
Elements {
attributes: AttributeMap<'t>,
elements: Vec<Element<'t>>,
},
SubList {
#[serde(flatten)]
element: Box<Element<'t>>,
},
}
impl ListItem<'_> {
pub fn to_owned(&self) -> ListItem<'static> {
match self {
ListItem::Elements {
attributes,
elements,
} => ListItem::Elements {
attributes: attributes.to_owned(),
elements: elements_to_owned(elements),
},
ListItem::SubList { element } => {
let element: &Element = element;
ListItem::SubList {
element: Box::new(element.to_owned()),
}
}
}
}
}
#[derive(
Serialize, Deserialize, IntoStaticStr, Debug, Copy, Clone, Hash, PartialEq, Eq,
)]
#[serde(rename_all = "kebab-case")]
pub enum ListType {
Bullet,
Numbered,
Generic,
}
impl ListType {
#[inline]
pub fn name(self) -> &'static str {
self.into()
}
#[inline]
pub fn html_tag(self) -> &'static str {
match self {
ListType::Bullet | ListType::Generic => "ul",
ListType::Numbered => "ol",
}
}
}