From ecf49100f4ee68cb3653600a018352bde0b2034d Mon Sep 17 00:00:00 2001 From: Noah Hellman Date: Tue, 17 Jan 2023 18:05:34 +0100 Subject: [PATCH] fixup! parser: impl link references --- src/block.rs | 4 ++++ src/lib.rs | 40 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/block.rs b/src/block.rs index ffa0a95..920ea37 100644 --- a/src/block.rs +++ b/src/block.rs @@ -730,6 +730,10 @@ mod test { #[test] fn block_link_definition() { test_block!("[tag]: url\n", Block::Leaf(LinkDefinition), "tag", 1); + } + + #[test] + fn block_link_definition_multiline() { test_block!( concat!( "[tag]: uuu\n", diff --git a/src/lib.rs b/src/lib.rs index 2105091..c1d4737 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -285,7 +285,7 @@ impl<'s> Parser<'s> { { let tag = e.span.of(src); // TODO borrow url string if single inline - let url = tree.inlines().map(|sp| sp.of(src)).collect(); + let url = tree.inlines().map(|sp| sp.of(src).trim()).collect(); defs.insert(tag, url); } } @@ -691,6 +691,44 @@ mod test { ); } + #[test] + fn link_reference_multiline() { + test_parse!( + concat!( + "[text][tag]\n", + "\n", + "[tag]: u\n", + " rl\n", // + ), + Start(Paragraph, Attributes::new()), + Start( + Link("url".into(), LinkType::Span(SpanLinkType::Reference)), + Attributes::new() + ), + Str("text".into()), + End(Link("url".into(), LinkType::Span(SpanLinkType::Reference))), + End(Paragraph), + Atom(Blankline), + ); + test_parse!( + concat!( + "[text][tag]\n", + "\n", + "[tag]:\n", + " url\n", // + ), + Start(Paragraph, Attributes::new()), + Start( + Link("url".into(), LinkType::Span(SpanLinkType::Reference)), + Attributes::new() + ), + Str("text".into()), + End(Link("url".into(), LinkType::Span(SpanLinkType::Reference))), + End(Paragraph), + Atom(Blankline), + ); + } + #[test] fn attr_block() { test_parse!(