| 1 | |
| 2 | |
| 3 | use note_model::flat::{self, Wrap}; |
| 4 | |
| 5 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] |
| 6 | pub enum Kind { |
| 7 | Paragraph, |
| 8 | Heading(u8), |
| 9 | CodeBlock, |
| 10 | Rule, |
| 11 | Blockquote, |
| 12 | BulletList, |
| 13 | OrderedList, |
| 14 | } |
| 15 | |
| 16 | impl Kind { |
| 17 | pub fn leaf(self) -> Option<flat::Kind> { |
| 18 | Some(match self { |
| 19 | Kind::Paragraph => flat::Kind::Para, |
| 20 | Kind::Heading(n) => flat::Kind::Heading(n), |
| 21 | Kind::CodeBlock => flat::Kind::Code, |
| 22 | Kind::Rule => flat::Kind::Rule, |
| 23 | _ => return None, |
| 24 | }) |
| 25 | } |
| 26 | |
| 27 | pub fn wrap(self) -> Option<Wrap> { |
| 28 | Some(match self { |
| 29 | Kind::Blockquote => Wrap::Quote, |
| 30 | Kind::BulletList => Wrap::Bullet, |
| 31 | Kind::OrderedList => Wrap::Ordered, |
| 32 | _ => return None, |
| 33 | }) |
| 34 | } |
| 35 | |
| 36 | pub fn of_leaf(k: flat::Kind) -> Kind { |
| 37 | match k { |
| 38 | flat::Kind::Para => Kind::Paragraph, |
| 39 | flat::Kind::Heading(n) => Kind::Heading(n), |
| 40 | flat::Kind::Code => Kind::CodeBlock, |
| 41 | flat::Kind::Rule => Kind::Rule, |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | pub fn of_wrap(w: Wrap) -> Kind { |
| 46 | match w { |
| 47 | Wrap::Quote => Kind::Blockquote, |
| 48 | Wrap::Bullet => Kind::BulletList, |
| 49 | Wrap::Ordered => Kind::OrderedList, |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | pub fn is_textblock(self) -> bool { |
| 54 | matches!(self, Kind::Paragraph | Kind::Heading(_) | Kind::CodeBlock) |
| 55 | } |
| 56 | |
| 57 | pub fn is_list(self) -> bool { |
| 58 | matches!(self, Kind::BulletList | Kind::OrderedList) |
| 59 | } |
| 60 | } |