summaryrefslogtreecommitdiff
path: root/library/src/text
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-03-10 12:55:21 +0100
committerLaurenz <laurmaedje@gmail.com>2023-03-10 12:55:21 +0100
commit62f35602a87574dcc607f1637aeae1be574981ff (patch)
tree363a1918006e06d7d79dc2ace5f8e59cd3b6bb19 /library/src/text
parentc38d72383d2068361d635d6c1c78ba97aa917801 (diff)
New #[func] macro
Diffstat (limited to 'library/src/text')
-rw-r--r--library/src/text/deco.rs3
-rw-r--r--library/src/text/misc.rs60
-rw-r--r--library/src/text/mod.rs10
-rw-r--r--library/src/text/raw.rs1
-rw-r--r--library/src/text/shift.rs2
5 files changed, 32 insertions, 44 deletions
diff --git a/library/src/text/deco.rs b/library/src/text/deco.rs
index 2a552226..4dadf45a 100644
--- a/library/src/text/deco.rs
+++ b/library/src/text/deco.rs
@@ -61,7 +61,6 @@ pub struct UnderlineNode {
pub evade: bool,
/// The content to underline.
- #[positional]
#[required]
pub body: Content,
}
@@ -141,7 +140,6 @@ pub struct OverlineNode {
pub evade: bool,
/// The content to add a line over.
- #[positional]
#[required]
pub body: Content,
}
@@ -206,7 +204,6 @@ pub struct StrikeNode {
pub extent: Length,
/// The content to strike through.
- #[positional]
#[required]
pub body: Content,
}
diff --git a/library/src/text/misc.rs b/library/src/text/misc.rs
index 64ab5bd2..60521f12 100644
--- a/library/src/text/misc.rs
+++ b/library/src/text/misc.rs
@@ -94,7 +94,6 @@ pub struct StrongNode {
pub delta: i64,
/// The content to strongly emphasize.
- #[positional]
#[required]
pub body: Content,
}
@@ -155,7 +154,6 @@ impl Fold for Delta {
#[node(Show)]
pub struct EmphNode {
/// The content to emphasize.
- #[positional]
#[required]
pub body: Content,
}
@@ -196,15 +194,15 @@ impl Fold for Toggle {
/// #lower[already low]
/// ```
///
-/// ## Parameters
-/// - text: `ToCase` (positional, required)
-/// The text to convert to lowercase.
-///
/// Display: Lowercase
/// Category: text
+/// Returns: string or content
#[func]
-pub fn lower(args: &mut Args) -> SourceResult<Value> {
- case(Case::Lower, args)
+pub fn lower(
+ /// The text to convert to lowercase.
+ text: ToCase,
+) -> Value {
+ case(text, Case::Lower)
}
/// Convert text or content to uppercase.
@@ -216,23 +214,23 @@ pub fn lower(args: &mut Args) -> SourceResult<Value> {
/// #upper[ALREADY HIGH]
/// ```
///
-/// ## Parameters
-/// - text: `ToCase` (positional, required)
-/// The text to convert to uppercase.
-///
/// Display: Uppercase
/// Category: text
+/// Returns: string or content
#[func]
-pub fn upper(args: &mut Args) -> SourceResult<Value> {
- case(Case::Upper, args)
+pub fn upper(
+ /// The text to convert to uppercase.
+ text: ToCase,
+) -> Value {
+ case(text, Case::Upper)
}
/// Change the case of text.
-fn case(case: Case, args: &mut Args) -> SourceResult<Value> {
- Ok(match args.expect("string or content")? {
+fn case(text: ToCase, case: Case) -> Value {
+ match text {
ToCase::Str(v) => Value::Str(case.apply(&v).into()),
ToCase::Content(v) => Value::Content(v.styled(TextNode::set_case(Some(case)))),
- })
+ }
}
/// A value whose case can be changed.
@@ -302,16 +300,15 @@ cast_to_value! {
/// #lorem(40)
/// ```
///
-/// ## Parameters
-/// - text: `Content` (positional, required)
-/// The text to display to small capitals.
-///
/// Display: Small Capitals
/// Category: text
+/// Returns: content
#[func]
-pub fn smallcaps(args: &mut Args) -> SourceResult<Value> {
- let body: Content = args.expect("content")?;
- Ok(Value::Content(body.styled(TextNode::set_smallcaps(true))))
+pub fn smallcaps(
+ /// The text to display to small capitals.
+ body: Content,
+) -> Value {
+ Value::Content(body.styled(TextNode::set_smallcaps(true)))
}
/// Create blind text.
@@ -330,16 +327,13 @@ pub fn smallcaps(args: &mut Args) -> SourceResult<Value> {
/// #lorem(15)
/// ```
///
-/// ## Parameters
-/// - words: `usize` (positional, required)
-/// The length of the blind text in words.
-///
-/// - returns: string
-///
/// Display: Blind Text
/// Category: text
+/// Returns: string
#[func]
-pub fn lorem(args: &mut Args) -> SourceResult<Value> {
- let words: usize = args.expect("number of words")?;
- Ok(Value::Str(lipsum::lipsum(words).replace("--", "–").into()))
+pub fn lorem(
+ /// The length of the blind text in words.
+ words: usize,
+) -> Value {
+ Value::Str(lipsum::lipsum(words).replace("--", "–").into())
}
diff --git a/library/src/text/mod.rs b/library/src/text/mod.rs
index 83f4e2d7..a81ef3d7 100644
--- a/library/src/text/mod.rs
+++ b/library/src/text/mod.rs
@@ -38,10 +38,6 @@ use crate::prelude::*;
/// ])
/// ```
///
-/// ## Parameters
-/// - body: `Content` (positional, required)
-/// Content in which all text is styled according to the other arguments.
-///
/// Display: Text
/// Category: text
#[node(Construct)]
@@ -447,9 +443,13 @@ pub struct TextNode {
#[fold]
pub features: FontFeatures,
+ /// Content in which all text is styled according to the other arguments.
+ #[external]
+ #[required]
+ pub body: Content,
+
/// The text.
#[internal]
- #[positional]
#[required]
pub text: EcoString,
diff --git a/library/src/text/raw.rs b/library/src/text/raw.rs
index 36a0fc78..3768e65e 100644
--- a/library/src/text/raw.rs
+++ b/library/src/text/raw.rs
@@ -57,7 +57,6 @@ pub struct RawNode {
/// 1 + 2 + 3 + 4 + 5
/// ```
/// ````
- #[positional]
#[required]
pub text: EcoString,
diff --git a/library/src/text/shift.rs b/library/src/text/shift.rs
index ccdb0197..acd46d4e 100644
--- a/library/src/text/shift.rs
+++ b/library/src/text/shift.rs
@@ -42,7 +42,6 @@ pub struct SubNode {
pub size: TextSize,
/// The text to display in subscript.
- #[positional]
#[required]
pub body: Content,
}
@@ -110,7 +109,6 @@ pub struct SuperNode {
pub size: TextSize,
/// The text to display in superscript.
- #[positional]
#[required]
pub body: Content,
}