#![allow(dead_code)]
use crate::render::Modifier;
use crate::style::Color;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum AdmonitionType {
Note,
Tip,
Important,
Warning,
Caution,
}
impl AdmonitionType {
pub fn from_marker(text: &str) -> Option<Self> {
let text = text.trim();
if !text.starts_with("[!") || !text.contains(']') {
return None;
}
let end = text.find(']')?;
let type_str = &text[2..end];
match type_str.to_uppercase().as_str() {
"NOTE" => Some(AdmonitionType::Note),
"TIP" => Some(AdmonitionType::Tip),
"IMPORTANT" => Some(AdmonitionType::Important),
"WARNING" => Some(AdmonitionType::Warning),
"CAUTION" => Some(AdmonitionType::Caution),
_ => None,
}
}
pub fn icon(&self) -> &'static str {
match self {
AdmonitionType::Note => "âšī¸ ",
AdmonitionType::Tip => "đĄ",
AdmonitionType::Important => "â",
AdmonitionType::Warning => "â ī¸ ",
AdmonitionType::Caution => "đ´",
}
}
pub fn color(&self) -> Color {
match self {
AdmonitionType::Note => Color::rgb(88, 166, 255), AdmonitionType::Tip => Color::rgb(63, 185, 80), AdmonitionType::Important => Color::rgb(163, 113, 247), AdmonitionType::Warning => Color::rgb(210, 153, 34), AdmonitionType::Caution => Color::rgb(248, 81, 73), }
}
pub fn label(&self) -> &'static str {
match self {
AdmonitionType::Note => "Note",
AdmonitionType::Tip => "Tip",
AdmonitionType::Important => "Important",
AdmonitionType::Warning => "Warning",
AdmonitionType::Caution => "Caution",
}
}
}
#[derive(Clone, Debug)]
pub struct FootnoteDefinition {
pub label: String,
pub content: String,
}
#[derive(Clone)]
pub struct StyledText {
pub text: String,
pub fg: Option<Color>,
pub bg: Option<Color>,
pub modifier: Modifier,
}
impl StyledText {
pub fn new(text: impl Into<String>) -> Self {
Self {
text: text.into(),
fg: None,
bg: None,
modifier: Modifier::empty(),
}
}
pub fn with_fg(mut self, color: Color) -> Self {
self.fg = Some(color);
self
}
pub fn with_modifier(mut self, modifier: Modifier) -> Self {
self.modifier = modifier;
self
}
}
#[derive(Clone)]
pub struct Line {
pub segments: Vec<StyledText>,
}
impl Line {
pub fn new() -> Self {
Self {
segments: Vec::new(),
}
}
pub fn push(&mut self, segment: StyledText) {
self.segments.push(segment);
}
pub fn is_empty(&self) -> bool {
self.segments.is_empty() || self.segments.iter().all(|s| s.text.is_empty())
}
}
impl Default for Line {
fn default() -> Self {
Self::new()
}
}
#[derive(Clone, Debug)]
pub struct TocEntry {
pub level: u8,
pub text: String,
}