blob: d1d7842dffbb37adbe6105bf8446700bbc2207b3 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
//! Hyperlinking.
use super::prelude::*;
use crate::util::EcoString;
/// `link`: Link text or other elements.
pub fn link(_: &mut EvalContext, args: &mut Args) -> TypResult<Value> {
let url: String = args.expect::<EcoString>("url")?.into();
let body = args.find().unwrap_or_else(|| {
let mut text = url.as_str();
for prefix in ["mailto:", "tel:"] {
text = text.trim_start_matches(prefix);
}
Node::Text(text.into())
});
Ok(Value::Node(
body.styled(StyleMap::with(LinkNode::URL, Some(url))),
))
}
/// Host for link styles.
#[derive(Debug, Hash)]
pub struct LinkNode;
#[properties]
impl LinkNode {
/// An URL to link to.
pub const URL: Option<String> = None;
}
|