parse: do not inline parse link definitions
better match the actual url produced, which is verbatim
This commit is contained in:
parent
7c28a068e9
commit
bbdb314ae1
2 changed files with 23 additions and 6 deletions
16
src/block.rs
16
src/block.rs
|
@ -350,7 +350,7 @@ impl<'s> TreeParser<'s> {
|
||||||
k: &Kind,
|
k: &Kind,
|
||||||
span_start: Span,
|
span_start: Span,
|
||||||
span_end: Span,
|
span_end: Span,
|
||||||
lines: &mut [Span],
|
mut lines: &mut [Span],
|
||||||
) {
|
) {
|
||||||
if let Kind::Fenced { indent, .. } = k {
|
if let Kind::Fenced { indent, .. } = k {
|
||||||
for line in lines.iter_mut() {
|
for line in lines.iter_mut() {
|
||||||
|
@ -367,6 +367,18 @@ impl<'s> TreeParser<'s> {
|
||||||
*line = line.trim_start(self.src);
|
*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
|
// trim ending whitespace of block
|
||||||
let l = lines.len();
|
let l = lines.len();
|
||||||
if l > 0 {
|
if l > 0 {
|
||||||
|
@ -412,7 +424,7 @@ impl<'s> TreeParser<'s> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// trim '#' characters
|
// 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());
|
*line = line.trim_start_matches(self.src, |c| c == '#' || c.is_whitespace());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
13
src/lib.rs
13
src/lib.rs
|
@ -1064,6 +1064,7 @@ impl<'s> Parser<'s> {
|
||||||
},
|
},
|
||||||
block::Leaf::Caption => Container::Caption,
|
block::Leaf::Caption => Container::Caption,
|
||||||
block::Leaf::LinkDefinition { label } => {
|
block::Leaf::LinkDefinition { label } => {
|
||||||
|
self.verbatim = enter;
|
||||||
Container::LinkDefinition { label }
|
Container::LinkDefinition { label }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1709,7 +1710,6 @@ mod test {
|
||||||
Blankline,
|
Blankline,
|
||||||
Start(LinkDefinition { label: "tag" }, Attributes::new()),
|
Start(LinkDefinition { label: "tag" }, Attributes::new()),
|
||||||
Str("u".into()),
|
Str("u".into()),
|
||||||
Softbreak,
|
|
||||||
Str("rl".into()),
|
Str("rl".into()),
|
||||||
End(LinkDefinition { label: "tag" }),
|
End(LinkDefinition { label: "tag" }),
|
||||||
);
|
);
|
||||||
|
@ -1718,19 +1718,24 @@ mod test {
|
||||||
"[text][tag]\n",
|
"[text][tag]\n",
|
||||||
"\n",
|
"\n",
|
||||||
"[tag]:\n",
|
"[tag]:\n",
|
||||||
" url\n", //
|
" url\n", //
|
||||||
|
" cont\n", //
|
||||||
),
|
),
|
||||||
Start(Paragraph, Attributes::new()),
|
Start(Paragraph, Attributes::new()),
|
||||||
Start(
|
Start(
|
||||||
Link("url".into(), LinkType::Span(SpanLinkType::Reference)),
|
Link("urlcont".into(), LinkType::Span(SpanLinkType::Reference)),
|
||||||
Attributes::new()
|
Attributes::new()
|
||||||
),
|
),
|
||||||
Str("text".into()),
|
Str("text".into()),
|
||||||
End(Link("url".into(), LinkType::Span(SpanLinkType::Reference))),
|
End(Link(
|
||||||
|
"urlcont".into(),
|
||||||
|
LinkType::Span(SpanLinkType::Reference)
|
||||||
|
)),
|
||||||
End(Paragraph),
|
End(Paragraph),
|
||||||
Blankline,
|
Blankline,
|
||||||
Start(LinkDefinition { label: "tag" }, Attributes::new()),
|
Start(LinkDefinition { label: "tag" }, Attributes::new()),
|
||||||
Str("url".into()),
|
Str("url".into()),
|
||||||
|
Str("cont".into()),
|
||||||
End(LinkDefinition { label: "tag" }),
|
End(LinkDefinition { label: "tag" }),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue