inline: parse multiline attributes
reimplement after broken by "take str per line instead of full inline iter" commit also resolves #18 and #34
This commit is contained in:
parent
3d42820001
commit
62d33effc4
4 changed files with 351 additions and 112 deletions
101
src/lib.rs
101
src/lib.rs
|
@ -793,23 +793,15 @@ impl<'s> Parser<'s> {
|
|||
}
|
||||
|
||||
fn inline(&mut self) -> Option<Event<'s>> {
|
||||
let mut inline = self.inline_parser.next();
|
||||
let next = self.inline_parser.next()?;
|
||||
|
||||
inline.as_ref()?;
|
||||
|
||||
let mut first_is_attr = false;
|
||||
let mut attributes = inline.as_ref().map_or_else(Attributes::new, |inl| {
|
||||
if let inline::EventKind::Attributes { .. } = inl.kind {
|
||||
first_is_attr = true;
|
||||
attr::parse(inl.span.of(self.src))
|
||||
} else {
|
||||
Attributes::new()
|
||||
}
|
||||
});
|
||||
|
||||
if first_is_attr {
|
||||
inline = self.inline_parser.next();
|
||||
}
|
||||
let (inline, mut attributes) = match next {
|
||||
inline::Event {
|
||||
kind: inline::EventKind::Attributes { attrs, .. },
|
||||
..
|
||||
} => (self.inline_parser.next(), attrs),
|
||||
inline => (Some(inline), Attributes::new()),
|
||||
};
|
||||
|
||||
inline.map(|inline| {
|
||||
let enter = matches!(inline.kind, inline::EventKind::Enter(_));
|
||||
|
@ -1706,7 +1698,6 @@ mod test {
|
|||
);
|
||||
}
|
||||
|
||||
#[ignore = "broken"]
|
||||
#[test]
|
||||
fn attr_inline_consecutive() {
|
||||
test_parse!(
|
||||
|
@ -1733,7 +1724,6 @@ mod test {
|
|||
);
|
||||
}
|
||||
|
||||
#[ignore = "broken"]
|
||||
#[test]
|
||||
fn attr_inline_consecutive_invalid() {
|
||||
test_parse!(
|
||||
|
@ -1776,7 +1766,6 @@ mod test {
|
|||
);
|
||||
}
|
||||
|
||||
#[ignore = "multiline attributes broken"]
|
||||
#[test]
|
||||
fn attr_inline_multiline() {
|
||||
test_parse!(
|
||||
|
@ -1792,6 +1781,80 @@ mod test {
|
|||
End(Paragraph),
|
||||
End(Blockquote),
|
||||
);
|
||||
test_parse!(
|
||||
concat!(
|
||||
"> a{\n", //
|
||||
"> %%\n", //
|
||||
"> a=a}\n", //
|
||||
),
|
||||
Start(Blockquote, Attributes::new()),
|
||||
Start(Paragraph, Attributes::new()),
|
||||
Start(Span, [("a", "a")].into_iter().collect()),
|
||||
Str("a".into()),
|
||||
End(Span),
|
||||
End(Paragraph),
|
||||
End(Blockquote),
|
||||
);
|
||||
test_parse!(
|
||||
concat!(
|
||||
"> a{a=\"a\n", //
|
||||
"> b\n", //
|
||||
"> c\"}\n", //
|
||||
),
|
||||
Start(Blockquote, Attributes::new()),
|
||||
Start(Paragraph, Attributes::new()),
|
||||
Start(Span, [("a", "a b c")].into_iter().collect()),
|
||||
Str("a".into()),
|
||||
End(Span),
|
||||
End(Paragraph),
|
||||
End(Blockquote),
|
||||
);
|
||||
test_parse!(
|
||||
concat!(
|
||||
"> a{a=\"\n", //
|
||||
"> b\"}\n", //
|
||||
),
|
||||
Start(Blockquote, Attributes::new()),
|
||||
Start(Paragraph, Attributes::new()),
|
||||
Start(Span, [("a", "b")].into_iter().collect()),
|
||||
Str("a".into()),
|
||||
End(Span),
|
||||
End(Paragraph),
|
||||
End(Blockquote),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn attr_inline_multiline_unclosed() {
|
||||
test_parse!(
|
||||
concat!(
|
||||
"a{\n", //
|
||||
" b\n", //
|
||||
),
|
||||
Start(Paragraph, Attributes::new()),
|
||||
Str("a{".into()),
|
||||
Softbreak,
|
||||
Str("b".into()),
|
||||
End(Paragraph),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn attr_inline_multiline_invalid() {
|
||||
test_parse!(
|
||||
concat!(
|
||||
"a{a=b\n", //
|
||||
" b\n", //
|
||||
"}", //
|
||||
),
|
||||
Start(Paragraph, Attributes::new()),
|
||||
Str("a{a=b".into()),
|
||||
Softbreak,
|
||||
Str("b".into()),
|
||||
Softbreak,
|
||||
Str("}".into()),
|
||||
End(Paragraph),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue