diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-01-05 14:49:14 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-01-05 15:06:42 +0100 |
| commit | f7e8624b4cf31744d600167dd7f3a9d9d1626014 (patch) | |
| tree | 0941c8db497befc47a666d3d1384db4ab9fc5133 /src/library/link.rs | |
| parent | 4c81a5d43eabd959dbb500a8076f99f21bd037bd (diff) | |
Refactor
Diffstat (limited to 'src/library/link.rs')
| -rw-r--r-- | src/library/link.rs | 21 |
1 files changed, 7 insertions, 14 deletions
diff --git a/src/library/link.rs b/src/library/link.rs index d1d7842d..1050963c 100644 --- a/src/library/link.rs +++ b/src/library/link.rs @@ -1,9 +1,10 @@ //! Hyperlinking. use super::prelude::*; +use super::{ImageNode, ShapeNode, TextNode}; use crate::util::EcoString; -/// `link`: Link text or other elements. +/// `link`: Link text and other elements to an URL. 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(|| { @@ -14,17 +15,9 @@ pub fn link(_: &mut EvalContext, args: &mut Args) -> TypResult<Value> { 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; + let mut passed = StyleMap::new(); + passed.set(TextNode::LINK, Some(url.clone())); + passed.set(ImageNode::LINK, Some(url.clone())); + passed.set(ShapeNode::LINK, Some(url)); + Ok(Value::Node(body.styled(passed))) } |
