diff options
Diffstat (limited to 'src/library/link.rs')
| -rw-r--r-- | src/library/link.rs | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/src/library/link.rs b/src/library/link.rs index a27908c7..a43c5290 100644 --- a/src/library/link.rs +++ b/src/library/link.rs @@ -5,10 +5,22 @@ use super::TextNode; use crate::util::EcoString; /// Link text and other elements to an URL. -pub struct LinkNode; +#[derive(Debug, Hash)] +pub struct LinkNode { + /// The url the link points to. + pub url: EcoString, + /// How the link is represented. + pub body: Template, +} #[class] impl LinkNode { + /// The fill color of text in the link. Just the surrounding text color + /// if `auto`. + pub const FILL: Smart<Paint> = Smart::Auto; + /// Whether to underline link. + pub const UNDERLINE: bool = true; + fn construct(_: &mut EvalContext, args: &mut Args) -> TypResult<Template> { let url = args.expect::<EcoString>("url")?; let body = args.find().unwrap_or_else(|| { @@ -20,6 +32,24 @@ impl LinkNode { Template::Text(if shorter { text.into() } else { url.clone() }) }); - Ok(body.styled(TextNode::LINK, Some(url))) + Ok(Template::show(Self { url, body })) + } +} + +impl Show for LinkNode { + fn show(&self, styles: StyleChain) -> Template { + let mut map = StyleMap::new(); + map.set(TextNode::LINK, Some(self.url.clone())); + + if let Smart::Custom(fill) = styles.get(Self::FILL) { + map.set(TextNode::FILL, fill); + } + + let mut body = self.body.clone(); + if styles.get(Self::UNDERLINE) { + body = body.underlined(); + } + + body.styled_with_map(map) } } |
