lib: fix url in autolink/email end event

was constant ">" instead of actual url
This commit is contained in:
Noah Hellman 2023-04-10 18:09:42 +02:00
parent 3c17d6df49
commit d2d7f5d474
2 changed files with 36 additions and 5 deletions

View file

@ -557,8 +557,9 @@ impl<'s> Parser<'s> {
self.input.span = self.input.span.after(len); self.input.span = self.input.span.after(len);
self.push(EventKind::Enter(Autolink)); self.push(EventKind::Enter(Autolink));
self.push(EventKind::Str); self.push(EventKind::Str);
self.push(EventKind::Exit(Autolink));
self.input.span = self.input.span.after(1); self.input.span = self.input.span.after(1);
return self.push(EventKind::Exit(Autolink)); return Some(Continue);
} }
} }
None None
@ -1507,22 +1508,22 @@ mod test {
"<https://example.com>", "<https://example.com>",
(Enter(Autolink), "https://example.com"), (Enter(Autolink), "https://example.com"),
(Str, "https://example.com"), (Str, "https://example.com"),
(Exit(Autolink), ">") (Exit(Autolink), "https://example.com")
); );
test_parse!( test_parse!(
"<a@b.c>", "<a@b.c>",
(Enter(Autolink), "a@b.c"), (Enter(Autolink), "a@b.c"),
(Str, "a@b.c"), (Str, "a@b.c"),
(Exit(Autolink), ">"), (Exit(Autolink), "a@b.c"),
); );
test_parse!( test_parse!(
"<http://a.b><http://c.d>", "<http://a.b><http://c.d>",
(Enter(Autolink), "http://a.b"), (Enter(Autolink), "http://a.b"),
(Str, "http://a.b"), (Str, "http://a.b"),
(Exit(Autolink), ">"), (Exit(Autolink), "http://a.b"),
(Enter(Autolink), "http://c.d"), (Enter(Autolink), "http://c.d"),
(Str, "http://c.d"), (Str, "http://c.d"),
(Exit(Autolink), ">") (Exit(Autolink), "http://c.d"),
); );
test_parse!("<not-a-url>", (Str, "<not-a-url>")); test_parse!("<not-a-url>", (Str, "<not-a-url>"));
} }

View file

@ -1540,6 +1540,36 @@ mod test {
); );
} }
#[test]
fn autolink() {
test_parse!(
"<proto:url>\n",
Start(Paragraph, Attributes::new()),
Start(
Link("proto:url".into(), LinkType::AutoLink),
Attributes::new()
),
Str("proto:url".into()),
End(Link("proto:url".into(), LinkType::AutoLink)),
End(Paragraph),
);
}
#[test]
fn email() {
test_parse!(
"<name@domain>\n",
Start(Paragraph, Attributes::new()),
Start(
Link("name@domain".into(), LinkType::Email),
Attributes::new()
),
Str("name@domain".into()),
End(Link("name@domain".into(), LinkType::Email)),
End(Paragraph),
);
}
#[test] #[test]
fn footnote_references() { fn footnote_references() {
test_parse!( test_parse!(