//! The block vocabulary of commands and the toolbar: leaf kinds and containers. use note_model::flat::{self, Wrap}; #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub enum Kind { Paragraph, Heading(u8), CodeBlock, Rule, Blockquote, BulletList, OrderedList, } impl Kind { pub fn leaf(self) -> Option { Some(match self { Kind::Paragraph => flat::Kind::Para, Kind::Heading(n) => flat::Kind::Heading(n), Kind::CodeBlock => flat::Kind::Code, Kind::Rule => flat::Kind::Rule, _ => return None, }) } pub fn wrap(self) -> Option { Some(match self { Kind::Blockquote => Wrap::Quote, Kind::BulletList => Wrap::Bullet, Kind::OrderedList => Wrap::Ordered, _ => return None, }) } pub fn of_leaf(k: flat::Kind) -> Kind { match k { flat::Kind::Para => Kind::Paragraph, flat::Kind::Heading(n) => Kind::Heading(n), flat::Kind::Code => Kind::CodeBlock, flat::Kind::Rule => Kind::Rule, } } pub fn of_wrap(w: Wrap) -> Kind { match w { Wrap::Quote => Kind::Blockquote, Wrap::Bullet => Kind::BulletList, Wrap::Ordered => Kind::OrderedList, } } pub fn is_textblock(self) -> bool { matches!(self, Kind::Paragraph | Kind::Heading(_) | Kind::CodeBlock) } pub fn is_list(self) -> bool { matches!(self, Kind::BulletList | Kind::OrderedList) } }