Trim mailto: and tel: from links

This commit is contained in:
Laurenz 2021-10-25 14:08:30 +02:00
parent 5e34c81a01
commit 1ca4ff69e2
3 changed files with 5 additions and 1 deletions

View File

@ -199,7 +199,7 @@ pub fn link(_: &mut EvalContext, args: &mut Args) -> TypResult<Value> {
let url = args.expect::<Str>("url")?; let url = args.expect::<Str>("url")?;
let body = args.find().unwrap_or_else(|| { let body = args.find().unwrap_or_else(|| {
let mut template = Template::new(); let mut template = Template::new();
template.text(&url); template.text(url.trim_start_matches("mailto:").trim_start_matches("tel:"));
template template
}); });

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 9.1 KiB

View File

@ -7,6 +7,10 @@
// With line break. // With line break.
This link appears #link("https://google.com/")[in the middle of] a paragraph. This link appears #link("https://google.com/")[in the middle of] a paragraph.
// Prefix is trimmed.
Contact #link("mailto:hi@typst.app") or call #link("tel:123") for more information.
---
// Styled with underline and color. // Styled with underline and color.
#let link(url, body) = link(url, font(fill: rgb("283663"), underline(body))) #let link(url, body) = link(url, font(fill: rgb("283663"), underline(body)))
You could also make the #link("https://html5zombo.com/")[link look way more typical.] You could also make the #link("https://html5zombo.com/")[link look way more typical.]