Create a render ast node type.

This commit is contained in:
Tom Alexander
2023-10-29 15:36:15 -04:00
parent 645ae26701
commit b66ec507ef
74 changed files with 566 additions and 80 deletions

View File

@@ -2,7 +2,7 @@ use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct IAngleLink {}
impl IAngleLink {

View File

@@ -55,7 +55,7 @@ use super::IVerseBlock;
use crate::error::CustomError;
use futures::future::{BoxFuture, FutureExt};
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) enum IAstNode {
Heading(IHeading),
Section(ISection),

View File

@@ -2,7 +2,7 @@ use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct IBabelCall {}
impl IBabelCall {

View File

@@ -2,7 +2,7 @@ use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct IBold {}
impl IBold {

View File

@@ -2,7 +2,7 @@ use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct ICenterBlock {}
impl ICenterBlock {

View File

@@ -2,7 +2,7 @@ use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct ICitation {}
impl ICitation {

View File

@@ -2,7 +2,7 @@ use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct ICitationReference {}
impl ICitationReference {

View File

@@ -2,7 +2,7 @@ use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct IClock {}
impl IClock {

View File

@@ -2,7 +2,7 @@ use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct ICode {}
impl ICode {

View File

@@ -3,7 +3,7 @@ use crate::error::CustomError;
use super::registry::Registry;
/// Essentially a no-op since the comment is not rendered.
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct IComment {}
impl IComment {

View File

@@ -2,7 +2,7 @@ use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct ICommentBlock {}
impl ICommentBlock {

View File

@@ -2,7 +2,7 @@ use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct IDiarySexp {}
impl IDiarySexp {

View File

@@ -5,7 +5,7 @@ use super::IHeading;
use super::ISection;
use futures::future::{BoxFuture, FutureExt};
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) enum IDocumentElement {
Heading(IHeading),
Section(ISection),

View File

@@ -2,7 +2,7 @@ use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct IDrawer {}
impl IDrawer {

View File

@@ -2,7 +2,7 @@ use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct IDynamicBlock {}
impl IDynamicBlock {

View File

@@ -27,7 +27,7 @@ use super::ITable;
use super::IVerseBlock;
use futures::future::{BoxFuture, FutureExt};
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) enum IElement {
Paragraph(IParagraph),
PlainList(IPlainList),

View File

@@ -2,7 +2,7 @@ use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct IEntity {
pub(crate) html: String,
}

View File

@@ -2,7 +2,7 @@ use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct IExampleBlock {}
impl IExampleBlock {

View File

@@ -2,7 +2,7 @@ use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct IExportBlock {}
impl IExportBlock {

View File

@@ -2,7 +2,7 @@ use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct IExportSnippet {}
impl IExportSnippet {

View File

@@ -2,7 +2,7 @@ use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct IFixedWidthArea {}
impl IFixedWidthArea {

View File

@@ -5,7 +5,7 @@ use super::registry::Registry;
use super::IElement;
use super::IObject;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct IFootnoteDefinition {}
impl IFootnoteDefinition {
@@ -22,8 +22,8 @@ impl IFootnoteDefinition {
#[derive(Debug)]
pub(crate) struct IRealFootnoteDefinition {
footnote_id: usize,
contents: Vec<IAstNode>,
pub(crate) footnote_id: usize,
pub(crate) contents: Vec<IAstNode>,
}
impl IRealFootnoteDefinition {
@@ -37,4 +37,22 @@ impl IRealFootnoteDefinition {
contents,
})
}
pub(crate) fn get_display_label(&self) -> String {
format!("{}", self.footnote_id + 1)
}
/// Get an ID to refer to the first reference to this footnote definition.
///
/// This ID could, for example, be used for the id attribute in HTML for the reference anchor tag.
pub(crate) fn get_reference_id(&self) -> String {
format!("fnr.{}", self.get_display_label())
}
/// Get an ID to refer to the footnote definition.
///
/// This ID could, for example, be used for the id attribute in HTML for the definition anchor tag.
pub(crate) fn get_definition_id(&self) -> String {
format!("fn.{}", self.get_display_label())
}
}

View File

@@ -2,7 +2,7 @@ use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct IFootnoteReference {
footnote_id: usize,
duplicate_offset: usize,

View File

@@ -4,7 +4,7 @@ use super::registry::Registry;
use super::IDocumentElement;
use super::IObject;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct IHeading {
pub(crate) level: organic::types::HeadlineLevel,
pub(crate) title: Vec<IObject>,

View File

@@ -2,7 +2,7 @@ use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct IHorizontalRule {}
impl IHorizontalRule {

View File

@@ -2,7 +2,7 @@ use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct IInlineBabelCall {}
impl IInlineBabelCall {

View File

@@ -2,7 +2,7 @@ use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct IInlineSourceBlock {
pub(crate) value: String,
}

View File

@@ -2,7 +2,7 @@ use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct IItalic {}
impl IItalic {

View File

@@ -3,7 +3,7 @@ use crate::error::CustomError;
use super::registry::Registry;
/// Essentially a no-op since the keyword is not rendered and any relevant impact on other elements is pulled from the parsed form of keyword.
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct IKeyword {}
impl IKeyword {

View File

@@ -2,7 +2,7 @@ use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct ILatexEnvironment {}
impl ILatexEnvironment {

View File

@@ -2,7 +2,7 @@ use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct ILatexFragment {}
impl ILatexFragment {

View File

@@ -2,7 +2,7 @@ use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct ILineBreak {}
impl ILineBreak {

View File

@@ -62,6 +62,7 @@ mod util;
mod verbatim;
mod verse_block;
pub(crate) use angle_link::IAngleLink;
pub(crate) use ast_node::IAstNode;
pub(crate) use babel_call::IBabelCall;
pub(crate) use bold::IBold;
pub(crate) use center_block::ICenterBlock;
@@ -84,6 +85,7 @@ pub(crate) use export_block::IExportBlock;
pub(crate) use export_snippet::IExportSnippet;
pub(crate) use fixed_width_area::IFixedWidthArea;
pub(crate) use footnote_definition::IFootnoteDefinition;
pub(crate) use footnote_definition::IRealFootnoteDefinition;
pub(crate) use footnote_reference::IFootnoteReference;
pub(crate) use heading::IHeading;
pub(crate) use horizontal_rule::IHorizontalRule;

View File

@@ -30,7 +30,7 @@ use super::verbatim::IVerbatim;
use super::ITarget;
use futures::future::{BoxFuture, FutureExt};
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) enum IObject {
Bold(IBold),
Italic(IItalic),

View File

@@ -2,7 +2,7 @@ use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct IOrgMacro {}
impl IOrgMacro {

View File

@@ -39,13 +39,23 @@ impl BlogPostPage {
));
}
// TODO: Get footnote definitions
let footnotes = {
let footnote_definitions: Vec<_> = registry
.get_footnote_ids()
.map(|(id, def)| (id, def.clone()))
.collect();
let mut ret = Vec::new();
for (id, def) in footnote_definitions.into_iter() {
ret.push(IRealFootnoteDefinition::new(registry, id, def).await?);
}
ret
};
Ok(BlogPostPage {
path,
title: get_title(&document),
children,
footnotes: Vec::new(), // TODO
footnotes,
})
}

View File

@@ -3,7 +3,7 @@ use crate::error::CustomError;
use super::registry::Registry;
use super::IObject;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct IParagraph {
pub(crate) children: Vec<IObject>,
}

View File

@@ -2,7 +2,7 @@ use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct IPlainLink {}
impl IPlainLink {

View File

@@ -3,7 +3,7 @@ use crate::error::CustomError;
use super::registry::Registry;
use super::IPlainListItem;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct IPlainList {
pub(crate) list_type: organic::types::PlainListType,
pub(crate) children: Vec<IPlainListItem>,

View File

@@ -4,7 +4,7 @@ use super::registry::Registry;
use super::IElement;
use super::IObject;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct IPlainListItem {
pub(crate) tag: Vec<IObject>,
pub(crate) children: Vec<IElement>,

View File

@@ -3,7 +3,7 @@ use crate::intermediate::util::coalesce_whitespace;
use super::registry::Registry;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct IPlainText {
pub(crate) source: String,
}

View File

@@ -2,7 +2,7 @@ use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct IPlanning {}
impl IPlanning {

View File

@@ -2,7 +2,7 @@ use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct IPropertyDrawer {}
impl IPropertyDrawer {

View File

@@ -3,7 +3,7 @@ use crate::error::CustomError;
use super::registry::Registry;
use super::IElement;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct IQuoteBlock {
pub(crate) children: Vec<IElement>,
}

View File

@@ -2,7 +2,7 @@ use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct IRadioLink {}
impl IRadioLink {

View File

@@ -2,7 +2,7 @@ use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct IRadioTarget {}
impl IRadioTarget {

View File

@@ -31,6 +31,13 @@ impl<'parse> Registry<'parse> {
})
}
pub(crate) fn get_footnote_ids(&self) -> impl Iterator<Item = (usize, &Vec<IAstNode>)> {
self.footnote_ids
.iter()
.map(|(_label, definition)| definition)
.enumerate()
}
/// Get a 0-indexed ID for a footnote.
///
/// This needs to be incremented to be 1-indexed for render.

View File

@@ -3,7 +3,7 @@ use crate::error::CustomError;
use super::registry::Registry;
use super::IObject;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct IRegularLink {
pub(crate) raw_link: String,
pub(crate) children: Vec<IObject>,

View File

@@ -3,7 +3,7 @@ use crate::error::CustomError;
use super::registry::Registry;
use super::IElement;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct ISection {
pub(crate) children: Vec<IElement>,
}

View File

@@ -2,7 +2,7 @@ use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct ISpecialBlock {}
impl ISpecialBlock {

View File

@@ -2,7 +2,7 @@ use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct ISrcBlock {
pub(crate) lines: Vec<String>,
}

View File

@@ -2,7 +2,7 @@ use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct IStatisticsCookie {}
impl IStatisticsCookie {

View File

@@ -2,7 +2,7 @@ use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct IStrikeThrough {}
impl IStrikeThrough {

View File

@@ -2,7 +2,7 @@ use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct ISubscript {}
impl ISubscript {

View File

@@ -2,7 +2,7 @@ use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct ISuperscript {}
impl ISuperscript {

View File

@@ -2,7 +2,7 @@ use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct ITable {}
impl ITable {

View File

@@ -3,7 +3,7 @@ use crate::intermediate::util::coalesce_whitespace;
use super::registry::Registry;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct ITarget {
pub(crate) id: String,
value: String,

View File

@@ -2,7 +2,7 @@ use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct ITimestamp {}
impl ITimestamp {

View File

@@ -2,7 +2,7 @@ use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct IUnderline {}
impl IUnderline {

View File

@@ -2,7 +2,7 @@ use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct IVerbatim {}
impl IVerbatim {

View File

@@ -2,7 +2,7 @@ use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub(crate) struct IVerseBlock {}
impl IVerseBlock {