Implement parser for inline footnotes.

This commit is contained in:
Tom Alexander 2023-07-19 23:20:17 -04:00
parent a36a820e84
commit b850f59640
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -15,7 +15,6 @@ use crate::parser::parser_context::FootnoteReferenceDefinition;
use crate::parser::parser_with_context::parser_with_context;
use crate::parser::util::exit_matcher_parser;
use crate::parser::util::get_consumed;
use crate::parser::util::not_yet_implemented;
use crate::parser::FootnoteReference;
use crate::parser::Object;
@ -39,6 +38,7 @@ fn anonymous_footnote<'r, 's>(
depth: 0,
},
));
// TODO: I could insert FootnoteReferenceDefinition entries in the context after each matched object to reduce the scanning done for counting brackets which should be more efficient.
let (remaining, (children, _exit_contents)) = verify(
many_till(
parser_with_context!(standard_set_object)(&parser_context),
@ -63,8 +63,33 @@ fn inline_footnote<'r, 's>(
context: Context<'r, 's>,
input: &'s str,
) -> Res<&'s str, FootnoteReference<'s>> {
not_yet_implemented()?;
todo!()
let (remaining, _) = tag_no_case("[fn:")(input)?;
let (remaining, label_contents) = label(remaining)?;
let (remaining, _) = tag(":")(remaining)?;
let parser_context = context.with_additional_node(ContextElement::FootnoteReferenceDefinition(
FootnoteReferenceDefinition {
position: remaining,
depth: 0,
},
));
// TODO: I could insert FootnoteReferenceDefinition entries in the context after each matched object to reduce the scanning done for counting brackets which should be more efficient.
let (remaining, (children, _exit_contents)) = verify(
many_till(
parser_with_context!(standard_set_object)(&parser_context),
parser_with_context!(exit_matcher_parser)(&parser_context),
),
|(children, exit_contents)| !children.is_empty() && exit_contents == &"]",
)(remaining)?;
let source = get_consumed(input, remaining);
Ok((
remaining,
FootnoteReference {
source,
label: Some(label_contents),
definition: children,
},
))
}
#[tracing::instrument(ret, level = "debug")]