diff --git a/src/block.rs b/src/block.rs index 9057a06..2ce775d 100644 --- a/src/block.rs +++ b/src/block.rs @@ -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()); } } diff --git a/src/lib.rs b/src/lib.rs index f6800e0..1c2620e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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" }), ); }