Lines
0 %
Functions
Branches
100 %
//! CSS list styling properties (`list-style-type` and `list-style-position`)
use alloc::string::{String, ToString};
use core::fmt;
use crate::corety::AzString;
use crate::{format_rust_code::FormatAsRustCode, props::formatter::PrintAsCssValue};
// --- list-style-type ---
/// CSS `list-style-type` property — controls the marker style for list items.
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(C)]
#[derive(Default)]
pub enum StyleListStyleType {
None,
#[default]
Disc,
Circle,
Square,
Decimal,
DecimalLeadingZero,
LowerRoman,
UpperRoman,
LowerGreek,
UpperGreek,
LowerAlpha,
UpperAlpha,
}
impl PrintAsCssValue for StyleListStyleType {
fn print_as_css_value(&self) -> String {
use StyleListStyleType::*;
String::from(match self {
None => "none",
Disc => "disc",
Circle => "circle",
Square => "square",
Decimal => "decimal",
DecimalLeadingZero => "decimal-leading-zero",
LowerRoman => "lower-roman",
UpperRoman => "upper-roman",
LowerGreek => "lower-greek",
UpperGreek => "upper-greek",
LowerAlpha => "lower-alpha",
UpperAlpha => "upper-alpha",
})
impl FormatAsRustCode for StyleListStyleType {
fn format_as_rust_code(&self, _tabs: usize) -> String {
format!(
"StyleListStyleType::{}",
match self {
None => "None",
Disc => "Disc",
Circle => "Circle",
Square => "Square",
Decimal => "Decimal",
DecimalLeadingZero => "DecimalLeadingZero",
LowerRoman => "LowerRoman",
UpperRoman => "UpperRoman",
LowerGreek => "LowerGreek",
UpperGreek => "UpperGreek",
LowerAlpha => "LowerAlpha",
UpperAlpha => "UpperAlpha",
)
impl fmt::Display for StyleListStyleType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.print_as_css_value())
// --- list-style-position ---
/// CSS `list-style-position` property — controls whether the marker is inside or outside the list item box.
pub enum StyleListStylePosition {
Inside,
Outside,
impl PrintAsCssValue for StyleListStylePosition {
use StyleListStylePosition::*;
Inside => "inside",
Outside => "outside",
impl FormatAsRustCode for StyleListStylePosition {
"StyleListStylePosition::{}",
Inside => "Inside",
Outside => "Outside",
impl fmt::Display for StyleListStylePosition {
// --- Parsing Logic ---
#[cfg(feature = "parser")]
#[derive(Clone, PartialEq)]
pub enum StyleListStyleTypeParseError<'a> {
InvalidValue(&'a str),
impl_debug_as_display!(StyleListStyleTypeParseError<'a>);
impl_display! { StyleListStyleTypeParseError<'a>, {
InvalidValue(val) => format!("Invalid list-style-type value: \"{}\"", val),
}}
#[derive(Debug, Clone, PartialEq)]
#[repr(C, u8)]
pub enum StyleListStyleTypeParseErrorOwned {
InvalidValue(AzString),
impl<'a> StyleListStyleTypeParseError<'a> {
pub fn to_contained(&self) -> StyleListStyleTypeParseErrorOwned {
Self::InvalidValue(s) => StyleListStyleTypeParseErrorOwned::InvalidValue(s.to_string().into()),
impl StyleListStyleTypeParseErrorOwned {
pub fn to_shared<'a>(&'a self) -> StyleListStyleTypeParseError<'a> {
Self::InvalidValue(s) => StyleListStyleTypeParseError::InvalidValue(s.as_str()),
/// Parses a CSS `list-style-type` value from a string.
pub fn parse_style_list_style_type<'a>(
input: &'a str,
) -> Result<StyleListStyleType, StyleListStyleTypeParseError<'a>> {
let input = input.trim();
match input {
"none" => Ok(StyleListStyleType::None),
"disc" => Ok(StyleListStyleType::Disc),
"circle" => Ok(StyleListStyleType::Circle),
"square" => Ok(StyleListStyleType::Square),
"decimal" => Ok(StyleListStyleType::Decimal),
"decimal-leading-zero" => Ok(StyleListStyleType::DecimalLeadingZero),
"lower-roman" => Ok(StyleListStyleType::LowerRoman),
"upper-roman" => Ok(StyleListStyleType::UpperRoman),
"lower-greek" => Ok(StyleListStyleType::LowerGreek),
"upper-greek" => Ok(StyleListStyleType::UpperGreek),
"lower-alpha" | "lower-latin" => Ok(StyleListStyleType::LowerAlpha),
"upper-alpha" | "upper-latin" => Ok(StyleListStyleType::UpperAlpha),
_ => Err(StyleListStyleTypeParseError::InvalidValue(input)),
pub enum StyleListStylePositionParseError<'a> {
impl_debug_as_display!(StyleListStylePositionParseError<'a>);
impl_display! { StyleListStylePositionParseError<'a>, {
InvalidValue(val) => format!("Invalid list-style-position value: \"{}\"", val),
pub enum StyleListStylePositionParseErrorOwned {
impl<'a> StyleListStylePositionParseError<'a> {
pub fn to_contained(&self) -> StyleListStylePositionParseErrorOwned {
Self::InvalidValue(s) => {
StyleListStylePositionParseErrorOwned::InvalidValue(s.to_string().into())
impl StyleListStylePositionParseErrorOwned {
pub fn to_shared<'a>(&'a self) -> StyleListStylePositionParseError<'a> {
Self::InvalidValue(s) => StyleListStylePositionParseError::InvalidValue(s.as_str()),
/// Parses a CSS `list-style-position` value from a string.
pub fn parse_style_list_style_position<'a>(
) -> Result<StyleListStylePosition, StyleListStylePositionParseError<'a>> {
"inside" => Ok(StyleListStylePosition::Inside),
"outside" => Ok(StyleListStylePosition::Outside),
_ => Err(StyleListStylePositionParseError::InvalidValue(input)),