summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorMartin <mhaug@live.de>2021-08-23 23:56:33 +0200
committerGitHub <noreply@github.com>2021-08-23 23:56:33 +0200
commitd546453880721d7a12ea228e5c1ed6c65b653ca2 (patch)
tree6dee8615a0755f2376d557328eee070de2dcb744 /src/library
parent0806af4aecc9414962b13894a2a3c4befd2ca3c8 (diff)
Links! (#43)
Co-authored-by: Laurenz <laurmaedje@gmail.com>
Diffstat (limited to 'src/library')
-rw-r--r--src/library/mod.rs1
-rw-r--r--src/library/text.rs17
2 files changed, 17 insertions, 1 deletions
diff --git a/src/library/mod.rs b/src/library/mod.rs
index 44f1f01f..9d25a008 100644
--- a/src/library/mod.rs
+++ b/src/library/mod.rs
@@ -35,6 +35,7 @@ pub fn new() -> Scope {
std.def_func("strike", strike);
std.def_func("underline", underline);
std.def_func("overline", overline);
+ std.def_func("link", link);
// Layout.
std.def_func("page", page);
diff --git a/src/library/text.rs b/src/library/text.rs
index bde2a9aa..cfd2de99 100644
--- a/src/library/text.rs
+++ b/src/library/text.rs
@@ -1,4 +1,4 @@
-use crate::eval::{FontState, LineState};
+use crate::eval::{Decoration, FontState, LineState};
use crate::layout::Paint;
use super::*;
@@ -197,3 +197,18 @@ fn line_impl(
Ok(Value::Template(template))
}
+
+/// `link`: Set a link.
+pub fn link(_: &mut EvalContext, args: &mut Arguments) -> TypResult<Value> {
+ let url = args.expect::<Str>("url")?;
+
+ let mut body = args.eat().unwrap_or_else(|| {
+ let mut template = Template::new();
+ template.text(&url);
+ template
+ });
+
+ body.decorate(Decoration::Link(url.into()));
+
+ Ok(Value::Template(body))
+}