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,41 +732,36 @@ impl<'s> Parser<'s> {
|
||||||
image,
|
image,
|
||||||
} => {
|
} => {
|
||||||
let span_spec = self.events[e_opener].span.end..self.input.span.start;
|
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;
|
self.events[e_opener].span.start < self.input.span_line.start;
|
||||||
|
|
||||||
let spec: CowStr = if span_spec.is_empty() && !inline {
|
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
|
let events_text = self
|
||||||
.events
|
.events
|
||||||
.iter()
|
.iter()
|
||||||
.skip(event_span + 1)
|
.skip(event_span + 1)
|
||||||
.take(e_opener - event_span - 2);
|
.take(e_opener - event_span - 2);
|
||||||
|
|
||||||
if multiline
|
let mut spec = String::new();
|
||||||
|| events_text.clone().any(|ev| {
|
let mut span = 0..0;
|
||||||
!matches!(ev.kind, EventKind::Str | EventKind::Atom(..))
|
for ev in events_text.filter(|ev| {
|
||||||
})
|
matches!(ev.kind, EventKind::Str | EventKind::Atom(..))
|
||||||
{
|
&& !matches!(ev.kind, EventKind::Atom(Escape))
|
||||||
let mut spec = String::new();
|
}) {
|
||||||
let mut span = 0..0;
|
if matches!(ev.kind, EventKind::Atom(Softbreak | Hardbreak)) {
|
||||||
for ev in events_text.filter(|ev| {
|
spec.push_str(&self.input.src[span.clone()]);
|
||||||
matches!(ev.kind, EventKind::Str | EventKind::Atom(..))
|
spec.push(' ');
|
||||||
}) {
|
span = ev.span.end..ev.span.end;
|
||||||
if span.end == ev.span.start {
|
} else if span.end == ev.span.start {
|
||||||
span.end = ev.span.end;
|
span.end = ev.span.end;
|
||||||
} else {
|
} else {
|
||||||
spec.push_str(&self.input.src[span.clone()]);
|
spec.push_str(&self.input.src[span.clone()]);
|
||||||
span = ev.span.clone();
|
span = ev.span.clone();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
spec.push_str(&self.input.src[span]);
|
|
||||||
spec.into()
|
|
||||||
} else {
|
|
||||||
self.input.src[span_spec].into()
|
|
||||||
}
|
}
|
||||||
} else if multiline {
|
spec.push_str(&self.input.src[span]);
|
||||||
|
spec.into()
|
||||||
|
} else if multiline_spec {
|
||||||
let mut spec = String::new();
|
let mut spec = String::new();
|
||||||
let mut first_part = true;
|
let mut first_part = true;
|
||||||
let mut span =
|
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]
|
#[test]
|
||||||
fn link_definition_multiline() {
|
fn link_definition_multiline() {
|
||||||
test_parse!(
|
test_parse!(
|
||||||
|
|
Loading…
Reference in a new issue