Implement get_contents for footnote references.

This commit is contained in:
Tom Alexander 2023-10-31 22:41:45 -04:00
parent 90ba17b68c
commit d2f2bdf88d
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
8 changed files with 73 additions and 68 deletions

View File

@ -2,6 +2,7 @@ use nom::branch::alt;
use nom::bytes::complete::tag;
use nom::bytes::complete::tag_no_case;
use nom::combinator::all_consuming;
use nom::combinator::consumed;
use nom::combinator::map_parser;
use nom::combinator::verify;
use nom::multi::many1;
@ -59,7 +60,7 @@ fn anonymous_footnote<'b, 'g, 'r, 's>(
let initial_context = ContextElement::document_context();
let initial_context = Context::new(context.get_global_settings(), List::new(&initial_context));
let (remaining, children) = map_parser(
let (remaining, (contents, children)) = consumed(map_parser(
verify(
parser_with_context!(text_until_exit)(&parser_context),
|text| text.len() > 0,
@ -69,7 +70,7 @@ fn anonymous_footnote<'b, 'g, 'r, 's>(
&initial_context,
)))(i)
}),
)(remaining)?;
))(remaining)?;
let (remaining, _) = tag("]")(remaining)?;
@ -80,6 +81,7 @@ fn anonymous_footnote<'b, 'g, 'r, 's>(
remaining,
FootnoteReference {
source: source.into(),
contents: Some(contents.into()),
label: None,
definition: children,
},
@ -106,7 +108,7 @@ fn inline_footnote<'b, 'g, 'r, 's>(
let initial_context = ContextElement::document_context();
let initial_context = Context::new(context.get_global_settings(), List::new(&initial_context));
let (remaining, children) = map_parser(
let (remaining, (contents, children)) = consumed(map_parser(
verify(
parser_with_context!(text_until_exit)(&parser_context),
|text| text.len() > 0,
@ -116,7 +118,7 @@ fn inline_footnote<'b, 'g, 'r, 's>(
&initial_context,
)))(i)
}),
)(remaining)?;
))(remaining)?;
let (remaining, _) = tag("]")(remaining)?;
@ -127,6 +129,7 @@ fn inline_footnote<'b, 'g, 'r, 's>(
remaining,
FootnoteReference {
source: source.into(),
contents: Some(contents.into()),
label: Some(label_contents.into()),
definition: children,
},
@ -151,6 +154,7 @@ fn footnote_reference_only<'b, 'g, 'r, 's>(
remaining,
FootnoteReference {
source: source.into(),
contents: None,
label: Some(label_contents.into()),
definition: Vec::with_capacity(0),
},

View File

@ -324,7 +324,7 @@ impl<'r, 's> StandardProperties<'s> for AstNode<'r, 's> {
}
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
match self {
AstNode::Document(inner) => inner.get_contents(),
AstNode::Heading(inner) => inner.get_contents(),

View File

@ -59,7 +59,7 @@ impl<'s> StandardProperties<'s> for Document<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -73,7 +73,7 @@ impl<'s> StandardProperties<'s> for Section<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -87,7 +87,7 @@ impl<'s> StandardProperties<'s> for Heading<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -152,7 +152,7 @@ impl<'s> StandardProperties<'s> for DocumentElement<'s> {
}
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
match self {
DocumentElement::Heading(inner) => inner.get_contents(),
DocumentElement::Section(inner) => inner.get_contents(),

View File

@ -84,7 +84,7 @@ impl<'s> StandardProperties<'s> for Element<'s> {
}
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
match self {
Element::Paragraph(inner) => inner.get_contents(),
Element::PlainList(inner) => inner.get_contents(),

View File

@ -133,7 +133,7 @@ impl<'s> StandardProperties<'s> for PlainList<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -147,7 +147,7 @@ impl<'s> StandardProperties<'s> for PlainListItem<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -161,7 +161,7 @@ impl<'s> StandardProperties<'s> for CenterBlock<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -175,7 +175,7 @@ impl<'s> StandardProperties<'s> for QuoteBlock<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -189,7 +189,7 @@ impl<'s> StandardProperties<'s> for SpecialBlock<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -203,7 +203,7 @@ impl<'s> StandardProperties<'s> for DynamicBlock<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -217,7 +217,7 @@ impl<'s> StandardProperties<'s> for FootnoteDefinition<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -231,7 +231,7 @@ impl<'s> StandardProperties<'s> for Drawer<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -245,7 +245,7 @@ impl<'s> StandardProperties<'s> for PropertyDrawer<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -259,7 +259,7 @@ impl<'s> StandardProperties<'s> for NodeProperty<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -273,7 +273,7 @@ impl<'s> StandardProperties<'s> for Table<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -287,7 +287,7 @@ impl<'s> StandardProperties<'s> for TableRow<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}

View File

@ -200,7 +200,7 @@ impl<'s> StandardProperties<'s> for Paragraph<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -214,7 +214,7 @@ impl<'s> StandardProperties<'s> for TableCell<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -228,7 +228,7 @@ impl<'s> StandardProperties<'s> for Comment<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -242,7 +242,7 @@ impl<'s> StandardProperties<'s> for VerseBlock<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -255,7 +255,7 @@ impl<'s> StandardProperties<'s> for CommentBlock<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -268,7 +268,7 @@ impl<'s> StandardProperties<'s> for ExampleBlock<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -281,7 +281,7 @@ impl<'s> StandardProperties<'s> for ExportBlock<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -294,7 +294,7 @@ impl<'s> StandardProperties<'s> for SrcBlock<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -308,7 +308,7 @@ impl<'s> StandardProperties<'s> for Clock<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -322,7 +322,7 @@ impl<'s> StandardProperties<'s> for DiarySexp<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -336,7 +336,7 @@ impl<'s> StandardProperties<'s> for Planning<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -350,7 +350,7 @@ impl<'s> StandardProperties<'s> for FixedWidthArea<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -364,7 +364,7 @@ impl<'s> StandardProperties<'s> for HorizontalRule<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -378,7 +378,7 @@ impl<'s> StandardProperties<'s> for Keyword<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -392,7 +392,7 @@ impl<'s> StandardProperties<'s> for BabelCall<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -406,7 +406,7 @@ impl<'s> StandardProperties<'s> for LatexEnvironment<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}

