natter/src/context/ast_node.rs

408 lines
15 KiB
Rust
Raw Normal View History

2023-10-29 15:36:15 -04:00
use std::path::Path;
use serde::Serialize;
use crate::config::Config;
use crate::error::CustomError;
use crate::intermediate::IAstNode;
use super::angle_link::RenderAngleLink;
use super::babel_call::RenderBabelCall;
use super::bold::RenderBold;
use super::center_block::RenderCenterBlock;
use super::citation::RenderCitation;
use super::citation_reference::RenderCitationReference;
use super::clock::RenderClock;
use super::code::RenderCode;
use super::comment::RenderComment;
use super::comment_block::RenderCommentBlock;
use super::diary_sexp::RenderDiarySexp;
use super::drawer::RenderDrawer;
use super::dynamic_block::RenderDynamicBlock;
use super::entity::RenderEntity;
use super::example_block::RenderExampleBlock;
use super::export_block::RenderExportBlock;
use super::export_snippet::RenderExportSnippet;
use super::fixed_width_area::RenderFixedWidthArea;
use super::footnote_definition::RenderFootnoteDefinition;
use super::footnote_reference::RenderFootnoteReference;
use super::horizontal_rule::RenderHorizontalRule;
use super::inline_babel_call::RenderInlineBabelCall;
use super::inline_source_block::RenderInlineSourceBlock;
use super::italic::RenderItalic;
use super::keyword::RenderKeyword;
use super::latex_environment::RenderLatexEnvironment;
use super::latex_fragment::RenderLatexFragment;
use super::line_break::RenderLineBreak;
use super::org_macro::RenderOrgMacro;
use super::paragraph::RenderParagraph;
use super::plain_link::RenderPlainLink;
use super::plain_list::RenderPlainList;
use super::plain_text::RenderPlainText;
use super::planning::RenderPlanning;
use super::property_drawer::RenderPropertyDrawer;
use super::quote_block::RenderQuoteBlock;
use super::radio_link::RenderRadioLink;
use super::radio_target::RenderRadioTarget;
use super::regular_link::RenderRegularLink;
use super::special_block::RenderSpecialBlock;
use super::src_block::RenderSrcBlock;
use super::statistics_cookie::RenderStatisticsCookie;
use super::strike_through::RenderStrikeThrough;
use super::subscript::RenderSubscript;
use super::superscript::RenderSuperscript;
use super::table::RenderTable;
use super::target::RenderTarget;
use super::timestamp::RenderTimestamp;
use super::underline::RenderUnderline;
use super::verbatim::RenderVerbatim;
use super::verse_block::RenderVerseBlock;
use super::RenderHeading;
use super::RenderSection;
#[derive(Debug, Serialize)]
#[serde(untagged)]
pub(crate) enum RenderAstNode {
Heading(RenderHeading),
Section(RenderSection),
Paragraph(RenderParagraph),
PlainList(RenderPlainList),
CenterBlock(RenderCenterBlock),
QuoteBlock(RenderQuoteBlock),
SpecialBlock(RenderSpecialBlock),
DynamicBlock(RenderDynamicBlock),
FootnoteDefinition(RenderFootnoteDefinition),
Comment(RenderComment),
Drawer(RenderDrawer),
PropertyDrawer(RenderPropertyDrawer),
Table(RenderTable),
VerseBlock(RenderVerseBlock),
CommentBlock(RenderCommentBlock),
ExampleBlock(RenderExampleBlock),
ExportBlock(RenderExportBlock),
SrcBlock(RenderSrcBlock),
Clock(RenderClock),
DiarySexp(RenderDiarySexp),
Planning(RenderPlanning),
FixedWidthArea(RenderFixedWidthArea),
HorizontalRule(RenderHorizontalRule),
Keyword(RenderKeyword),
BabelCall(RenderBabelCall),
LatexEnvironment(RenderLatexEnvironment),
Bold(RenderBold),
Italic(RenderItalic),
Underline(RenderUnderline),
StrikeThrough(RenderStrikeThrough),
Code(RenderCode),
Verbatim(RenderVerbatim),
PlainText(RenderPlainText),
RegularLink(RenderRegularLink),
RadioLink(RenderRadioLink),
RadioTarget(RenderRadioTarget),
PlainLink(RenderPlainLink),
AngleLink(RenderAngleLink),
OrgMacro(RenderOrgMacro),
Entity(RenderEntity),
LatexFragment(RenderLatexFragment),
ExportSnippet(RenderExportSnippet),
FootnoteReference(RenderFootnoteReference),
Citation(RenderCitation),
CitationReference(RenderCitationReference),
InlineBabelCall(RenderInlineBabelCall),
InlineSourceBlock(RenderInlineSourceBlock),
LineBreak(RenderLineBreak),
Target(RenderTarget),
StatisticsCookie(RenderStatisticsCookie),
Subscript(RenderSubscript),
Superscript(RenderSuperscript),
Timestamp(RenderTimestamp),
}
pub(crate) trait IntoRenderAstNode {
fn into_render_ast_node(
&self,
config: &Config,
output_directory: &Path,
output_file: &Path,
) -> Result<RenderAstNode, CustomError>;
}
impl IntoRenderAstNode for IAstNode {
fn into_render_ast_node(
&self,
config: &Config,
output_directory: &Path,
output_file: &Path,
) -> Result<RenderAstNode, CustomError> {
match self {
IAstNode::Heading(inner) => Ok(RenderAstNode::Heading(RenderHeading::new(
config,
output_directory,
output_file,
inner,
)?)),
IAstNode::Section(inner) => Ok(RenderAstNode::Section(RenderSection::new(
config,
output_directory,
output_file,
inner,
)?)),
IAstNode::Paragraph(inner) => Ok(RenderAstNode::Paragraph(RenderParagraph::new(
config,
output_directory,
output_file,
inner,
)?)),
IAstNode::PlainList(inner) => Ok(RenderAstNode::PlainList(RenderPlainList::new(
config,
output_directory,
output_file,
inner,
)?)),
IAstNode::CenterBlock(inner) => Ok(RenderAstNode::CenterBlock(RenderCenterBlock::new(
config,
output_directory,
output_file,
inner,
)?)),
IAstNode::QuoteBlock(inner) => Ok(RenderAstNode::QuoteBlock(RenderQuoteBlock::new(
config,
output_directory,
output_file,
inner,
)?)),
IAstNode::SpecialBlock(inner) => Ok(RenderAstNode::SpecialBlock(
RenderSpecialBlock::new(config, output_directory, output_file, inner)?,
)),
IAstNode::DynamicBlock(inner) => Ok(RenderAstNode::DynamicBlock(
RenderDynamicBlock::new(config, output_directory, output_file, inner)?,
)),
IAstNode::FootnoteDefinition(inner) => Ok(RenderAstNode::FootnoteDefinition(
RenderFootnoteDefinition::new(config, output_directory, output_file, inner)?,
)),
IAstNode::Comment(inner) => Ok(RenderAstNode::Comment(RenderComment::new(
config,
output_directory,
output_file,
inner,
)?)),
IAstNode::Drawer(inner) => Ok(RenderAstNode::Drawer(RenderDrawer::new(
config,
output_directory,
output_file,
inner,
)?)),
IAstNode::PropertyDrawer(inner) => Ok(RenderAstNode::PropertyDrawer(
RenderPropertyDrawer::new(config, output_directory, output_file, inner)?,
)),
IAstNode::Table(inner) => Ok(RenderAstNode::Table(RenderTable::new(
config,
output_directory,
output_file,
inner,
)?)),
IAstNode::VerseBlock(inner) => Ok(RenderAstNode::VerseBlock(RenderVerseBlock::new(
config,
output_directory,
output_file,
inner,
)?)),
IAstNode::CommentBlock(inner) => Ok(RenderAstNode::CommentBlock(
RenderCommentBlock::new(config, output_directory, output_file, inner)?,
)),
IAstNode::ExampleBlock(inner) => Ok(RenderAstNode::ExampleBlock(
RenderExampleBlock::new(config, output_directory, output_file, inner)?,
)),
IAstNode::ExportBlock(inner) => Ok(RenderAstNode::ExportBlock(RenderExportBlock::new(
config,
output_directory,
output_file,
inner,
)?)),
IAstNode::SrcBlock(inner) => Ok(RenderAstNode::SrcBlock(RenderSrcBlock::new(
config,
output_directory,
output_file,
inner,
)?)),
IAstNode::Clock(inner) => Ok(RenderAstNode::Clock(RenderClock::new(
config,
output_directory,
output_file,
inner,
)?)),
IAstNode::DiarySexp(inner) => Ok(RenderAstNode::DiarySexp(RenderDiarySexp::new(
config,
output_directory,
output_file,
inner,
)?)),
IAstNode::Planning(inner) => Ok(RenderAstNode::Planning(RenderPlanning::new(
config,
output_directory,
output_file,
inner,
)?)),
IAstNode::FixedWidthArea(inner) => Ok(RenderAstNode::FixedWidthArea(
RenderFixedWidthArea::new(config, output_directory, output_file, inner)?,
)),
IAstNode::HorizontalRule(inner) => Ok(RenderAstNode::HorizontalRule(
RenderHorizontalRule::new(config, output_directory, output_file, inner)?,
)),
IAstNode::Keyword(inner) => Ok(RenderAstNode::Keyword(RenderKeyword::new(
config,
output_directory,
output_file,
inner,
)?)),
IAstNode::BabelCall(inner) => Ok(RenderAstNode::BabelCall(RenderBabelCall::new(
config,
output_directory,
output_file,
inner,
)?)),
IAstNode::LatexEnvironment(inner) => Ok(RenderAstNode::LatexEnvironment(
RenderLatexEnvironment::new(config, output_directory, output_file, inner)?,
)),
IAstNode::Bold(inner) => Ok(RenderAstNode::Bold(RenderBold::new(
config,
output_directory,
output_file,
inner,
)?)),
IAstNode::Italic(inner) => Ok(RenderAstNode::Italic(RenderItalic::new(
config,
output_directory,
output_file,
inner,
)?)),
IAstNode::Underline(inner) => Ok(RenderAstNode::Underline(RenderUnderline::new(
config,
output_directory,
output_file,
inner,
)?)),
IAstNode::StrikeThrough(inner) => Ok(RenderAstNode::StrikeThrough(
RenderStrikeThrough::new(config, output_directory, output_file, inner)?,
)),
IAstNode::Code(inner) => Ok(RenderAstNode::Code(RenderCode::new(
config,
output_directory,
output_file,
inner,
)?)),
IAstNode::Verbatim(inner) => Ok(RenderAstNode::Verbatim(RenderVerbatim::new(
config,
output_directory,
output_file,
inner,
)?)),
IAstNode::PlainText(inner) => Ok(RenderAstNode::PlainText(RenderPlainText::new(
config,
output_directory,
output_file,
inner,
)?)),
IAstNode::RegularLink(inner) => Ok(RenderAstNode::RegularLink(RenderRegularLink::new(
config,
output_directory,
output_file,
inner,
)?)),
IAstNode::RadioLink(inner) => Ok(RenderAstNode::RadioLink(RenderRadioLink::new(
config,
output_directory,
output_file,
inner,
)?)),
IAstNode::RadioTarget(inner) => Ok(RenderAstNode::RadioTarget(RenderRadioTarget::new(
config,
output_directory,
output_file,
inner,
)?)),
IAstNode::PlainLink(inner) => Ok(RenderAstNode::PlainLink(RenderPlainLink::new(
config,
output_directory,
output_file,
inner,
)?)),
IAstNode::AngleLink(inner) => Ok(RenderAstNode::AngleLink(RenderAngleLink::new(
config,
output_directory,
output_file,
inner,
)?)),
IAstNode::OrgMacro(inner) => Ok(RenderAstNode::OrgMacro(RenderOrgMacro::new(
config,
output_directory,
output_file,
inner,
)?)),
IAstNode::Entity(inner) => Ok(RenderAstNode::Entity(RenderEntity::new(
config,
output_directory,
output_file,
inner,
)?)),
IAstNode::LatexFragment(inner) => Ok(RenderAstNode::LatexFragment(
RenderLatexFragment::new(config, output_directory, output_file, inner)?,
)),
IAstNode::ExportSnippet(inner) => Ok(RenderAstNode::ExportSnippet(
RenderExportSnippet::new(config, output_directory, output_file, inner)?,
)),
IAstNode::FootnoteReference(inner) => Ok(RenderAstNode::FootnoteReference(
RenderFootnoteReference::new(config, output_directory, output_file, inner)?,
)),
IAstNode::Citation(inner) => Ok(RenderAstNode::Citation(RenderCitation::new(
config,
output_directory,
output_file,
inner,
)?)),
IAstNode::CitationReference(inner) => Ok(RenderAstNode::CitationReference(
RenderCitationReference::new(config, output_directory, output_file, inner)?,
)),
IAstNode::InlineBabelCall(inner) => Ok(RenderAstNode::InlineBabelCall(
RenderInlineBabelCall::new(config, output_directory, output_file, inner)?,
)),
IAstNode::InlineSourceBlock(inner) => Ok(RenderAstNode::InlineSourceBlock(
RenderInlineSourceBlock::new(config, output_directory, output_file, inner)?,
)),
IAstNode::LineBreak(inner) => Ok(RenderAstNode::LineBreak(RenderLineBreak::new(
config,
output_directory,
output_file,
inner,
)?)),
IAstNode::Target(inner) => Ok(RenderAstNode::Target(RenderTarget::new(
config,
output_directory,
output_file,
inner,
)?)),
IAstNode::StatisticsCookie(inner) => Ok(RenderAstNode::StatisticsCookie(
RenderStatisticsCookie::new(config, output_directory, output_file, inner)?,
)),
IAstNode::Subscript(inner) => Ok(RenderAstNode::Subscript(RenderSubscript::new(
config,
output_directory,
output_file,
inner,
)?)),
IAstNode::Superscript(inner) => Ok(RenderAstNode::Superscript(RenderSuperscript::new(
config,
output_directory,
output_file,
inner,
)?)),
IAstNode::Timestamp(inner) => Ok(RenderAstNode::Timestamp(RenderTimestamp::new(
config,
output_directory,
output_file,
inner,
)?)),
}
}
}