summaryrefslogtreecommitdiff
path: root/src/library/text
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-05-06 10:05:11 +0200
committerLaurenz <laurmaedje@gmail.com>2022-05-06 10:05:11 +0200
commitbfaf5447a789cd0dbbb1e418bea62fef9edc2b7d (patch)
tree0cc1a47b37439fbeda06c57ebef0025becae0066 /src/library/text
parent49b8574b8d03e52a990f7d7b009c36fbdad0d55a (diff)
Cast content from string
Diffstat (limited to 'src/library/text')
-rw-r--r--src/library/text/link.rs2
-rw-r--r--src/library/text/mod.rs44
2 files changed, 38 insertions, 8 deletions
diff --git a/src/library/text/link.rs b/src/library/text/link.rs
index 423bcbfb..9e933529 100644
--- a/src/library/text/link.rs
+++ b/src/library/text/link.rs
@@ -22,7 +22,7 @@ impl LinkNode {
fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> {
Ok(Content::show(Self {
url: args.expect::<EcoString>("url")?,
- body: args.find()?,
+ body: args.eat()?,
}))
}
}
diff --git a/src/library/text/mod.rs b/src/library/text/mod.rs
index 09c7fa17..80b036ac 100644
--- a/src/library/text/mod.rs
+++ b/src/library/text/mod.rs
@@ -35,7 +35,7 @@ pub struct TextNode;
#[node]
impl TextNode {
/// A prioritized sequence of font families.
- #[property(referenced, variadic)]
+ #[property(skip, referenced)]
pub const FAMILY: Vec<FontFamily> = vec![FontFamily::new("IBM Plex Sans")];
/// Whether to allow font fallback when the primary font list contains no
/// match.
@@ -109,22 +109,22 @@ impl TextNode {
pub const FEATURES: Vec<(Tag, u32)> = vec![];
/// Whether the font weight should be increased by 300.
- #[property(hidden, fold)]
+ #[property(skip, fold)]
pub const STRONG: Toggle = false;
/// Whether the the font style should be inverted.
- #[property(hidden, fold)]
+ #[property(skip, fold)]
pub const EMPH: Toggle = false;
/// A case transformation that should be applied to the text.
- #[property(hidden)]
+ #[property(skip)]
pub const CASE: Option<Case> = None;
/// Whether small capital glyphs should be used. ("smcp")
- #[property(hidden)]
+ #[property(skip)]
pub const SMALLCAPS: bool = false;
/// An URL the text should link to.
- #[property(hidden, referenced)]
+ #[property(skip, referenced)]
pub const LINK: Option<EcoString> = None;
/// Decorative lines.
- #[property(hidden, fold)]
+ #[property(skip, fold)]
pub const DECO: Decoration = vec![];
fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> {
@@ -133,6 +133,36 @@ impl TextNode {
// styles all text in it.
args.expect("body")
}
+
+ fn set(...) {
+ if let Some(family) = args.named("family")? {
+ styles.set(Self::FAMILY, family);
+ } else {
+ let mut count = 0;
+ let mut content = false;
+ for item in args.items.iter().filter(|item| item.name.is_none()) {
+ if EcoString::is(&item.value) {
+ count += 1;
+ } else if Content::is(&item.value) {
+ content = true;
+ }
+ }
+
+ // Skip the final string if it's needed as the body.
+ if constructor && !content && count > 0 {
+ count -= 1;
+ }
+
+ if count > 0 {
+ let mut list = Vec::with_capacity(count);
+ for _ in 0 .. count {
+ list.push(args.find()?.unwrap());
+ }
+
+ styles.set(Self::FAMILY, list);
+ }
+ }
+ }
}
/// A font family like "Arial".