parse: do not inline parse link definitions

better match the actual url produced, which is verbatim
This commit is contained in:
Noah Hellman 2023-05-07 11:04:34 +02:00
parent 7c28a068e9
commit bbdb314ae1
2 changed files with 23 additions and 6 deletions

View file

@ -350,7 +350,7 @@ impl<'s> TreeParser<'s> {
k: &Kind,
span_start: Span,
span_end: Span,
lines: &mut [Span],
mut lines: &mut [Span],
) {
if let Kind::Fenced { indent, .. } = k {
for line in lines.iter_mut() {
@ -367,6 +367,18 @@ impl<'s> TreeParser<'s> {
*line = line.trim_start(self.src);
}
// skip first inline if empty
if lines.get(0).map_or(false, |l| l.is_empty()) {
lines = &mut lines[1..];
};
if matches!(leaf, LinkDefinition { .. }) {
// trim ending whitespace of each inline
for line in lines.iter_mut() {
*line = line.trim_end(self.src);
}
}
// trim ending whitespace of block
let l = lines.len();
if l > 0 {
@ -412,7 +424,7 @@ impl<'s> TreeParser<'s> {
}
// trim '#' characters
for line in lines[1..].iter_mut() {
for line in lines.iter_mut().skip(1) {
*line = line.trim_start_matches(self.src, |c| c == '#' || c.is_whitespace());
}
}

View file

@ -1064,6 +1064,7 @@ impl<'s> Parser<'s> {
},
block::Leaf::Caption => Container::Caption,
block::Leaf::LinkDefinition { label } => {
self.verbatim = enter;
Container::LinkDefinition { label }
}
}
@ -1709,7 +1710,6 @@ mod test {
Blankline,
Start(LinkDefinition { label: "tag" }, Attributes::new()),
Str("u".into()),
Softbreak,
Str("rl".into()),
End(LinkDefinition { label: "tag" }),
);
@ -1718,19 +1718,24 @@ mod test {
"[text][tag]\n",
"\n",
"[tag]:\n",
" url\n", //
" url\n", //
" cont\n", //
),
Start(Paragraph, Attributes::new()),
Start(
Link("url".into(), LinkType::Span(SpanLinkType::Reference)),
Link("urlcont".into(), LinkType::Span(SpanLinkType::Reference)),
Attributes::new()
),
Str("text".into()),
End(Link("url".into(), LinkType::Span(SpanLinkType::Reference))),
End(Link(
"urlcont".into(),
LinkType::Span(SpanLinkType::Reference)
)),
End(Paragraph),
Blankline,
Start(LinkDefinition { label: "tag" }, Attributes::new()),
Str("url".into()),
Str("cont".into()),
End(LinkDefinition { label: "tag" }),
);
}