Port dynamic block.

This commit is contained in:
Tom Alexander
2023-10-12 16:46:15 -04:00
parent d1223dcdb7
commit 9ccdcaac24
3 changed files with 38 additions and 29 deletions

View File

@@ -1,9 +1,7 @@
use nom::branch::alt;
use nom::combinator::map;
use nom::combinator::opt;
use nom::combinator::peek;
use nom::multi::many0;
use nom::sequence::tuple;
#[cfg(feature = "tracing")]
use tracing::span;
@@ -82,7 +80,15 @@ fn _element<'b, 'g, 'r, 's>(
input
);
let dynamic_block_matcher = parser_with_context!(dynamic_block)(context);
ak_element!(
dynamic_block,
&mut affiliated_keywords,
post_affiliated_keywords_input,
context,
input,
Element::DynamicBlock
);
let footnote_definition_matcher = parser_with_context!(footnote_definition)(context);
let comment_matcher = parser_with_context!(comment)(context);
let drawer_matcher = parser_with_context!(drawer)(context);
@@ -100,14 +106,13 @@ fn _element<'b, 'g, 'r, 's>(
let babel_keyword_matcher = parser_with_context!(babel_call)(context);
let latex_environment_matcher = parser_with_context!(latex_environment)(context);
let (mut remaining, mut maybe_element) = {
let (remaining, maybe_element) = {
#[cfg(feature = "tracing")]
let span = span!(tracing::Level::DEBUG, "Main element block");
#[cfg(feature = "tracing")]
let _enter = span.enter();
opt(alt((
map(dynamic_block_matcher, Element::DynamicBlock),
map(footnote_definition_matcher, Element::FootnoteDefinition),
map(comment_matcher, Element::Comment),
map(drawer_matcher, Element::Drawer),
@@ -127,25 +132,27 @@ fn _element<'b, 'g, 'r, 's>(
)))(input)?
};
// Paragraph with affiliated keyword
ak_element!(
paragraph,
&mut affiliated_keywords,
post_affiliated_keywords_input,
context,
input,
Element::Paragraph
);
if can_be_paragraph {
// Paragraph with affiliated keyword
ak_element!(
paragraph,
&mut affiliated_keywords,
post_affiliated_keywords_input,
context,
input,
Element::Paragraph
);
// Paragraph without affiliated keyword
ak_element!(
paragraph,
std::iter::empty(),
input,
context,
input,
Element::Paragraph
);
// Paragraph without affiliated keyword
ak_element!(
paragraph,
std::iter::empty(),
input,
context,
input,
Element::Paragraph
);
}
if maybe_element.is_none() {
return Err(nom::Err::Error(CustomError::MyError(MyError(