inline: fix label of empty multi-line ref links
e.g. [some text][] [some text]: url
This commit is contained in:
parent
253d1d2d4b
commit
b60650dd0d
2 changed files with 59 additions and 24 deletions
|
@ -732,29 +732,27 @@ impl<'s> Parser<'s> {
|
|||
image,
|
||||
} => {
|
||||
let span_spec = self.events[e_opener].span.end..self.input.span.start;
|
||||
let multiline =
|
||||
let multiline_spec =
|
||||
self.events[e_opener].span.start < self.input.span_line.start;
|
||||
|
||||
let spec: CowStr = if span_spec.is_empty() && !inline {
|
||||
let span_spec = self.events[event_span].span.end
|
||||
..self.events[e_opener - 1].span.start;
|
||||
let events_text = self
|
||||
.events
|
||||
.iter()
|
||||
.skip(event_span + 1)
|
||||
.take(e_opener - event_span - 2);
|
||||
|
||||
if multiline
|
||||
|| events_text.clone().any(|ev| {
|
||||
!matches!(ev.kind, EventKind::Str | EventKind::Atom(..))
|
||||
})
|
||||
{
|
||||
let mut spec = String::new();
|
||||
let mut span = 0..0;
|
||||
for ev in events_text.filter(|ev| {
|
||||
matches!(ev.kind, EventKind::Str | EventKind::Atom(..))
|
||||
&& !matches!(ev.kind, EventKind::Atom(Escape))
|
||||
}) {
|
||||
if span.end == ev.span.start {
|
||||
if matches!(ev.kind, EventKind::Atom(Softbreak | Hardbreak)) {
|
||||
spec.push_str(&self.input.src[span.clone()]);
|
||||
spec.push(' ');
|
||||
span = ev.span.end..ev.span.end;
|
||||
} else if span.end == ev.span.start {
|
||||
span.end = ev.span.end;
|
||||
} else {
|
||||
spec.push_str(&self.input.src[span.clone()]);
|
||||
|
@ -763,10 +761,7 @@ impl<'s> Parser<'s> {
|
|||
}
|
||||
spec.push_str(&self.input.src[span]);
|
||||
spec.into()
|
||||
} else {
|
||||
self.input.src[span_spec].into()
|
||||
}
|
||||
} else if multiline {
|
||||
} else if multiline_spec {
|
||||
let mut spec = String::new();
|
||||
let mut first_part = true;
|
||||
let mut span =
|
||||
|
|
40
src/lib.rs
40
src/lib.rs
|
@ -1697,6 +1697,46 @@ mod test {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn link_reference_multiline_empty() {
|
||||
test_parse!(
|
||||
concat!(
|
||||
"> [a\n", //
|
||||
"> b][]\n", //
|
||||
"> [a\\\n", //
|
||||
"> b][]\n", //
|
||||
"\n", //
|
||||
"[a b]: url\n", //
|
||||
),
|
||||
Start(Blockquote, Attributes::new()),
|
||||
Start(Paragraph, Attributes::new()),
|
||||
Start(
|
||||
Link("url".into(), LinkType::Span(SpanLinkType::Reference)),
|
||||
Attributes::new()
|
||||
),
|
||||
Str("a".into()),
|
||||
Softbreak,
|
||||
Str("b".into()),
|
||||
End(Link("url".into(), LinkType::Span(SpanLinkType::Reference))),
|
||||
Softbreak,
|
||||
Start(
|
||||
Link("url".into(), LinkType::Span(SpanLinkType::Reference)),
|
||||
Attributes::new()
|
||||
),
|
||||
Str("a".into()),
|
||||
Escape,
|
||||
Hardbreak,
|
||||
Str("b".into()),
|
||||
End(Link("url".into(), LinkType::Span(SpanLinkType::Reference))),
|
||||
End(Paragraph),
|
||||
End(Blockquote),
|
||||
Blankline,
|
||||
Start(LinkDefinition { label: "a b" }, Attributes::new()),
|
||||
Str("url".into()),
|
||||
End(LinkDefinition { label: "a b" }),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn link_definition_multiline() {
|
||||
test_parse!(
|
||||
|
|
Loading…
Reference in a new issue