use super::attrs::Attributes;
use super::span::Span;
#[cfg(feature = "npm")]
use napi_derive::napi;
use serde::Serialize;
#[cfg_attr(feature = "npm", napi)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum Block {
Heading {
level: u8,
children: Vec<Inline>,
pos: Span,
#[serde(skip_serializing_if = "Option::is_none")]
attrs: Option<Attributes>,
},
Paragraph {
children: Vec<Inline>,
pos: Span,
#[serde(skip_serializing_if = "Option::is_none")]
attrs: Option<Attributes>,
},
CodeBlock {
lang: Option<String>,
code: String,
pos: Span,
#[serde(skip_serializing_if = "Option::is_none")]
attrs: Option<Attributes>,
},
BlockQuote {
children: Vec<Block>,
pos: Span,
#[serde(skip_serializing_if = "Option::is_none")]
attrs: Option<Attributes>,
},
List {
ordered: bool,
items: Vec<ListItem>,
pos: Span,
#[serde(skip_serializing_if = "Option::is_none")]
attrs: Option<Attributes>,
},
ThematicBreak {
pos: Span,
},
HtmlBlock {
html: String,
pos: Span,
#[serde(skip_serializing_if = "Option::is_none")]
attrs: Option<Attributes>,
},
Table {
table: Table,
pos: Span,
#[serde(skip_serializing_if = "Option::is_none")]
attrs: Option<Attributes>,
},
LinkReferenceDefinition {
label: String,
url: String,
#[serde(skip_serializing_if = "Option::is_none")]
title: Option<String>,
pos: Span,
},
Comment {
value: String,
pos: Span,
},
}
#[cfg_attr(feature = "npm", napi(object))]
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct LinkReferenceDefinition {
pub label: String,
pub url: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub title: Option<String>,
pub pos: Span,
}
#[cfg_attr(feature = "npm", napi(object))]
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct ListItem {
pub children: Vec<Block>,
#[cfg_attr(feature = "npm", napi(ts_type = "PeisarTaskState"))]
#[serde(skip_serializing_if = "Option::is_none")]
pub task: Option<TaskState>,
pub pos: Span,
}
#[cfg_attr(feature = "npm", napi(string_enum, skip_typescript))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
pub enum TaskState {
Unchecked,
Checked,
}
#[cfg_attr(feature = "npm", napi(object))]
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct Table {
pub header: TableRow,
pub rows: Vec<TableRow>,
#[cfg_attr(feature = "npm", napi(ts_type = "PeisarTableCellAlignments"))]
pub alignments: Vec<TableCellAlignment>,
}
#[cfg_attr(feature = "npm", napi(object))]
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct TableRow {
pub cells: Vec<TableCell>,
}
#[cfg_attr(feature = "npm", napi(object))]
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct TableCell {
pub children: Vec<Inline>,
}
#[cfg_attr(feature = "npm", napi(string_enum, skip_typescript))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize)]
pub enum TableCellAlignment {
#[default]
Default,
Left,
Center,
Right,
}
#[cfg_attr(feature = "npm", napi)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum Inline {
Text {
value: String,
pos: Span,
},
Emphasis {
#[cfg_attr(feature = "npm", napi(ts_type = "PeisarEmphasisLevel"))]
level: EmphasisLevel,
children: Vec<Inline>,
pos: Span,
},
Code {
code: String,
pos: Span,
},
HtmlInline {
html: String,
pos: Span,
},
Strikethrough {
children: Vec<Inline>,
pos: Span,
},
HardBreak {
pos: Span,
},
SoftBreak {
pos: Span,
},
Image {
alt: String,
url: String,
title: Option<String>,
pos: Span,
},
Link {
text: Vec<Inline>,
url: String,
title: Option<String>,
autolink: bool,
pos: Span,
},
LinkReference {
text: Vec<Inline>,
label: String,
url: String,
#[serde(skip_serializing_if = "Option::is_none")]
title: Option<String>,
pos: Span,
},
}
#[cfg_attr(feature = "npm", napi(string_enum, skip_typescript))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
pub enum EmphasisLevel {
Italic,
Bold,
}