diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-12-17 16:24:29 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-12-17 16:24:29 +0100 |
| commit | 35b16e545b4fce299edbc00c9a9754179fa51634 (patch) | |
| tree | eb1081e55187e59ff6482abc1ac2f1932606ef59 /library/src | |
| parent | b6202b646a0d5ecced301d9bac8bfcaf977d7ee4 (diff) | |
Document parameters in comment
Diffstat (limited to 'library/src')
39 files changed, 790 insertions, 182 deletions
diff --git a/library/src/basics/heading.rs b/library/src/basics/heading.rs index 60415697..2781034e 100644 --- a/library/src/basics/heading.rs +++ b/library/src/basics/heading.rs @@ -7,7 +7,14 @@ use crate::text::{SpaceNode, TextNode, TextSize}; /// A section heading. /// -/// Tags: basics. +/// # Parameters +/// - body: Content (positional, required) +/// The heading's contents. +/// - level: NonZeroUsize (named) +/// The logical nesting depth of the heading, starting from one. +/// +/// # Tags +/// - basics #[func] #[capable(Prepare, Show, Finalize)] #[derive(Debug, Hash)] diff --git a/library/src/basics/list.rs b/library/src/basics/list.rs index 4c016128..c9215a50 100644 --- a/library/src/basics/list.rs +++ b/library/src/basics/list.rs @@ -5,7 +5,17 @@ use crate::text::{SpaceNode, TextNode}; /// An unordered (bulleted) or ordered (numbered) list. /// -/// Tags: basics. +/// # Parameters +/// - items: Content (positional, variadic) +/// The contents of the list items. +/// - start: NonZeroUsize (named) +/// Which number to start the enumeration with. +/// - tight: bool (named) +/// Makes the list more compact, if enabled. This looks better if the items +/// fit into a single line each. +/// +/// # Tags +/// - basics #[func] #[capable(Layout)] #[derive(Debug, Hash)] diff --git a/library/src/basics/table.rs b/library/src/basics/table.rs index 10a9143f..d7e2e08f 100644 --- a/library/src/basics/table.rs +++ b/library/src/basics/table.rs @@ -3,7 +3,22 @@ use crate::prelude::*; /// A table of items. /// -/// Tags: basics. +/// # Parameters +/// - cells: Content (positional, variadic) +/// The contents of the table cells. +/// - rows: TrackSizings (named) +/// Defines the row sizes. +/// - columns: TrackSizings (named) +/// Defines the column sizes. +/// - gutter: TrackSizings (named) +/// Defines the gaps between rows & columns. +/// - column-gutter: TrackSizings (named) +/// Defines the gaps between columns. Takes precedence over `gutter`. +/// - row-gutter: TrackSizings (named) +/// Defines the gaps between rows. Takes precedence over `gutter`. +/// +/// # Tags +/// - basics #[func] #[capable(Layout)] #[derive(Debug, Hash)] diff --git a/library/src/compute/calc.rs b/library/src/compute/calc.rs index 62d0a419..eccc4531 100644 --- a/library/src/compute/calc.rs +++ b/library/src/compute/calc.rs @@ -4,26 +4,37 @@ use crate::prelude::*; /// The absolute value of a numeric value. /// -/// Tags: calculate. +/// # Parameters +/// - value: ToAbs (positional, required) +/// The value whose absolute value to calculate. +/// +/// # Tags +/// - calculate #[func] pub fn abs(args: &mut Args) -> SourceResult<Value> { - let Spanned { v, span } = args.expect("numeric value")?; - Ok(match v { - Value::Int(v) => Value::Int(v.abs()), - Value::Float(v) => Value::Float(v.abs()), - Value::Angle(v) => Value::Angle(v.abs()), - Value::Ratio(v) => Value::Ratio(v.abs()), - Value::Fraction(v) => Value::Fraction(v.abs()), - Value::Length(_) | Value::Relative(_) => { - bail!(span, "cannot take absolute value of a length") - } - v => bail!(span, "expected numeric value, found {}", v.type_name()), - }) + Ok(args.expect::<ToAbs>("value")?.0) +} + +/// A value of which the absolute value can be taken. +struct ToAbs(Value); + +castable! { + ToAbs, + v: i64 => Self(Value::Int(v.abs())), + v: f64 => Self(Value::Float(v.abs())), + v: Angle => Self(Value::Angle(v.abs())), + v: Ratio => Self(Value::Ratio(v.abs())), + v: Fr => Self(Value::Fraction(v.abs())), } /// The minimum of a sequence of values. /// -/// Tags: calculate. +/// # Parameters +/// - values: Value (positional, variadic) +/// The sequence of values. +/// +/// # Tags +/// - calculate #[func] pub fn min(args: &mut Args) -> SourceResult<Value> { minmax(args, Ordering::Less) @@ -31,7 +42,12 @@ pub fn min(args: &mut Args) -> SourceResult<Value> { /// The maximum of a sequence of values. /// -/// Tags: calculate. +/// # Parameters +/// - values: Value (positional, variadic) +/// The sequence of values. +/// +/// # Tags +/// - calculate #[func] pub fn max(args: &mut Args) -> SourceResult<Value> { minmax(args, Ordering::Greater) @@ -60,27 +76,44 @@ fn minmax(args: &mut Args, goal: Ordering) -> SourceResult<Value> { /// Whether an integer is even. /// -/// Tags: calculate. +/// # Parameters +/// - value: i64 (positional, required) +/// The number to check for evenness. +/// +/// # Tags +/// - calculate #[func] pub fn even(args: &mut Args) -> SourceResult<Value> { - Ok(Value::Bool(args.expect::<i64>("integer")? % 2 == 0)) + Ok(Value::Bool(args.expect::<i64>("value")? % 2 == 0)) } /// Whether an integer is odd. /// -/// Tags: calculate. +/// # Parameters +/// - value: i64 (positional, required) +/// The number to check for oddness. +/// +/// # Tags +/// - calculate #[func] pub fn odd(args: &mut Args) -> SourceResult<Value> { - Ok(Value::Bool(args.expect::<i64>("integer")? % 2 != 0)) + Ok(Value::Bool(args.expect::<i64>("value")? % 2 != 0)) } -/// The modulo of two numbers. +/// The modulus of two numbers. +/// +/// # Parameters +/// - dividend: ToMod (positional, required) +/// The dividend of the modulus. +/// - divisor: ToMod (positional, required) +/// The divisor of the modulus. /// -/// Tags: calculate. +/// # Tags +/// - calculate #[func] pub fn mod_(args: &mut Args) -> SourceResult<Value> { - let Spanned { v: v1, span: span1 } = args.expect("integer or float")?; - let Spanned { v: v2, span: span2 } = args.expect("integer or float")?; + let Spanned { v: v1, span: span1 } = args.expect("dividend")?; + let Spanned { v: v2, span: span2 } = args.expect("divisor")?; let (a, b) = match (v1, v2) { (Value::Int(a), Value::Int(b)) => match a.checked_rem(b) { @@ -104,3 +137,12 @@ pub fn mod_(args: &mut Args) -> SourceResult<Value> { Ok(Value::Float(a % b)) } + +/// A value which can be passed to the `mod` function. +struct ToMod; + +castable! { + ToMod, + _: i64 => Self, + _: f64 => Self, +} diff --git a/library/src/compute/create.rs b/library/src/compute/create.rs index a0eecfb8..e3733d60 100644 --- a/library/src/compute/create.rs +++ b/library/src/compute/create.rs @@ -6,42 +6,60 @@ use crate::prelude::*; /// Convert a value to an integer. /// -/// Tags: create. +/// # Parameters +/// - value: ToInt (positional, required) +/// The value that should be converted to an integer. +/// +/// # Tags +/// - create #[func] pub fn int(args: &mut Args) -> SourceResult<Value> { - let Spanned { v, span } = args.expect("value")?; - Ok(Value::Int(match v { - Value::Bool(v) => v as i64, - Value::Int(v) => v, - Value::Float(v) => v as i64, - Value::Str(v) => match v.parse() { - Ok(v) => v, - Err(_) => bail!(span, "invalid integer"), - }, - v => bail!(span, "cannot convert {} to integer", v.type_name()), - })) + Ok(Value::Int(args.expect::<ToInt>("value")?.0)) +} + +/// A value that can be cast to an integer. +struct ToInt(i64); + +castable! { + ToInt, + v: bool => Self(v as i64), + v: i64 => Self(v), + v: f64 => Self(v as i64), + v: EcoString => Self(v.parse().map_err(|_| "not a valid integer")?), } /// Convert a value to a float. /// -/// Tags: create. +/// # Parameters +/// - value: ToFloat (positional, required) +/// The value that should be converted to a float. +/// +/// # Tags +/// - create #[func] pub fn float(args: &mut Args) -> SourceResult<Value> { - let Spanned { v, span } = args.expect("value")?; - Ok(Value::Float(match v { - Value::Int(v) => v as f64, - Value::Float(v) => v, - Value::Str(v) => match v.parse() { - Ok(v) => v, - Err(_) => bail!(span, "invalid float"), - }, - v => bail!(span, "cannot convert {} to float", v.type_name()), - })) + Ok(Value::Float(args.expect::<ToFloat>("value")?.0)) +} + +/// A value that can be cast to a float. +struct ToFloat(f64); + +castable! { + ToFloat, + v: bool => Self(v as i64 as f64), + v: i64 => Self(v as f64), + v: f64 => Self(v), + v: EcoString => Self(v.parse().map_err(|_| "not a valid float")?), } /// Create a grayscale color. /// -/// Tags: create. +/// # Parameters +/// - gray: Component (positional, required) +/// The gray component. +/// +/// # Tags +/// - create #[func] pub fn luma(args: &mut Args) -> SourceResult<Value> { let Component(luma) = args.expect("gray component")?; @@ -50,7 +68,26 @@ pub fn luma(args: &mut Args) -> SourceResult<Value> { /// Create an RGB(A) color. /// -/// Tags: create. +/// # Parameters +/// - hex: EcoString (positional) +/// The color in hexademical notation. +/// +/// Accepts three, four, six or eight hexadecimal digits and optionally +/// a leading hashtag. +/// +/// If this string is given, the individual components should not be given. +/// +/// - red: Component (positional) +/// The red component. +/// - green: Component (positional) +/// The green component. +/// - blue: Component (positional) +/// The blue component. +/// - alpha: Component (positional) +/// The alpha component. +/// +/// # Tags +/// - create #[func] pub fn rgb(args: &mut Args) -> SourceResult<Value> { Ok(Value::Color(if let Some(string) = args.find::<Spanned<EcoString>>()? { @@ -67,18 +104,6 @@ pub fn rgb(args: &mut Args) -> SourceResult<Value> { })) } -/// Create a CMYK color. -/// -/// Tags: create. -#[func] -pub fn cmyk(args: &mut Args) -> SourceResult<Value> { - let RatioComponent(c) = args.expect("cyan component")?; - let RatioComponent(m) = args.expect("magenta component")?; - let RatioComponent(y) = args.expect("yellow component")?; - let RatioComponent(k) = args.expect("key component")?; - Ok(Value::Color(CmykColor::new(c, m, y, k).into())) -} - /// An integer or ratio component. struct Component(u8); @@ -95,6 +120,29 @@ castable! { }, } +/// Create a CMYK color. +/// +/// # Parameters +/// - cyan: RatioComponent (positional, required) +/// The cyan component. +/// - magenta: RatioComponent (positional, required) +/// The magenta component. +/// - yellow: RatioComponent (positional, required) +/// The yellow component. +/// - key: RatioComponent (positional, required) +/// The key component. +/// +/// # Tags +/// - create +#[func] +pub fn cmyk(args: &mut Args) -> SourceResult<Value> { + let RatioComponent(c) = args.expect("cyan component")?; + let RatioComponent(m) = args.expect("magenta component")?; + let RatioComponent(y) = args.expect("yellow component")?; + let RatioComponent(k) = args.expect("key component")?; + Ok(Value::Color(CmykColor::new(c, m, y, k).into())) +} + /// A component that must be a ratio. struct RatioComponent(u8); @@ -109,22 +157,36 @@ castable! { /// Convert a value to a string. /// -/// Tags: create. +/// # Parameters +/// - value: ToStr (positional, required) +/// The value that should be converted to a string. +/// +/// # Tags +/// - create #[func] pub fn str(args: &mut Args) -> SourceResult<Value> { - let Spanned { v, span } = args.expect("value")?; - Ok(Value::Str(match v { - Value::Int(v) => format_str!("{}", v), - Value::Float(v) => format_str!("{}", v), - Value::Label(label) => label.0.into(), - Value::Str(v) => v, - v => bail!(span, "cannot convert {} to string", v.type_name()), - })) + Ok(Value::Str(args.expect::<ToStr>("value")?.0)) +} + +/// A value that can be cast to a string. +struct ToStr(Str); + +castable! { + ToStr, + v: i64 => Self(format_str!("{}", v)), + v: f64 => Self(format_str!("{}", v)), + v: Label => Self(v.0.into()), + v: Str => Self(v), } /// Create a label from a string. /// -/// Tags: create. +/// # Parameters +/// - name: EcoString (positional, required) +/// The name of the label. +/// +/// # Tags +/// - create #[func] pub fn label(args: &mut Args) -> SourceResult<Value> { Ok(Value::Label(Label(args.expect("string")?))) @@ -132,7 +194,12 @@ pub fn label(args: &mut Args) -> SourceResult<Value> { /// Create a regular expression from a string. /// -/// Tags: create. +/// # Parameters +/// - regex: EcoString (positional, required) +/// The regular expression. +/// +/// # Tags +/// - create #[func] pub fn regex(args: &mut Args) -> SourceResult<Value> { let Spanned { v, span } = args.expect::<Spanned<EcoString>>("regular expression")?; @@ -141,7 +208,18 @@ pub fn regex(args: &mut Args) -> SourceResult<Value> { /// Create an array consisting of a sequence of numbers. /// -/// Tags: create. +/// # Parameters +/// - start: i64 (positional) +/// The start of the range (inclusive). +/// +/// - end: i64 (positional, required) +/// The end of the range (exclusive). +/// +/// - step: i64 (named) +/// The distance between the generated numbers. +/// +/// # Tags +/// - create #[func] pub fn range(args: &mut Args) -> SourceResult<Value> { let first = args.expect::<i64>("end")?; diff --git a/library/src/compute/data.rs b/library/src/compute/data.rs index af545304..5de3eb61 100644 --- a/library/src/compute/data.rs +++ b/library/src/compute/data.rs @@ -6,7 +6,12 @@ use crate::prelude::*; /// Read structured data from a CSV file. /// -/// Tags: data-loading. +/// # Parameters +/// - path: EcoString (positional, required) +/// Path to a CSV file. +/// +/// # Tags +/// - data-loading #[func] pub fn csv(vm: &Vm, args: &mut Args) -> SourceResult<Value> { let Spanned { v: path, span } = @@ -49,7 +54,12 @@ fn format_csv_error(error: csv::Error) -> String { /// Read structured data from a JSON file. /// -/// Tags: data-loading. +/// # Parameters +/// - path: EcoString (positional, required) +/// Path to a JSON file. +/// +/// # Tags +/// - data-loading #[func] pub fn json(vm: &Vm, args: &mut Args) -> SourceResult<Value> { let Spanned { v: path, span } = @@ -92,7 +102,12 @@ fn format_json_error(error: serde_json::Error) -> String { /// Read structured data from an XML file. /// -/// Tags: data-loading. +/// # Parameters +/// - path: EcoString (positional, required) +/// Path to an XML file. +/// +/// # Tags +/// - data-loading #[func] pub fn xml(vm: &Vm, args: &mut Args) -> SourceResult<Value> { let Spanned { v: path, span } = diff --git a/library/src/compute/foundations.rs b/library/src/compute/foundations.rs index 22d26553..cb952d81 100644 --- a/library/src/compute/foundations.rs +++ b/library/src/compute/foundations.rs @@ -6,7 +6,12 @@ use typst::syntax::Source; /// The name of a value's type. /// -/// Tags: foundations. +/// # Parameters +/// - value: Value (positional, required) +/// The value whose type's to determine. +/// +/// # Tags +/// - foundations #[func] pub fn type_(args: &mut Args) -> SourceResult<Value> { Ok(args.expect::<Value>("value")?.type_name().into()) @@ -14,7 +19,12 @@ pub fn type_(args: &mut Args) -> SourceResult<Value> { /// The string representation of a value. /// -/// Tags: foundations. +/// # Parameters +/// - value: Value (positional, required) +/// The value whose string representation to produce. +/// +/// # Tags +/// - foundations #[func] pub fn repr(args: &mut Args) -> SourceResult<Value> { Ok(args.expect::<Value>("value")?.repr().into()) @@ -22,7 +32,12 @@ pub fn repr(args: &mut Args) -> SourceResult<Value> { /// Ensure that a condition is fulfilled. /// -/// Tags: foundations. +/// # Parameters +/// - condition: bool (positional, required) +/// The condition that must be true for the assertion to pass. +/// +/// # Tags +/// - foundations #[func] pub fn assert(args: &mut Args) -> SourceResult<Value> { let Spanned { v, span } = args.expect::<Spanned<bool>>("condition")?; @@ -34,7 +49,12 @@ pub fn assert(args: &mut Args) -> SourceResult<Value> { /// Evaluate a string as Typst markup. /// -/// Tags: foundations. +/// # Parameters +/// - source: String (positional, required) +/// A string of Typst markup to evaluate. +/// +/// # Tags +/// - foundations #[func] pub fn eval(vm: &Vm, args: &mut Args) -> SourceResult<Value> { let Spanned { v: text, span } = args.expect::<Spanned<String>>("source")?; diff --git a/library/src/compute/utility.rs b/library/src/compute/utility.rs index 5a6534f4..bdad9618 100644 --- a/library/src/compute/utility.rs +++ b/library/src/compute/utility.rs @@ -3,18 +3,30 @@ use std::str::FromStr; use crate::prelude::*; use crate::text::Case; -/// Create a blind text string. +/// Create blind text. /// -/// Tags: utility. +/// # Parameters +/// - words: usize (positional, required) +/// The length of the blind text in words. +/// +/// # Tags +/// - utility #[func] pub fn lorem(args: &mut Args) -> SourceResult<Value> { let words: usize = args.expect("number of words")?; Ok(Value::Str(lipsum::lipsum(words).into())) } -/// Apply a numbering pattern to a number. +/// Apply a numbering pattern to a sequence of numbers. +/// +/// # Parameters +/// - pattern: NumberingPattern (positional, required) +/// A string that defines how the numbering works. +/// - numbers: NonZeroUsize (positional, variadic) +/// The numbers to apply the pattern to. /// -/// Tags: utility. +/// # Tags +/// - utility #[func] pub fn numbering(args: &mut Args) -> SourceResult<Value> { let pattern = args.expect::<NumberingPattern>("pattern")?; diff --git a/library/src/layout/align.rs b/library/src/layout/align.rs index f00aeaf2..7853d84d 100644 --- a/library/src/layout/align.rs +++ b/library/src/layout/align.rs @@ -2,7 +2,14 @@ use crate::prelude::*; /// Align content horizontally and vertically. /// -/// Tags: layout. +/// # Parameters +/// - body: Content (positional, required) +/// The content to align. +/// - alignment: Axes<Option<GenAlign>> (positional, settable) +/// The alignment along both axes. +/// +/// # Tags +/// - layout #[func] #[capable] #[derive(Debug, Hash)] diff --git a/library/src/layout/columns.rs b/library/src/layout/columns.rs index 3bbf56e4..b31b0a6d 100644 --- a/library/src/layout/columns.rs +++ b/library/src/layout/columns.rs @@ -3,13 +3,20 @@ use crate::text::TextNode; /// Separate a region into multiple equally sized columns. /// -/// Tags: layout. +/// # Parameters +/// - count: usize (positional, required) +/// The number of columns. +/// - body: Content (positional, required) +/// The content that should be layouted into the columns. +/// +/// # Tags +/// - layout #[func] #[capable(Layout)] #[derive(Debug, Hash)] pub struct ColumnsNode { /// How many columns there should be. - pub columns: NonZeroUsize, + pub count: NonZeroUsize, /// The child to be layouted into the columns. Most likely, this should be a /// flow or stack node. pub body: Content, @@ -23,7 +30,7 @@ impl ColumnsNode { fn construct(_: &Vm, args: &mut Args) -> SourceResult<Content> { Ok(Self { - columns: args.expect("column count")?, + count: args.expect("column count")?, body: args.expect("body")?, } .pack()) @@ -44,7 +51,7 @@ impl Layout for ColumnsNode { } // Determine the width of the gutter and each column. - let columns = self.columns.get(); + let columns = self.count.get(); let gutter = styles.get(Self::GUTTER).relative_to(regions.base.x); let width = (regions.first.x - gutter * (columns - 1) as f64) / columns as f64; @@ -106,7 +113,13 @@ impl Layout for ColumnsNode { /// A column break. /// -/// Tags: layout. +/// # Parameters +/// - weak: bool (named) +/// If true, the column break is skipped if the current column is already +/// empty. +/// +/// # Tags +/// - layout #[func] #[capable(Behave)] #[derive(Debug, Hash)] diff --git a/library/src/layout/container.rs b/library/src/layout/container.rs index d451bccf..4b58434b 100644 --- a/library/src/layout/container.rs +++ b/library/src/layout/container.rs @@ -1,9 +1,19 @@ use super::VNode; +use crate::layout::Spacing; use crate::prelude::*; /// An inline-level container that sizes content. /// -/// Tags: layout. +/// # Parameters +/// - body: Content (positional) +/// The contents of the box. +/// - width: Rel<Length> (named) +/// The width of the box. +/// - height: Rel<Length> (named) +/// The height of the box. +/// +/// # Tags +/// - layout #[func] #[capable(Layout, Inline)] #[derive(Debug, Hash)] @@ -65,7 +75,20 @@ impl Inline for BoxNode {} /// A block-level container that places content into a separate flow. /// -/// Tags: layout. +/// # Parameters +/// - body: Content (positional) +/// The contents of the block. +/// - spacing: Spacing (named, settable) +/// The spacing around this block. +/// - above: Spacing (named, settable) +/// The spacing between the previous and this block. Takes precedence over +/// `spacing`. +/// - below: Spacing (named, settable) +/// The spacing between this block and the following one. Takes precedence +/// over `spacing`. +/// +/// # Tags +/// - layout #[func] #[capable(Layout)] #[derive(Debug, Hash)] @@ -74,10 +97,10 @@ pub struct BlockNode(pub Content); #[node] impl BlockNode { /// The spacing between the previous and this block. - #[property(reflect, skip)] + #[property(skip)] pub const ABOVE: VNode = VNode::block_spacing(Em::new(1.2).into()); /// The spacing between this and the following block. - #[property(reflect, skip)] + #[property(skip)] pub const BELOW: VNode = VNode::block_spacing(Em::new(1.2).into()); /// Whether this block must stick to the following one. #[property(skip)] diff --git a/library/src/layout/grid.rs b/library/src/layout/grid.rs index e70210c0..8aaffe08 100644 --- a/library/src/layout/grid.rs +++ b/library/src/layout/grid.rs @@ -4,7 +4,22 @@ use super::Spacing; /// Arrange content in a grid. /// -/// Tags: layout. +/// # Parameters +/// - cells: Content (positional, variadic) +/// The contents of the table cells. +/// - rows: TrackSizings (named) +/// Defines the row sizes. +/// - columns: TrackSizings (named) +/// Defines the column sizes. +/// - gutter: TrackSizings (named) +/// Defines the gaps between rows & columns. +/// - column-gutter: TrackSizings (named) +/// Defines the gaps between columns. Takes precedence over `gutter`. +/// - row-gutter: TrackSizings (named) +/// Defines the gaps between rows. Takes precedence over `gutter`. +/// +/// # Tags +/// - layout #[func] #[capable(Layout)] #[derive(Debug, Hash)] diff --git a/library/src/layout/hide.rs b/library/src/layout/hide.rs index 4e70dca9..fc9150c1 100644 --- a/library/src/layout/hide.rs +++ b/library/src/layout/hide.rs @@ -2,7 +2,12 @@ use crate::prelude::*; /// Hide content without affecting layout. /// -/// Tags: layout. +/// # Parameters +/// - body: Content (positional, required) +/// The content to hide. +/// +/// # Tags +/// - layout #[func] #[capable(Layout, Inline)] #[derive(Debug, Hash)] diff --git a/library/src/layout/pad.rs b/library/src/layout/pad.rs index 9d882ba4..94492f83 100644 --- a/library/src/layout/pad.rs +++ b/library/src/layout/pad.rs @@ -2,7 +2,26 @@ use crate::prelude::*; /// Pad content at the sides. /// -/// Tags: layout. +/// # Parameters +/// - body: Content (positional, required) +/// The content to pad at the sides. +/// - left: Rel<Length> (named) +/// The padding at the left side. +/// - right: Rel<Length> (named) +/// The padding at the right side. +/// - top: Rel<Length> (named) +/// The padding at the top side. +/// - bottom: Rel<Length> (named) +/// The padding at the bottom side. +/// - x: Rel<Length> (named) +/// The horizontal padding. Both `left` and `right` take precedence over this. +/// - y: Rel<Length> (named) +/// The vertical padding. Both `top` and `bottom` take precedence over this. +/// - rest: Rel<Length> (named) +/// The padding for all sides. All other parameters take precedence over this. +/// +/// # Tags +/// - layout #[func] #[capable(Layout)] #[derive(Debug, Hash)] diff --git a/library/src/layout/page.rs b/library/src/layout/page.rs index fe83137e..8782ed08 100644 --- a/library/src/layout/page.rs +++ b/library/src/layout/page.rs @@ -6,7 +6,14 @@ use crate::text::TextNode; /// Layouts its child onto one or multiple pages. /// -/// Tags: layout. +/// # Parameters +/// - body: Content (positional, required) +/// The contents of the page(s). +/// - paper: Paper (positional, settable) +/// The paper size. +/// +/// # Tags +/// - layout #[func] #[capable] #[derive(Clone, Hash)] @@ -14,9 +21,6 @@ pub struct PageNode(pub Content); #[node] impl PageNode { - /// The paper size. - #[property(reflect, skip, shorthand)] - pub const PAPER: Paper = Paper::A4; /// The unflipped width of the page. #[property(resolve)] pub const WIDTH: Smart<Length> = Smart::Custom(Paper::A4.width().into()); @@ -91,7 +95,7 @@ impl PageNode { // Realize columns. let columns = styles.get(Self::COLUMNS); if columns.get() > 1 { - child = ColumnsNode { columns, body: self.0.clone() }.pack(); + child = ColumnsNode { count: columns, body: self.0.clone() }.pack(); } // Realize margins. @@ -151,7 +155,12 @@ impl Debug for PageNode { /// A page break. /// -/// Tags: layout. +/// # Parameters +/// - weak: bool (named) +/// If true, the page break is skipped if the current page is already empty. +/// +/// # Tags +/// - layout #[func] #[capable] #[derive(Debug, Copy, Clone, Hash)] @@ -266,7 +275,10 @@ macro_rules! papers { castable! { Paper, - $($pat => Self::$var,)* + $( + /// Produces a paper of the respective size. + $pat => Self::$var, + )* } }; } diff --git a/library/src/layout/par.rs b/library/src/layout/par.rs index eed0dbb1..f9731ff2 100644 --- a/library/src/layout/par.rs +++ b/library/src/layout/par.rs @@ -13,7 +13,12 @@ use crate::text::{ /// Arrange text, spacing and inline-level nodes into a paragraph. /// -/// Tags: layout. +/// # Parameters +/// - body: Content (positional, required) +/// The contents of the paragraph. +/// +/// # Tags +/// - layout #[func] #[capable] #[derive(Hash)] @@ -144,7 +149,8 @@ castable! { /// A paragraph break. /// -/// Tags: layout. +/// # Tags +/// - layout #[func] #[capable(Unlabellable)] #[derive(Debug, Hash)] diff --git a/library/src/layout/place.rs b/library/src/layout/place.rs index c3fcd0d5..890480a7 100644 --- a/library/src/layout/place.rs +++ b/library/src/layout/place.rs @@ -2,7 +2,18 @@ use crate::prelude::*; /// Place content at an absolute position. /// -/// Tags: layout. +/// # Parameters +/// - alignment: Axes<Option<GenAlign>> (positional) +/// Relative to which position in the parent container to place the content. +/// - body: Content (positional, required) +/// The content to place. +/// - dx: Rel<Length> (named) +/// The horizontal displacement of the placed content. +/// - dy: Rel<Length> (named) +/// The vertical displacement of the placed content. +/// +/// # Tags +/// - layout #[func] #[capable(Layout, Behave)] #[derive(Debug, Hash)] diff --git a/library/src/layout/repeat.rs b/library/src/layout/repeat.rs index a47dbb3e..fa87d922 100644 --- a/library/src/layout/repeat.rs +++ b/library/src/layout/repeat.rs @@ -2,7 +2,12 @@ use crate::prelude::*; /// Repeats content to fill a line. /// -/// Tags: layout. +/// # Parameters +/// - body: Content (positional, required) +/// The content to repeat. +/// +/// # Tags +/// - layout #[func] #[capable(Layout, Inline)] #[derive(Debug, Hash)] diff --git a/library/src/layout/spacing.rs b/library/src/layout/spacing.rs index e961c0cf..ef69c070 100644 --- a/library/src/layout/spacing.rs +++ b/library/src/layout/spacing.rs @@ -2,9 +2,18 @@ use std::cmp::Ordering; use crate::prelude::*; -/// Horizontal spacing. +/// Horizontal spacing in a paragraph. /// -/// Tags: layout. +/// # Parameters +/// - amount: Spacing (positional, required) +/// How much spacing to insert. +/// - weak: bool (named) +/// If true, the spacing collapses at the start or end of a paragraph. +/// Moreover, from multiple adjacent weak spacings all but the largest one +/// collapse. +/// +/// # Tags +/// - layout #[func] #[capable(Behave)] #[derive(Debug, Copy, Clone, Hash)] @@ -55,7 +64,16 @@ impl Behave for HNode { /// Vertical spacing. /// -/// Tags: layout. +/// # Parameters +/// - amount: Spacing (positional, required) +/// How much spacing to insert. +/// - weak: bool (named) +/// If true, the spacing collapses at the start or end of a flow. +/// Moreover, from multiple adjacent weak spacings all but the largest one +/// collapse. +/// +/// # Tags +/// - layout #[func] #[capable(Behave)] #[derive(Debug, Copy, Clone, Hash, PartialEq, PartialOrd)] @@ -123,11 +141,6 @@ impl Behave for VNode { } } -castable! { - VNode, - spacing: Spacing => VNode::block_around(spacing), -} - /// Kinds of spacing. #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] pub enum Spacing { diff --git a/library/src/layout/stack.rs b/library/src/layout/stack.rs index 111e3433..deb565b6 100644 --- a/library/src/layout/stack.rs +++ b/library/src/layout/stack.rs @@ -5,7 +5,16 @@ use crate::prelude::*; /// Arrange content and spacing along an axis. /// -/// Tags: layout. +/// # Parameters +/// - items: StackChild (positional, variadic) +/// The items to stack along an axis. +/// - dir: Dir (named) +/// The direction along which the items are stacked. +/// - spacing: Spacing (named) +/// Spacing to insert between items where no explicit spacing was provided. +/// +/// # Tags +/// - layout #[func] #[capable(Layout)] #[derive(Debug, Hash)] diff --git a/library/src/layout/transform.rs b/library/src/layout/transform.rs index f1a89d4c..3af44ca0 100644 --- a/library/src/layout/transform.rs +++ b/library/src/layout/transform.rs @@ -4,7 +4,16 @@ use crate::prelude::*; /// Move content without affecting layout. /// -/// Tags: layout. +/// # Parameters +/// - body: Content (positional, required) +/// The content to move. +/// - dx: Rel<Length> (named) +/// The horizontal displacement of the content. +/// - dy: Rel<Length> (named) +/// The vertical displacement of the content. +/// +/// # Tags +/// - layout #[func] #[capable(Layout, Inline)] #[derive(Debug, Hash)] @@ -49,7 +58,18 @@ impl Inline for MoveNode {} /// Transform content without affecting layout. /// -/// Tags: layout. +/// # Parameters +/// - body: Content (positional, required) +/// The content to transform. +/// - angle: Angle (named) +/// The amount of rotation. +/// - x: Ratio (named) +/// The horizontal scaling factor. +/// - y: Ratio (named) +/// The vertical scaling factor. +/// +/// # Tags +/// - layout #[func] #[capable(Layout, Inline)] #[derive(Debug, Hash)] diff --git a/library/src/lib.rs b/library/src/lib.rs index 2d03ef7c..7e65ff79 100644 --- a/library/src/lib.rs +++ b/library/src/lib.rs @@ -50,7 +50,6 @@ fn scope() -> Scope { // Math. std.def_func::<math::MathNode>("math"); - std.def_func::<math::AtomNode>("atom"); std.def_func::<math::AccNode>("acc"); std.def_func::<math::FracNode>("frac"); std.def_func::<math::BinomNode>("binom"); @@ -203,7 +202,7 @@ fn items() -> LangItems { desc_item: |term, body| { basics::ListItem::Desc(Box::new(basics::DescItem { term, body })).pack() }, - math: |children, display| math::MathNode { children, display }.pack(), + math: |children, block| math::MathNode { children, block }.pack(), math_atom: |atom| math::AtomNode(atom).pack(), math_script: |base, sub, sup| math::ScriptNode { base, sub, sup }.pack(), math_frac: |num, denom| math::FracNode { num, denom }.pack(), diff --git a/library/src/math/matrix.rs b/library/src/math/matrix.rs index 21294b71..a32750ff 100644 --- a/library/src/math/matrix.rs +++ b/library/src/math/matrix.rs @@ -2,7 +2,12 @@ use super::*; /// A column vector. /// -/// Tags: math. +/// # Parameters +/// - elements: Content (positional, variadic) +/// The elements of the vector. +/// +/// # Tags +/// - math #[func] #[capable(Texify)] #[derive(Debug, Hash)] @@ -66,7 +71,12 @@ castable! { /// A case distinction. /// -/// Tags: math. +/// # Parameters +/// - branches: Content (positional, variadic) +/// The branches of the case distinction. +/// +/// # Tags +/// - math #[func] #[capable(Texify)] #[derive(Debug, Hash)] diff --git a/library/src/math/mod.rs b/library/src/math/mod.rs index 41cdb9f5..3bd7b2e3 100644 --- a/library/src/math/mod.rs +++ b/library/src/math/mod.rs @@ -16,22 +16,35 @@ use crate::text::{FontFamily, LinebreakNode, SpaceNode, SymbolNode, TextNode}; /// A piece of a mathematical formula. /// -/// Tags: math. +/// # Parameters +/// - items: Content (positional, variadic) +/// The individual parts of the formula. +/// - block: bool (named) +/// Whether the formula is displayed as a separate block. +/// +/// # Tags +/// - math #[func] #[capable(Show, Layout, Inline, Texify)] #[derive(Debug, Clone, Hash)] pub struct MathNode { - /// Whether the formula is display-level. - pub display: bool, + /// Whether the formula is displayed as a separate block. + pub block: bool, /// The pieces of the formula. pub children: Vec<Content>, } #[node] impl MathNode { + fn construct(_: &Vm, args: &mut Args) -> SourceResult<Content> { + let block = args.named("block")?.unwrap_or(false); + let children = args.all()?; + Ok(Self { block, children }.pack()) + } + fn field(&self, name: &str) -> Option<Value> { match name { - "display" => Some(Value::Bool(self.display)), + "block" => Some(Value::Bool(self.block)), _ => None, } } @@ -48,7 +61,7 @@ impl Show for MathNode { .guarded(Guard::Base(NodeId::of::<Self>())) .styled_with_map(map); - if self.display { + if self.block { realized = realized.aligned(Axes::with_x(Some(Align::Center.into()))) } @@ -65,7 +78,7 @@ impl Layout for MathNode { ) -> SourceResult<Fragment> { let mut t = Texifier::new(styles); self.texify(&mut t)?; - Ok(layout_tex(vt, &t.finish(), self.display, styles) + Ok(layout_tex(vt, &t.finish(), self.block, styles) .unwrap_or(Fragment::frame(Frame::new(Size::zero())))) } } @@ -247,7 +260,12 @@ impl Texify for Content { /// An atom in a math formula: `x`, `+`, `12`. /// -/// Tags: math. +/// # Parameters +/// - text: EcoString (positional, required) +/// The atom's text. +/// +/// # Tags +/// - math #[func] #[capable(Texify)] #[derive(Debug, Hash)] @@ -288,7 +306,14 @@ impl Texify for AtomNode { /// An accented node. /// -/// Tags: math. +/// # Parameters +/// - base: Content (positional, required) +/// The base to which the accent is applied. +/// - accent: Content (positional, required) +/// The accent to apply to the base. +/// +/// # Tags +/// - math #[func] #[capable(Texify)] #[derive(Debug, Hash)] @@ -365,7 +390,14 @@ impl Texify for AccNode { /// A fraction. /// -/// Tags: math. +/// # Parameters +/// - num: Content (positional, required) +/// The fraction's numerator. +/// - denom: Content (positional, required) +/// The fraction's denominator. +/// +/// # Tags +/// - math #[func] #[capable(Texify)] #[derive(Debug, Hash)] @@ -398,7 +430,14 @@ impl Texify for FracNode { /// A binomial. /// -/// Tags: math. +/// # Parameters +/// - upper: Content (positional, required) +/// The binomial's upper index. +/// - lower: Content (positional, required) +/// The binomial's lower index. +/// +/// # Tags +/// - math #[func] #[capable(Texify)] #[derive(Debug, Hash)] @@ -431,7 +470,16 @@ impl Texify for BinomNode { /// A sub- and/or superscript. /// -/// Tags: math. +/// # Parameters +/// - base: Content (positional, required) +/// The base to which the applies the sub- and/or superscript. +/// - sub: Content (named) +/// The subscript. +/// - sup: Content (named) +/// The superscript. +/// +/// # Tags +/// - math #[func] #[capable(Texify)] #[derive(Debug, Hash)] @@ -445,7 +493,14 @@ pub struct ScriptNode { } #[node] -impl ScriptNode {} +impl ScriptNode { + fn construct(_: &Vm, args: &mut Args) -> SourceResult<Content> { + let base = args.expect("base")?; + let sub = args.named("sub")?; + let sup = args.named("sup")?; + Ok(Self { base, sub, sup }.pack()) + } +} impl Texify for ScriptNode { fn texify(&self, t: &mut Texifier) -> SourceResult<()> { @@ -469,14 +524,23 @@ impl Texify for ScriptNode { /// A math alignment point: `&`, `&&`. /// -/// Tags: math. +/// # Parameters +/// - index: usize (positional, required) +/// The alignment point's index. +/// +/// # Tags +/// - math #[func] #[capable(Texify)] #[derive(Debug, Hash)] -pub struct AlignPointNode(pub usize); +pub struct AlignPointNode(pub NonZeroUsize); #[node] -impl AlignPointNode {} +impl AlignPointNode { + fn construct(_: &Vm, args: &mut Args) -> SourceResult<Content> { + Ok(Self(args.expect("index")?).pack()) + } +} impl Texify for AlignPointNode { fn texify(&self, _: &mut Texifier) -> SourceResult<()> { @@ -486,7 +550,12 @@ impl Texify for AlignPointNode { /// A square root. /// -/// Tags: math. +/// # Parameters +/// - body: Content (positional, required) +/// The expression to take the square root of. +/// +/// # Tags +/// - math #[func] #[capable(Texify)] #[derive(Debug, Hash)] @@ -510,7 +579,12 @@ impl Texify for SqrtNode { /// A floored expression. /// -/// Tags: math. +/// # Parameters +/// - body: Content (positional, required) +/// The expression to floor. +/// +/// # Tags +/// - math #[func] #[capable(Texify)] #[derive(Debug, Hash)] @@ -534,7 +608,12 @@ impl Texify for FloorNode { /// A ceiled expression. /// -/// Tags: math. +/// # Parameters +/// - body: Content (positional, required) +/// The expression to ceil. +/// +/// # Tags +/// - math #[func] #[capable(Texify)] #[derive(Debug, Hash)] diff --git a/library/src/math/style.rs b/library/src/math/style.rs index 444b1fb4..344aa071 100644 --- a/library/src/math/style.rs +++ b/library/src/math/style.rs @@ -2,7 +2,12 @@ use super::*; /// Serif (roman) font style. /// -/// Tags: math. +/// # Parameters +/// - body: Content (positional, required) +/// The piece of formula to style. +/// +/// # Tags +/// - math #[func] #[capable(Texify)] #[derive(Debug, Hash)] @@ -26,7 +31,12 @@ impl Texify for SerifNode { /// Sans-serif font style. /// -/// Tags: math. +/// # Parameters +/// - body: Content (positional, required) +/// The piece of formula to style. +/// +/// # Tags +/// - math #[func] #[capable(Texify)] #[derive(Debug, Hash)] @@ -50,7 +60,12 @@ impl Texify for SansNode { /// Bold font style. /// -/// Tags: math. +/// # Parameters +/// - body: Content (positional, required) +/// The piece of formula to style. +/// +/// # Tags +/// - math #[func] #[capable(Texify)] #[derive(Debug, Hash)] @@ -74,7 +89,12 @@ impl Texify for BoldNode { /// Italic font style. /// -/// Tags: math. +/// # Parameters +/// - body: Content (positional, required) +/// The piece of formula to style. +/// +/// # Tags +/// - math #[func] #[capable(Texify)] #[derive(Debug, Hash)] @@ -98,7 +118,12 @@ impl Texify for ItalNode { /// Calligraphic font style. /// -/// Tags: math. +/// # Parameters +/// - body: Content (positional, required) +/// The piece of formula to style. +/// +/// # Tags +/// - math #[func] #[capable(Texify)] #[derive(Debug, Hash)] @@ -122,7 +147,12 @@ impl Texify for CalNode { /// Fraktur font style. /// -/// Tags: math. +/// # Parameters +/// - body: Content (positional, required) +/// The piece of formula to style. +/// +/// # Tags +/// - math #[func] #[capable(Texify)] #[derive(Debug, Hash)] @@ -146,7 +176,12 @@ impl Texify for FrakNode { /// Monospace font style. /// -/// Tags: math. +/// # Parameters +/// - body: Content (positional, required) +/// The piece of formula to style. +/// +/// # Tags +/// - math #[func] #[capable(Texify)] #[derive(Debug, Hash)] @@ -170,7 +205,12 @@ impl Texify for MonoNode { /// Blackboard bold (double-struck) font style. /// -/// Tags: math. +/// # Parameters +/// - body: Content (positional, required) +/// The piece of formula to style. +/// +/// # Tags +/// - math #[func] #[capable(Texify)] #[derive(Debug, Hash)] diff --git a/library/src/meta/document.rs b/library/src/meta/document.rs index 8c664df3..e20821c5 100644 --- a/library/src/meta/document.rs +++ b/library/src/meta/document.rs @@ -3,7 +3,8 @@ use crate::prelude::*; /// The root node that represents a full document. /// -/// Tags: meta. +/// # Tags +/// - meta #[func] #[capable(LayoutRoot)] #[derive(Hash)] diff --git a/library/src/meta/link.rs b/library/src/meta/link.rs index 6f5d8af1..27294a8d 100644 --- a/library/src/meta/link.rs +++ b/library/src/meta/link.rs @@ -3,7 +3,14 @@ use crate::text::TextNode; /// Link text and other elements to a destination. /// -/// Tags: meta. +/// # Parameters +/// - dest: Destination (positional, required) +/// The destination the link points to. +/// - body: Content (positional) +/// How the link is represented. Defaults to the destination if it is a link. +/// +/// # Tags +/// - meta #[func] #[capable(Show, Finalize)] #[derive(Debug, Hash)] diff --git a/library/src/meta/outline.rs b/library/src/meta/outline.rs index 27ca5944..6ea65391 100644 --- a/library/src/meta/outline.rs +++ b/library/src/meta/outline.rs @@ -5,7 +5,8 @@ use crate::text::{LinebreakNode, SpaceNode, TextNode}; /// A section outline (table of contents). /// -/// Tags: meta. +/// # Tags +/// - meta #[func] #[capable(Prepare, Show)] #[derive(Debug, Hash)] diff --git a/library/src/meta/reference.rs b/library/src/meta/reference.rs index 378d19d2..c49ff970 100644 --- a/library/src/meta/reference.rs +++ b/library/src/meta/reference.rs @@ -3,7 +3,12 @@ use crate::text::TextNode; /// A reference to a label. /// -/// Tags: meta. +/// # Parameters +/// - target: Label (positional, required) +/// The label that should be referenced. +/// +/// # Tags +/// - meta #[func] #[capable(Show)] #[derive(Debug, Hash)] diff --git a/library/src/text/deco.rs b/library/src/text/deco.rs index 86866715..d725697e 100644 --- a/library/src/text/deco.rs +++ b/library/src/text/deco.rs @@ -6,7 +6,12 @@ use crate::prelude::*; /// Typeset underline, stricken-through or overlined text. /// -/// Tags: text. +/// # Parameters +/// - body: Content (positional, required) +/// The content to decorate. +/// +/// # Tags +/// - text #[func] #[capable(Show)] #[derive(Debug, Hash)] diff --git a/library/src/text/misc.rs b/library/src/text/misc.rs index fc4f7d73..20be156a 100644 --- a/library/src/text/misc.rs +++ b/library/src/text/misc.rs @@ -3,7 +3,8 @@ use crate::prelude::*; /// A text space. /// -/// Tags: text. +/// # Tags +/// - text #[func] #[capable(Unlabellable, Behave)] #[derive(Debug, Hash)] @@ -26,7 +27,12 @@ impl Behave for SpaceNode { /// A line break. /// -/// Tags: text. +/// # Parameters +/// - justify: bool (named) +/// Whether to justify the line before the break. +/// +/// # Tags +/// - text #[func] #[capable(Behave)] #[derive(Debug, Hash)] @@ -50,7 +56,12 @@ impl Behave for LinebreakNode { /// Strongly emphasizes content by increasing the font weight. /// -/// Tags: text. +/// # Parameters +/// - body: Content (positional, required) +/// The content to strongly emphasize. +/// +/// # Tags +/// - text #[func] #[capable(Show)] #[derive(Debug, Hash)] @@ -98,7 +109,12 @@ impl Fold for Delta { /// Emphasizes content by flipping the italicness. /// -/// Tags: text. +/// # Parameters +/// - body: Content (positional, required) +/// The content to emphasize. +/// +/// # Tags +/// - text #[func] #[capable(Show)] #[derive(Debug, Hash)] @@ -136,17 +152,27 @@ impl Fold for Toggle { } } -/// Convert a string or content to lowercase. +/// Convert text or content to lowercase. /// -/// Tags: text. +/// # Parameters +/// - text: ToCase (positional, required) +/// The text to convert to lowercase. +/// +/// # Tags +/// - text #[func] pub fn lower(args: &mut Args) -> SourceResult<Value> { case(Case::Lower, args) } -/// Convert a string or content to uppercase. +/// Convert text or content to uppercase. +/// +/// # Parameters +/// - text: ToCase (positional, required) +/// The text to convert to uppercase. /// -/// Tags: text. +/// # Tags +/// - text #[func] pub fn upper(args: &mut Args) -> SourceResult<Value> { case(Case::Upper, args) @@ -162,6 +188,15 @@ fn case(case: Case, args: &mut Args) -> SourceResult<Value> { }) } +/// A value whose case can be changed. +struct ToCase; + +castable! { + ToCase, + _: Str => Self, + _: Content => Self, +} + /// A case transformation on text. #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] pub enum Case { @@ -183,7 +218,12 @@ impl Case { /// Display text in small capitals. /// -/// Tags: text. +/// # Parameters +/// - text: Content (positional, required) +/// The text to display to small capitals. +/// +/// # Tags +/// - text #[func] pub fn smallcaps(args: &mut Args) -> SourceResult<Value> { let body: Content = args.expect("content")?; diff --git a/library/src/text/mod.rs b/library/src/text/mod.rs index 7340e5de..21dea8af 100644 --- a/library/src/text/mod.rs +++ b/library/src/text/mod.rs @@ -25,9 +25,16 @@ use typst::util::EcoString; use crate::layout::ParNode; use crate::prelude::*; -/// A single run of text with the same style. +/// Stylable text. /// -/// Tags: text. +/// # Parameters +/// - family: EcoString (positional, variadic, settable) +/// A prioritized sequence of font families. +/// - body: Content (positional, required) +/// Content in which all text is styled according to the other arguments. +/// +/// # Tags +/// - text #[func] #[capable] #[derive(Clone, Hash)] diff --git a/library/src/text/quotes.rs b/library/src/text/quotes.rs index ab6f166c..4f65c7fd 100644 --- a/library/src/text/quotes.rs +++ b/library/src/text/quotes.rs @@ -4,7 +4,12 @@ use crate::prelude::*; /// A smart quote. /// -/// Tags: text. +/// # Parameters +/// - double: bool (named) +/// Whether to produce a smart double quote. +/// +/// # Tags +/// - text #[func] #[capable] #[derive(Debug, Hash)] diff --git a/library/src/text/raw.rs b/library/src/text/raw.rs index 125a5da1..74626588 100644 --- a/library/src/text/raw.rs +++ b/library/src/text/raw.rs @@ -8,14 +8,21 @@ use crate::prelude::*; /// Raw text with optional syntax highlighting. /// -/// Tags: text. +/// # Parameters +/// - text: EcoString (positional, required) +/// The raw text. +/// - block: bool (named) +/// Whether the raw text is displayed as a separate block. +/// +/// # Tags +/// - text #[func] #[capable(Show)] #[derive(Debug, Hash)] pub struct RawNode { /// The raw text. pub text: EcoString, - /// Whether the node is block-level. + /// Whether the raw text is displayed as a separate block. pub block: bool, } diff --git a/library/src/text/shift.rs b/library/src/text/shift.rs index ad4a6cd9..969dce68 100644 --- a/library/src/text/shift.rs +++ b/library/src/text/shift.rs @@ -4,14 +4,19 @@ use typst::util::EcoString; use super::{variant, SpaceNode, TextNode, TextSize}; use crate::prelude::*; -/// Sub or superscript text. +/// Sub- or superscript text. /// -/// The text is rendered smaller and its baseline is raised. To provide the best -/// typography possible, we first try to transform the text to superscript -/// codepoints. If that fails, we fall back to rendering shrunk normal letters -/// in a raised way. +/// The text is rendered smaller and its baseline is raised/lowered. To provide +/// the best typography possible, we first try to transform the text to +/// superscript codepoints. If that fails, we fall back to rendering shrunk +/// normal letters in a raised way. /// -/// Tags: text. +/// # Parameters +/// - body: Content (positional, required) +/// The text to display in sub- or superscript. +/// +/// # Tags +/// - text #[func] #[capable(Show)] #[derive(Debug, Hash)] diff --git a/library/src/text/symbol.rs b/library/src/text/symbol.rs index eece81ab..ccf1a55e 100644 --- a/library/src/text/symbol.rs +++ b/library/src/text/symbol.rs @@ -3,7 +3,12 @@ use crate::text::TextNode; /// A symbol identified by symmie notation. /// -/// Tags: text. +/// # Parameters +/// - notation: EcoString (positional, required) +/// The symbols symmie notation. +/// +/// # Tags +/// - text #[func] #[capable(Show)] #[derive(Debug, Hash)] diff --git a/library/src/visualize/image.rs b/library/src/visualize/image.rs index 936ec3bf..0ce3f20b 100644 --- a/library/src/visualize/image.rs +++ b/library/src/visualize/image.rs @@ -6,7 +6,14 @@ use crate::prelude::*; /// Show a raster or vector graphic. /// -/// Tags: visualize. +/// Supported formats are PNG, JPEG, GIF and SVG. +/// +/// # Parameters +/// - path: EcoString (positional, required) +/// Path to an image file. +/// +/// # Tags +/// - visualize #[func] #[capable(Layout, Inline)] #[derive(Debug, Hash)] diff --git a/library/src/visualize/line.rs b/library/src/visualize/line.rs index 9c9b8b00..5c8c9644 100644 --- a/library/src/visualize/line.rs +++ b/library/src/visualize/line.rs @@ -2,7 +2,20 @@ use crate::prelude::*; /// Display a line without affecting the layout. /// -/// Tags: visualize. +/// You should only provide either an endpoint or an angle and a length. +/// +/// # Parameters +/// - origin: Axes<Rel<Length>> (named) +/// The start point of the line. +/// - to: Axes<Rel<Length>> (named) +/// The end point of the line. +/// - length: Rel<Length> (named) +/// The line's length. +/// - angle: Angle (named) +/// The angle at which the line points away from the origin. +/// +/// # Tags +/// - visualize #[func] #[capable(Layout, Inline)] #[derive(Debug, Hash)] diff --git a/library/src/visualize/shape.rs b/library/src/visualize/shape.rs index a3443189..be80b4fb 100644 --- a/library/src/visualize/shape.rs +++ b/library/src/visualize/shape.rs @@ -4,7 +4,22 @@ use crate::prelude::*; /// A sizable and fillable shape with optional content. /// -/// Tags: visualize. +/// # Parameters +/// - body: Content (positional) +/// The content to place into the shape. +/// - width: Rel<Length> (named) +/// The shape's width. +/// - height: Rel<Length> (named) +/// The shape's height. +/// - size: Length (named) +/// The square's side length. +/// - radius: Length (named) +/// The circle's radius. +/// - stroke: Smart<Sides<Option<PartialStroke>>> (named) +/// How to stroke the shape. +/// +/// # Tags +/// - visualize #[func] #[capable(Layout, Inline)] #[derive(Debug, Hash)] @@ -27,7 +42,7 @@ impl<const S: ShapeKind> ShapeNode<S> { /// How to fill the shape. pub const FILL: Option<Paint> = None; /// How to stroke the shape. - #[property(reflect, skip, resolve, fold)] + #[property(skip, resolve, fold)] pub const STROKE: Smart<Sides<Option<PartialStroke>>> = Smart::Auto; /// How much to pad the shape's content. @@ -38,7 +53,7 @@ impl<const S: ShapeKind> ShapeNode<S> { pub const OUTSET: Sides<Option<Rel<Length>>> = Sides::splat(Rel::zero()); /// How much to round the shape's corners. - #[property(reflect, skip, resolve, fold)] + #[property(skip, resolve, fold)] pub const RADIUS: Corners<Option<Rel<Length>>> = Corners::splat(Rel::zero()); fn construct(_: &Vm, args: &mut Args) -> SourceResult<Content> { |
