diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-02-08 16:39:37 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-02-09 12:34:19 +0100 |
| commit | e089b6ea40015e012302dc55ac5d6cb42ca4876e (patch) | |
| tree | dbb66237cb996bc880560dfd94ac9b682e1ac985 /src/library/link.rs | |
| parent | 68503b9a07b00bce3f4d377bcfe945452de815ea (diff) | |
Set rules for everything
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) } } |
