use super::AssetUse;
use crate::ir::{Attributes, CalloutKind, SourceSegment, SourceSpan, TableAlignment};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct DecodedMarkdown {
pub blocks: Vec<FragmentBlock>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "kebab-case", deny_unknown_fields)]
pub enum FragmentBlock {
Paragraph {
inlines: Vec<FragmentInline>,
span: SourceSpan,
},
Heading {
level: usize,
attributes: Attributes,
inlines: Vec<FragmentInline>,
span: SourceSpan,
},
BlockQuote {
blocks: Vec<FragmentBlock>,
span: SourceSpan,
},
List {
ordered: bool,
items: Vec<FragmentListItem>,
span: SourceSpan,
},
ThematicBreak {
span: SourceSpan,
},
CodeBlock {
language: Option<String>,
source: String,
source_segments: Vec<SourceSegment>,
span: SourceSpan,
},
Table {
caption: Vec<FragmentInline>,
alignments: Vec<TableAlignment>,
rows: Vec<FragmentTableRow>,
span: SourceSpan,
},
Callout {
kind: CalloutKind,
attributes: Attributes,
blocks: Vec<FragmentBlock>,
span: SourceSpan,
},
Unsupported {
source_kind: String,
raw: String,
span: SourceSpan,
},
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct FragmentListItem {
pub checked: Option<bool>,
pub blocks: Vec<FragmentBlock>,
pub span: SourceSpan,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct FragmentTableRow {
pub header: bool,
pub cells: Vec<FragmentTableCell>,
pub span: SourceSpan,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct FragmentTableCell {
pub blocks: Vec<FragmentBlock>,
pub span: SourceSpan,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "kebab-case", deny_unknown_fields)]
pub enum FragmentInline {
Text {
value: String,
span: SourceSpan,
},
Space {
span: SourceSpan,
},
SoftBreak {
span: SourceSpan,
},
HardBreak {
span: SourceSpan,
},
NonbreakingSpace {
span: SourceSpan,
},
Emphasis {
inlines: Vec<FragmentInline>,
span: SourceSpan,
},
Strong {
inlines: Vec<FragmentInline>,
span: SourceSpan,
},
Strikeout {
inlines: Vec<FragmentInline>,
span: SourceSpan,
},
Code {
value: String,
span: SourceSpan,
},
Link {
inlines: Vec<FragmentInline>,
target: String,
title: Option<String>,
attributes: Attributes,
span: SourceSpan,
},
Image {
alt: Vec<FragmentInline>,
asset: AssetUse,
title: Option<String>,
attributes: Attributes,
span: SourceSpan,
},
AutoLink {
target: String,
span: SourceSpan,
},
SemanticReference {
target: String,
span: SourceSpan,
target_span: SourceSpan,
},
Unsupported {
source_kind: String,
raw: String,
span: SourceSpan,
},
}