diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-05-27 14:33:00 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-05-27 14:34:27 +0200 |
| commit | f8009b5b59660b8252bd3ee2cedfd234a1c30cb1 (patch) | |
| tree | 1039e298423f017344e3c9369c2872c82168f6ba /src/library | |
| parent | 736289b064c53c215249aad70b3a6a96e79b6021 (diff) | |
Reuse location type
Diffstat (limited to 'src/library')
| -rw-r--r-- | src/library/text/link.rs | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/src/library/text/link.rs b/src/library/text/link.rs index 2ce7a469..12cbaf59 100644 --- a/src/library/text/link.rs +++ b/src/library/text/link.rs @@ -1,6 +1,5 @@ use super::TextNode; use crate::library::prelude::*; -use crate::util::EcoString; /// Link text and other elements to an URL. #[derive(Debug, Hash)] @@ -24,7 +23,7 @@ impl LinkNode { let dest = args.expect::<Destination>("destination")?; let body = match dest { Destination::Url(_) => args.eat()?, - Destination::Internal(_, _) => Some(args.expect("body")?), + Destination::Internal(_) => Some(args.expect("body")?), }; Self { dest, body } })) @@ -36,10 +35,10 @@ castable! { Expected: "string or dictionary with `page`, `x`, and `y` keys", Value::Str(string) => Self::Url(string), Value::Dict(dict) => { - let page: i64 = dict.get(&EcoString::from_str("page"))?.clone().cast()?; - let x: RawLength = dict.get(&EcoString::from_str("x"))?.clone().cast()?; - let y: RawLength = dict.get(&EcoString::from_str("y"))?.clone().cast()?; - Self::Internal(page as usize, Point::new(x.length, y.length)) + let page: i64 = dict.get(&"page".into())?.clone().cast()?; + let x: RawLength = dict.get(&"x".into())?.clone().cast()?; + let y: RawLength = dict.get(&"y".into())?.clone().cast()?; + Self::Internal(Location { page: page as usize, pos: Point::new(x.length, y.length) }) }, } @@ -56,11 +55,7 @@ impl Show for LinkNode { dict! { "url" => match &self.dest { Destination::Url(url) => Value::Str(url.clone()), - Destination::Internal(page, point) => Value::Dict(dict!{ - "page" => Value::Int(*page as i64), - "x" => Value::Length(point.x.into()), - "y" => Value::Length(point.y.into()), - }), + Destination::Internal(loc) => Value::Dict(loc.encode()), }, "body" => match &self.body { Some(body) => Value::Content(body.clone()), @@ -79,7 +74,7 @@ impl Show for LinkNode { let shorter = text.len() < url.len(); Content::Text(if shorter { text.into() } else { url.clone() }) } - Destination::Internal(_, _) => panic!("missing body"), + Destination::Internal(_) => Content::Empty, })) } @@ -99,7 +94,7 @@ impl Show for LinkNode { if match styles.get(Self::UNDERLINE) { Smart::Auto => match &self.dest { Destination::Url(_) => true, - Destination::Internal(_, _) => false, + Destination::Internal(_) => false, }, Smart::Custom(underline) => underline, } { |
