Create structure for export snippets.

This commit is contained in:
Tom Alexander
2023-07-19 00:09:16 -04:00
parent eb03342506
commit 1fb8ce9af6
5 changed files with 56 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
use super::Context;
use crate::error::Res;
use crate::parser::util::not_yet_implemented;
use crate::parser::ExportSnippet;
#[tracing::instrument(ret, level = "debug")]
pub fn export_snippet<'r, 's>(
context: Context<'r, 's>,
input: &'s str,
) -> Res<&'s str, ExportSnippet<'s>> {
not_yet_implemented()?;
todo!()
}

View File

@@ -9,6 +9,7 @@ mod element;
mod element_parser;
mod entity;
mod exiting;
mod export_snippet;
mod fixed_width_area;
mod footnote_definition;
mod greater_block;
@@ -73,6 +74,7 @@ pub use object::AngleLink;
pub use object::Bold;
pub use object::Code;
pub use object::Entity;
pub use object::ExportSnippet;
pub use object::Italic;
pub use object::LatexFragment;
pub use object::Object;

View File

@@ -17,6 +17,7 @@ pub enum Object<'s> {
OrgMacro(OrgMacro<'s>),
Entity(Entity<'s>),
LatexFragment(LatexFragment<'s>),
ExportSnippet(ExportSnippet<'s>),
}
#[derive(Debug, PartialEq)]
@@ -109,6 +110,13 @@ pub struct LatexFragment<'s> {
pub source: &'s str,
}
#[derive(Debug, PartialEq)]
pub struct ExportSnippet<'s> {
pub source: &'s str,
pub backend: &'s str,
pub contents: &'s str,
}
impl<'s> Source<'s> for Object<'s> {
fn get_source(&'s self) -> &'s str {
match self {
@@ -127,6 +135,7 @@ impl<'s> Source<'s> for Object<'s> {
Object::OrgMacro(obj) => obj.source,
Object::Entity(obj) => obj.source,
Object::LatexFragment(obj) => obj.source,
Object::ExportSnippet(obj) => obj.source,
}
}
}
@@ -214,3 +223,9 @@ impl<'s> Source<'s> for LatexFragment<'s> {
self.source
}
}
impl<'s> Source<'s> for ExportSnippet<'s> {
fn get_source(&'s self) -> &'s str {
self.source
}
}

View File

@@ -54,6 +54,7 @@ impl<'r, 's> Token<'r, 's> {
Object::OrgMacro(_) => Box::new(std::iter::empty()),
Object::Entity(_) => Box::new(std::iter::empty()),
Object::LatexFragment(_) => Box::new(std::iter::empty()),
Object::ExportSnippet(_) => Box::new(std::iter::empty()),
},
Token::Element(elem) => match elem {
Element::Paragraph(inner) => Box::new(inner.children.iter().map(Token::Object)),