use gpui::SharedString;
use gpui_kit::base::text::editor_host::ColumnAlign;
#[non_exhaustive]
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum BlockKind {
Root,
Blockquote,
List {
ordered: bool,
},
ListItem {
checked: Option<bool>,
},
Table,
TableRow,
TableCell,
Paragraph,
Heading {
level: u8,
},
CodeBlock,
Image,
HorizontalRule,
Break,
Custom,
Definition,
Unknown,
}
#[derive(Clone, Debug, PartialEq)]
pub(crate) enum BlockKindData {
Root,
Blockquote,
List {
ordered: bool,
start: Option<u32>,
},
ListItem {
checked: Option<bool>,
spread: bool,
},
Table {
aligns: Vec<ColumnAlign>,
},
TableRow,
TableCell,
Paragraph,
Heading {
level: u8,
},
CodeBlock {
lang: Option<SharedString>,
meta: Option<SharedString>,
},
HorizontalRule,
Break {
html: bool,
},
Custom,
Definition {
identifier: SharedString,
url: SharedString,
title: Option<SharedString>,
},
Unknown,
}
impl BlockKindData {
pub(crate) fn public(&self) -> BlockKind {
match self {
Self::Root => BlockKind::Root,
Self::Blockquote => BlockKind::Blockquote,
Self::List { ordered, .. } => BlockKind::List { ordered: *ordered },
Self::ListItem { checked, .. } => BlockKind::ListItem { checked: *checked },
Self::Table { .. } => BlockKind::Table,
Self::TableRow => BlockKind::TableRow,
Self::TableCell => BlockKind::TableCell,
Self::Paragraph => BlockKind::Paragraph,
Self::Heading { level } => BlockKind::Heading { level: *level },
Self::CodeBlock { .. } => BlockKind::CodeBlock,
Self::HorizontalRule => BlockKind::HorizontalRule,
Self::Break { .. } => BlockKind::Break,
Self::Custom => BlockKind::Custom,
Self::Definition { .. } => BlockKind::Definition,
Self::Unknown => BlockKind::Unknown,
}
}
pub(crate) fn is_container(&self) -> bool {
matches!(
self,
Self::Root
| Self::Blockquote
| Self::List { .. }
| Self::ListItem { .. }
| Self::Table { .. }
| Self::TableRow
)
}
pub(crate) fn is_textblock(&self) -> bool {
matches!(
self,
Self::Paragraph | Self::Heading { .. } | Self::TableCell
)
}
}