View File

@ -192,6 +192,7 @@ pub struct ExportSnippet<'s> {
#[derive(Debug)]
pub struct FootnoteReference<'s> {
pub source: &'s str,
pub contents: Option<&'s str>,
pub label: Option<&'s str>,
pub definition: Vec<Object<'s>>,
}
@ -520,7 +521,7 @@ impl<'s> StandardProperties<'s> for Bold<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -534,7 +535,7 @@ impl<'s> StandardProperties<'s> for Italic<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -548,7 +549,7 @@ impl<'s> StandardProperties<'s> for Underline<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -562,7 +563,7 @@ impl<'s> StandardProperties<'s> for StrikeThrough<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -576,7 +577,7 @@ impl<'s> StandardProperties<'s> for Code<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -590,7 +591,7 @@ impl<'s> StandardProperties<'s> for Verbatim<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -604,7 +605,7 @@ impl<'s> StandardProperties<'s> for RegularLink<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -618,7 +619,7 @@ impl<'s> StandardProperties<'s> for RadioLink<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -632,7 +633,7 @@ impl<'s> StandardProperties<'s> for RadioTarget<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -646,7 +647,7 @@ impl<'s> StandardProperties<'s> for PlainLink<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -660,7 +661,7 @@ impl<'s> StandardProperties<'s> for AngleLink<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -674,7 +675,7 @@ impl<'s> StandardProperties<'s> for OrgMacro<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -688,7 +689,7 @@ impl<'s> StandardProperties<'s> for Entity<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -702,7 +703,7 @@ impl<'s> StandardProperties<'s> for LatexFragment<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -716,7 +717,7 @@ impl<'s> StandardProperties<'s> for ExportSnippet<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -730,8 +731,8 @@ impl<'s> StandardProperties<'s> for FootnoteReference<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
todo!()
fn get_contents<'b>(&'b self) -> Option<&'s str> {
self.contents
}
fn get_post_blank<'b>(&'b self) -> PostBlank {
@ -744,7 +745,7 @@ impl<'s> StandardProperties<'s> for Citation<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -758,7 +759,7 @@ impl<'s> StandardProperties<'s> for CitationReference<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -772,7 +773,7 @@ impl<'s> StandardProperties<'s> for InlineBabelCall<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -786,7 +787,7 @@ impl<'s> StandardProperties<'s> for InlineSourceBlock<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -800,7 +801,7 @@ impl<'s> StandardProperties<'s> for LineBreak<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -814,7 +815,7 @@ impl<'s> StandardProperties<'s> for Target<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -828,7 +829,7 @@ impl<'s> StandardProperties<'s> for StatisticsCookie<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -842,7 +843,7 @@ impl<'s> StandardProperties<'s> for Subscript<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -856,7 +857,7 @@ impl<'s> StandardProperties<'s> for Superscript<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -870,7 +871,7 @@ impl<'s> StandardProperties<'s> for Timestamp<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -884,7 +885,7 @@ impl<'s> StandardProperties<'s> for PlainText<'s> {
self.source
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
}
@ -1017,7 +1018,7 @@ impl<'s> StandardProperties<'s> for Object<'s> {
}
}
fn get_contents<'b>(&'b self) -> &'s str {
fn get_contents<'b>(&'b self) -> Option<&'s str> {
match self {
Object::Bold(inner) => inner.get_contents(),
Object::Italic(inner) => inner.get_contents(),

View File

@ -8,7 +8,7 @@ pub trait StandardProperties<'s> {
/// Get the slice of the AST node's contents.
///
/// This corresponds to :contents-begin to :contents-end
fn get_contents<'b>(&'b self) -> &'s str;
fn get_contents<'b>(&'b self) -> Option<&'s str>;
/// Get the ast node's post-blank.
///