Numerous fixes to property drawers.
This commit is contained in:
parent
b557b9ca5d
commit
603cc131a0
@ -121,20 +121,33 @@ fn zeroth_section<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s s
|
|||||||
class: ExitClass::Document,
|
class: ExitClass::Document,
|
||||||
exit_matcher: §ion_end,
|
exit_matcher: §ion_end,
|
||||||
}));
|
}));
|
||||||
|
let without_consuming_whitespace_context =
|
||||||
|
parser_context.with_additional_node(ContextElement::ConsumeTrailingWhitespace(false));
|
||||||
|
|
||||||
let element_matcher = parser_with_context!(element)(&parser_context);
|
let element_matcher = parser_with_context!(element)(&parser_context);
|
||||||
let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
|
let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
|
||||||
|
|
||||||
let (remaining, (comment_element, property_drawer_element)) = tuple((
|
let (remaining, (comment_element, property_drawer_element)) = tuple((
|
||||||
opt(parser_with_context!(comment)(&parser_context)),
|
opt(parser_with_context!(comment)(
|
||||||
opt(parser_with_context!(property_drawer)(&parser_context)),
|
&without_consuming_whitespace_context,
|
||||||
|
)),
|
||||||
|
opt(parser_with_context!(property_drawer)(
|
||||||
|
&without_consuming_whitespace_context,
|
||||||
|
)),
|
||||||
))(input)?;
|
))(input)?;
|
||||||
|
|
||||||
let (remaining, (mut children, _exit_contents)) = verify(
|
let (remaining, (mut children, _exit_contents)) = verify(
|
||||||
many_till(element_matcher, exit_matcher),
|
many_till(element_matcher, exit_matcher),
|
||||||
|(children, _exit_contents)| !children.is_empty(),
|
|(children, _exit_contents)| {
|
||||||
|
!children.is_empty() || property_drawer_element.is_some() || comment_element.is_some()
|
||||||
|
},
|
||||||
)(remaining)?;
|
)(remaining)?;
|
||||||
property_drawer_element.map(Element::PropertyDrawer).map(|ele| children.insert(0, ele));
|
property_drawer_element
|
||||||
comment_element.map(Element::Comment).map(|ele| children.insert(0, ele));
|
.map(Element::PropertyDrawer)
|
||||||
|
.map(|ele| children.insert(0, ele));
|
||||||
|
comment_element
|
||||||
|
.map(Element::Comment)
|
||||||
|
.map(|ele| children.insert(0, ele));
|
||||||
// children.insert(0, item)
|
// children.insert(0, item)
|
||||||
|
|
||||||
let (remaining, _trailing_ws) =
|
let (remaining, _trailing_ws) =
|
||||||
@ -156,10 +169,15 @@ fn section<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Sec
|
|||||||
}));
|
}));
|
||||||
let element_matcher = parser_with_context!(element)(&parser_context);
|
let element_matcher = parser_with_context!(element)(&parser_context);
|
||||||
let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
|
let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
|
||||||
let (remaining, (children, _exit_contents)) = verify(
|
let (remaining, property_drawer_element) =
|
||||||
|
opt(parser_with_context!(property_drawer)(&parser_context))(input)?;
|
||||||
|
let (remaining, (mut children, _exit_contents)) = verify(
|
||||||
many_till(element_matcher, exit_matcher),
|
many_till(element_matcher, exit_matcher),
|
||||||
|(children, _exit_contents)| !children.is_empty(),
|
|(children, _exit_contents)| !children.is_empty() || property_drawer_element.is_some(),
|
||||||
)(input)?;
|
)(remaining)?;
|
||||||
|
property_drawer_element
|
||||||
|
.map(Element::PropertyDrawer)
|
||||||
|
.map(|ele| children.insert(0, ele));
|
||||||
|
|
||||||
let (remaining, _trailing_ws) =
|
let (remaining, _trailing_ws) =
|
||||||
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||||
|
@ -13,7 +13,6 @@ use super::lesser_element::Comment;
|
|||||||
use super::lesser_element::Paragraph;
|
use super::lesser_element::Paragraph;
|
||||||
use super::paragraph::paragraph;
|
use super::paragraph::paragraph;
|
||||||
use super::plain_list::plain_list;
|
use super::plain_list::plain_list;
|
||||||
use super::property_drawer::property_drawer;
|
|
||||||
use super::source::Source;
|
use super::source::Source;
|
||||||
use super::Context;
|
use super::Context;
|
||||||
use super::Drawer;
|
use super::Drawer;
|
||||||
@ -123,7 +122,6 @@ pub fn non_paragraph_element<'r, 's>(
|
|||||||
let dynamic_block_matcher = parser_with_context!(dynamic_block)(context);
|
let dynamic_block_matcher = parser_with_context!(dynamic_block)(context);
|
||||||
let footnote_definition_matcher = parser_with_context!(footnote_definition)(context);
|
let footnote_definition_matcher = parser_with_context!(footnote_definition)(context);
|
||||||
let comment_matcher = parser_with_context!(comment)(context);
|
let comment_matcher = parser_with_context!(comment)(context);
|
||||||
let property_drawer_matcher = parser_with_context!(property_drawer)(context);
|
|
||||||
let drawer_matcher = parser_with_context!(drawer)(context);
|
let drawer_matcher = parser_with_context!(drawer)(context);
|
||||||
alt((
|
alt((
|
||||||
map(plain_list_matcher, Element::PlainList),
|
map(plain_list_matcher, Element::PlainList),
|
||||||
@ -131,7 +129,6 @@ pub fn non_paragraph_element<'r, 's>(
|
|||||||
map(dynamic_block_matcher, Element::DynamicBlock),
|
map(dynamic_block_matcher, Element::DynamicBlock),
|
||||||
map(footnote_definition_matcher, Element::FootnoteDefinition),
|
map(footnote_definition_matcher, Element::FootnoteDefinition),
|
||||||
map(comment_matcher, Element::Comment),
|
map(comment_matcher, Element::Comment),
|
||||||
map(property_drawer_matcher, Element::PropertyDrawer),
|
|
||||||
map(drawer_matcher, Element::Drawer),
|
map(drawer_matcher, Element::Drawer),
|
||||||
))(input)
|
))(input)
|
||||||
}
|
}
|
||||||
|
@ -76,13 +76,14 @@ fn property_drawer_end<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<
|
|||||||
recognize(tuple((
|
recognize(tuple((
|
||||||
parser_with_context!(start_of_line)(context),
|
parser_with_context!(start_of_line)(context),
|
||||||
space0,
|
space0,
|
||||||
tag(":end:"),
|
tag_no_case(":end:"),
|
||||||
space0,
|
space0,
|
||||||
alt((line_ending, eof)),
|
alt((line_ending, eof)),
|
||||||
)))(input)
|
)))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn node_property<'r, 's>(
|
#[tracing::instrument(ret, level = "debug")]
|
||||||
|
fn node_property<'r, 's>(
|
||||||
context: Context<'r, 's>,
|
context: Context<'r, 's>,
|
||||||
input: &'s str,
|
input: &'s str,
|
||||||
) -> Res<&'s str, NodeProperty<'s>> {
|
) -> Res<&'s str, NodeProperty<'s>> {
|
||||||
@ -106,7 +107,8 @@ pub fn node_property<'r, 's>(
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
let (remaining, (_ws, value)) = tuple((space1, is_not("\r\n")))(remaining)?;
|
let (remaining, (_ws, value, _line_ending)) =
|
||||||
|
tuple((space1, is_not("\r\n"), line_ending))(remaining)?;
|
||||||
let source = get_consumed(input, remaining);
|
let source = get_consumed(input, remaining);
|
||||||
Ok((
|
Ok((
|
||||||
remaining,
|
remaining,
|
||||||
@ -120,10 +122,7 @@ pub fn node_property<'r, 's>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(ret, level = "debug")]
|
#[tracing::instrument(ret, level = "debug")]
|
||||||
pub fn node_property_name<'r, 's>(
|
fn node_property_name<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
|
||||||
context: Context<'r, 's>,
|
|
||||||
input: &'s str,
|
|
||||||
) -> Res<&'s str, &'s str> {
|
|
||||||
let parser_context =
|
let parser_context =
|
||||||
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
|
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||||
class: ExitClass::Beta,
|
class: ExitClass::Beta,
|
||||||
@ -140,7 +139,7 @@ pub fn node_property_name<'r, 's>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(ret, level = "debug")]
|
#[tracing::instrument(ret, level = "debug")]
|
||||||
pub fn node_property_name_end<'r, 's>(
|
fn node_property_name_end<'r, 's>(
|
||||||
context: Context<'r, 's>,
|
context: Context<'r, 's>,
|
||||||
input: &'s str,
|
input: &'s str,
|
||||||
) -> Res<&'s str, &'s str> {
|
) -> Res<&'s str, &'s str> {
|
||||||
|
@ -3,6 +3,10 @@
|
|||||||
|
|
||||||
|
|
||||||
# Blank lines and comments can come before property drawers in the zeroth section
|
# Blank lines and comments can come before property drawers in the zeroth section
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:FOO: bar
|
:FOO: bar
|
||||||
:END:
|
:END:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user