inline: allow empty span when followed by url/label/attrs

allow e.g. images without alt text ![](url)
This commit is contained in:
Noah Hellman 2023-05-08 21:35:25 +02:00
parent 329207689b
commit b2d15383e7
2 changed files with 35 additions and 2 deletions

View file

@ -649,7 +649,9 @@ impl<'s> Parser<'s> {
(e, e + 1)
};
if e_opener == self.events.len() - 1 && !matches!(opener, Opener::Link { .. }) {
if e_opener == self.events.len() - 1
&& !matches!(opener, Opener::Link { .. } | Opener::Span { .. })
{
// empty container
return None;
}
@ -1469,6 +1471,38 @@ mod test {
test_parse!("[abc]", (Str, "[abc]"));
}
#[test]
fn span_no_text() {
test_parse!("[]", (Str, "[]"));
test_parse!(
"[](url)",
(Enter(InlineLink(0)), "["),
(Exit(InlineLink(0)), "](url)"),
);
test_parse!(
"![](url)",
(Enter(InlineImage(0)), "!["),
(Exit(InlineImage(0)), "](url)"),
);
test_parse!(
"[][label]",
(Enter(ReferenceLink(0)), "["),
(Exit(ReferenceLink(0)), "][label]"),
);
test_parse!(
"[]{.cls}",
(
Attributes {
container: true,
attrs: 0
},
"{.cls}",
),
(Enter(Span), "["),
(Exit(Span), "]")
);
}
#[test]
fn span_attr() {
test_parse!(

View file

@ -1,3 +1,2 @@
block_list_flat:large list marker number
inline_links_flat:space before img, img attrs order
inline_links_nested:empty link text