use serde::{Deserialize, Serialize};
mod cpp;
mod identity;
mod languages;
mod outputs;
mod package_metadata;
mod provenance;
mod signatures;
mod workspace;
pub use cpp::*;
pub use identity::*;
pub use languages::*;
pub use outputs::*;
pub use package_metadata::*;
pub use provenance::*;
pub use signatures::*;
pub use workspace::*;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub struct SourceSpan {
pub start: usize,
pub end: usize,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct SpannedString {
pub value: String,
pub span: SourceSpan,
}
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct Attributes {
pub identifier: Option<SpannedString>,
pub classes: Vec<SpannedString>,
pub key_values: Vec<AttributeKeyValue>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct AttributeKeyValue {
pub key: SpannedString,
pub value: SpannedString,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "kebab-case")]
pub enum MetadataValue {
Null {
span: SourceSpan,
},
Scalar {
raw: String,
value: String,
span: SourceSpan,
},
Mapping {
entries: Vec<MetadataEntry>,
span: SourceSpan,
},
Sequence {
items: Vec<MetadataValue>,
span: SourceSpan,
},
Unsupported {
raw: String,
span: SourceSpan,
},
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct MetadataEntry {
pub key: SpannedString,
pub value: MetadataValue,
pub span: SourceSpan,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Document {
pub span: SourceSpan,
pub frontmatter: Option<MetadataValue>,
pub blocks: Vec<Block>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "kebab-case")]
pub enum Block {
ApiDocumentation {
item: ItemReference,
selection: Vec<ItemReference>,
identifier: String,
span: SourceSpan,
},
Component {
attributes: Attributes,
blocks: Vec<Block>,
span: SourceSpan,
},
Tabset {
attributes: Attributes,
blocks: Vec<Block>,
span: SourceSpan,
},
Container {
kind: DocumentContainerKind,
identifier: Option<String>,
blocks: Vec<Block>,
span: SourceSpan,
},
DisplayMath {
latex: String,
fallback: Option<String>,
span: SourceSpan,
},
Paragraph {
inlines: Vec<Inline>,
span: SourceSpan,
},
Heading {
level: usize,
attributes: Attributes,
inlines: Vec<Inline>,
span: SourceSpan,
},
BlockQuote {
blocks: Vec<Block>,
span: SourceSpan,
},
List {
ordered: bool,
items: Vec<ListItem>,
span: SourceSpan,
},
ThematicBreak {
span: SourceSpan,
},
CodeBlock {
language: Option<String>,
source: String,
source_segments: Vec<SourceSegment>,
span: SourceSpan,
},
CodeCell(CodeCell),
Table {
caption: Vec<Inline>,
alignments: Vec<TableAlignment>,
rows: Vec<TableRow>,
span: SourceSpan,
},
Callout {
kind: CalloutKind,
attributes: Attributes,
blocks: Vec<Block>,
span: SourceSpan,
},
Unsupported {
source_kind: String,
raw: String,
span: SourceSpan,
},
}
#[derive(Clone)]
pub(crate) struct DescriptionEntry {
pub term: Vec<Block>,
pub description: Vec<Block>,
pub span: SourceSpan,
}
impl Block {
pub(crate) fn description_list(entries: Vec<DescriptionEntry>, span: SourceSpan) -> Self {
Self::Container {
kind: DocumentContainerKind::DefinitionList,
identifier: None,
blocks: entries
.into_iter()
.flat_map(|entry| {
[
Self::Container {
kind: DocumentContainerKind::DefinitionTerm,
identifier: None,
blocks: entry.term,
span: entry.span,
},
Self::Container {
kind: DocumentContainerKind::Definition,
identifier: None,
blocks: entry.description,
span: entry.span,
},
]
})
.collect(),
span,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum DocumentContainerKind {
Disclosure {
open: bool,
},
DefinitionList,
DefinitionTerm,
Definition,
Figure,
Footnotes,
Footnote,
BibliographyEntry,
GeneratedChunk,
GeneratedOutput,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum InlineStyle {
Superscript,
Subscript,
SmallCaps,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ListItem {
pub checked: Option<bool>,
pub blocks: Vec<Block>,
pub span: SourceSpan,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct SourceSegment {
pub text: String,
pub span: SourceSpan,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct CodeCell {
pub language: Option<String>,
pub identifier: Option<SpannedString>,
pub classes: Vec<SpannedString>,
pub labels: Vec<SpannedString>,
pub source: String,
pub source_segments: Vec<SourceSegment>,
pub options: Vec<CellOption>,
pub resolved_options: Vec<ResolvedCellOption>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub outputs: Vec<CellOutput>,
pub code_span: Option<SourceSpan>,
pub span: SourceSpan,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum CellOptionSource {
InlineInfo,
HashpipeYaml,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct CellOption {
pub key: Option<String>,
pub canonical_key: Option<String>,
pub raw_value: Option<String>,
pub cooked_value: Option<String>,
pub value: Option<MetadataValue>,
pub source: CellOptionSource,
pub key_span: Option<SourceSpan>,
pub value_span: Option<SourceSpan>,
pub span: SourceSpan,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ResolvedCellOption {
pub key: String,
pub resolution: CellOptionResolution,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "kebab-case")]
pub enum CellOptionResolution {
Resolved {
declaration: usize,
},
Ambiguous {
declarations: Vec<usize>,
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum TableAlignment {
Default,
Left,
Center,
Right,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct TableRow {
pub header: bool,
pub cells: Vec<TableCell>,
pub span: SourceSpan,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct TableCell {
pub blocks: Vec<Block>,
pub span: SourceSpan,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum CalloutKind {
Note,
Tip,
Important,
Warning,
Caution,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "kebab-case")]
pub enum Inline {
Styled {
style: InlineStyle,
inlines: Vec<Inline>,
span: SourceSpan,
},
Citation {
raw: String,
keys: Vec<String>,
inlines: Vec<Inline>,
span: SourceSpan,
},
Math {
latex: String,
fallback: Option<String>,
span: SourceSpan,
},
Text {
value: String,
span: SourceSpan,
},
Space {
span: SourceSpan,
},
SoftBreak {
span: SourceSpan,
},
HardBreak {
span: SourceSpan,
},
NonbreakingSpace {
span: SourceSpan,
},
Emphasis {
inlines: Vec<Inline>,
span: SourceSpan,
},
Strong {
inlines: Vec<Inline>,
span: SourceSpan,
},
Strikeout {
inlines: Vec<Inline>,
span: SourceSpan,
},
Code {
value: String,
span: SourceSpan,
},
Link {
inlines: Vec<Inline>,
target: String,
title: Option<String>,
attributes: Attributes,
span: SourceSpan,
},
Image {
alt: Vec<Inline>,
target: String,
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,
},
}