mirror of
https://github.com/typst/typst
synced 2025-06-28 16:22:53 +08:00
Formatting and documentation ✨
This commit is contained in:
parent
49bb7f9a2b
commit
6bd1a494e0
@ -2,26 +2,30 @@ use super::*;
|
|||||||
|
|
||||||
/// `align`: Align content along the layouting axes.
|
/// `align`: Align content along the layouting axes.
|
||||||
///
|
///
|
||||||
|
/// # Positional parameters
|
||||||
|
/// - Alignments: variadic, of type `alignment`.
|
||||||
|
/// - Body: optional, of type `template`.
|
||||||
|
///
|
||||||
/// Which axis an alignment should apply to (main or cross) is inferred from
|
/// Which axis an alignment should apply to (main or cross) is inferred from
|
||||||
/// either the argument itself (for anything other than `center`) or from the
|
/// either the argument itself (for anything other than `center`) or from the
|
||||||
/// second argument if present, defaulting to the cross axis for a single
|
/// second argument if present, defaulting to the cross axis for a single
|
||||||
/// `center` alignment.
|
/// `center` alignment.
|
||||||
///
|
///
|
||||||
/// # Positional arguments
|
/// # Named parameters
|
||||||
/// - Alignments: variadic, of type `alignment`.
|
|
||||||
/// - Body: optional, of type `template`.
|
|
||||||
///
|
|
||||||
/// # Named arguments
|
|
||||||
/// - Horizontal alignment: `horizontal`, of type `alignment`.
|
/// - Horizontal alignment: `horizontal`, of type `alignment`.
|
||||||
/// - Vertical alignment: `vertical`, of type `alignment`.
|
/// - Vertical alignment: `vertical`, of type `alignment`.
|
||||||
|
///
|
||||||
|
/// # Return value
|
||||||
|
/// A template that changes the alignment along the layouting axes. The effect
|
||||||
|
/// is scoped to the body if present.
|
||||||
///
|
///
|
||||||
/// # Relevant types and constants
|
/// # Relevant types and constants
|
||||||
/// - Type `alignment`
|
/// - Type `alignment`
|
||||||
/// - `left`
|
/// - `left`
|
||||||
/// - `right`
|
/// - `right`
|
||||||
/// - `top`
|
/// - `top`
|
||||||
/// - `bottom`
|
/// - `bottom`
|
||||||
/// - `center`
|
/// - `center`
|
||||||
pub fn align(ctx: &mut EvalContext, args: &mut ValueArgs) -> Value {
|
pub fn align(ctx: &mut EvalContext, args: &mut ValueArgs) -> Value {
|
||||||
let first = args.find(ctx);
|
let first = args.find(ctx);
|
||||||
let second = args.find(ctx);
|
let second = args.find(ctx);
|
||||||
|
@ -5,7 +5,7 @@ use super::*;
|
|||||||
|
|
||||||
/// `repr`: Get the string representation of a value.
|
/// `repr`: Get the string representation of a value.
|
||||||
///
|
///
|
||||||
/// # Positional arguments
|
/// # Positional parameters
|
||||||
/// - Any value.
|
/// - Any value.
|
||||||
///
|
///
|
||||||
/// # Return value
|
/// # Return value
|
||||||
@ -19,11 +19,14 @@ pub fn repr(ctx: &mut EvalContext, args: &mut ValueArgs) -> Value {
|
|||||||
|
|
||||||
/// `rgb`: Create an RGB(A) color.
|
/// `rgb`: Create an RGB(A) color.
|
||||||
///
|
///
|
||||||
/// # Positional arguments
|
/// # Positional parameters
|
||||||
/// - Red component: of type `float`, between 0.0 and 1.0.
|
/// - Red component: of type `float`, between 0.0 and 1.0.
|
||||||
/// - Green component: of type `float`, between 0.0 and 1.0.
|
/// - Green component: of type `float`, between 0.0 and 1.0.
|
||||||
/// - Blue component: of type `float`, between 0.0 and 1.0.
|
/// - Blue component: of type `float`, between 0.0 and 1.0.
|
||||||
/// - Alpha component: optional, of type `float`, between 0.0 and 1.0.
|
/// - Alpha component: optional, of type `float`, between 0.0 and 1.0.
|
||||||
|
///
|
||||||
|
/// # Return value
|
||||||
|
/// The color with the given components.
|
||||||
pub fn rgb(ctx: &mut EvalContext, args: &mut ValueArgs) -> Value {
|
pub fn rgb(ctx: &mut EvalContext, args: &mut ValueArgs) -> Value {
|
||||||
let r = args.require(ctx, "red component");
|
let r = args.require(ctx, "red component");
|
||||||
let g = args.require(ctx, "green component");
|
let g = args.require(ctx, "green component");
|
||||||
@ -49,7 +52,7 @@ pub fn rgb(ctx: &mut EvalContext, args: &mut ValueArgs) -> Value {
|
|||||||
|
|
||||||
/// `type`: Find out the name of a value's type.
|
/// `type`: Find out the name of a value's type.
|
||||||
///
|
///
|
||||||
/// # Positional arguments
|
/// # Positional parameters
|
||||||
/// - Any value.
|
/// - Any value.
|
||||||
///
|
///
|
||||||
/// # Return value
|
/// # Return value
|
||||||
|
@ -4,44 +4,48 @@ use super::*;
|
|||||||
|
|
||||||
/// `font`: Configure the font.
|
/// `font`: Configure the font.
|
||||||
///
|
///
|
||||||
/// # Positional arguments
|
/// # Positional parameters
|
||||||
/// - Font size: optional, of type `linear` relative to current font size.
|
/// - Font size: optional, of type `linear` relative to current font size.
|
||||||
/// - Font families: variadic, of type `font-family`.
|
/// - Font families: variadic, of type `font-family`.
|
||||||
/// - Body: optional, of type `template`.
|
/// - Body: optional, of type `template`.
|
||||||
///
|
///
|
||||||
/// # Named arguments
|
/// # Named parameters
|
||||||
/// - Font Style: `style`, of type `font-style`.
|
/// - Font Style: `style`, of type `font-style`.
|
||||||
/// - Font Weight: `weight`, of type `font-weight`.
|
/// - Font Weight: `weight`, of type `font-weight`.
|
||||||
/// - Serif family definition: `serif`, of type `font-families`.
|
/// - Font Stretch: `stretch`, of type `relative`, between 0.5 and 2.0.
|
||||||
/// - Sans-serif family definition: `sans-serif`, of type `font-families`.
|
/// - Serif family definition: `serif`, of type `font-familiy-list`.
|
||||||
/// - Monospace family definition: `monospace`, of type `font-families`.
|
/// - Sans-serif family definition: `sans-serif`, of type `font-familiy-list`.
|
||||||
/// - Font Stretch: `stretch`, of type `relative`, between 0.5 and 2.0.
|
/// - Monospace family definition: `monospace`, of type `font-familiy-list`.
|
||||||
|
///
|
||||||
|
/// # Return value
|
||||||
|
/// A template that configures font properties. The effect is scoped to the body
|
||||||
|
/// if present.
|
||||||
///
|
///
|
||||||
/// # Relevant types and constants
|
/// # Relevant types and constants
|
||||||
/// - Type `font-families`
|
/// - Type `font-family-list`
|
||||||
/// - coerces from `string`
|
/// - coerces from `string`
|
||||||
/// - coerces from `array`
|
/// - coerces from `array`
|
||||||
/// - coerces from `font-family`
|
/// - coerces from `font-family`
|
||||||
/// - Type `font-family`
|
/// - Type `font-family`
|
||||||
/// - `serif`
|
/// - `serif`
|
||||||
/// - `sans-serif`
|
/// - `sans-serif`
|
||||||
/// - `monospace`
|
/// - `monospace`
|
||||||
/// - coerces from `string`
|
/// - coerces from `string`
|
||||||
/// - Type `font-style`
|
/// - Type `font-style`
|
||||||
/// - `normal`
|
/// - `normal`
|
||||||
/// - `italic`
|
/// - `italic`
|
||||||
/// - `oblique`
|
/// - `oblique`
|
||||||
/// - Type `font-weight`
|
/// - Type `font-weight`
|
||||||
/// - `thin` (100)
|
/// - `thin` (100)
|
||||||
/// - `extralight` (200)
|
/// - `extralight` (200)
|
||||||
/// - `light` (300)
|
/// - `light` (300)
|
||||||
/// - `regular` (400)
|
/// - `regular` (400)
|
||||||
/// - `medium` (500)
|
/// - `medium` (500)
|
||||||
/// - `semibold` (600)
|
/// - `semibold` (600)
|
||||||
/// - `bold` (700)
|
/// - `bold` (700)
|
||||||
/// - `extrabold` (800)
|
/// - `extrabold` (800)
|
||||||
/// - `black` (900)
|
/// - `black` (900)
|
||||||
/// - coerces from `integer`
|
/// - coerces from `integer`
|
||||||
pub fn font(ctx: &mut EvalContext, args: &mut ValueArgs) -> Value {
|
pub fn font(ctx: &mut EvalContext, args: &mut ValueArgs) -> Value {
|
||||||
let size = args.find::<Linear>(ctx);
|
let size = args.find::<Linear>(ctx);
|
||||||
let list: Vec<_> = args.filter::<FontFamily>(ctx).map(|f| f.to_string()).collect();
|
let list: Vec<_> = args.filter::<FontFamily>(ctx).map(|f| f.to_string()).collect();
|
||||||
|
@ -8,8 +8,11 @@ use crate::layout::*;
|
|||||||
///
|
///
|
||||||
/// Supports PNG and JPEG files.
|
/// Supports PNG and JPEG files.
|
||||||
///
|
///
|
||||||
/// # Positional arguments
|
/// # Positional parameters
|
||||||
/// - Path to image file: of type `string`.
|
/// - Path to image file: of type `string`.
|
||||||
|
///
|
||||||
|
/// # Return value
|
||||||
|
/// A template that inserts an image.
|
||||||
pub fn image(ctx: &mut EvalContext, args: &mut ValueArgs) -> Value {
|
pub fn image(ctx: &mut EvalContext, args: &mut ValueArgs) -> Value {
|
||||||
let path = args.require::<Spanned<String>>(ctx, "path to image file");
|
let path = args.require::<Spanned<String>>(ctx, "path to image file");
|
||||||
let width = args.get(ctx, "width");
|
let width = args.get(ctx, "width");
|
||||||
|
@ -2,15 +2,18 @@ use super::*;
|
|||||||
|
|
||||||
/// `pad`: Pad content at the sides.
|
/// `pad`: Pad content at the sides.
|
||||||
///
|
///
|
||||||
/// # Positional arguments
|
/// # Positional parameters
|
||||||
/// - Padding for all sides: `padding`, of type `linear` relative to sides.
|
/// - Padding for all sides: `padding`, of type `linear` relative to sides.
|
||||||
/// - Body: of type `template`.
|
/// - Body: of type `template`.
|
||||||
///
|
///
|
||||||
/// # Named arguments
|
/// # Named parameters
|
||||||
/// - Left padding: `left`, of type `linear` relative to parent width.
|
/// - Left padding: `left`, of type `linear` relative to parent width.
|
||||||
/// - Right padding: `right`, of type `linear` relative to parent width.
|
/// - Right padding: `right`, of type `linear` relative to parent width.
|
||||||
/// - Top padding: `top`, of type `linear` relative to parent height.
|
/// - Top padding: `top`, of type `linear` relative to parent height.
|
||||||
/// - Bottom padding: `bottom`, of type `linear` relative to parent height.
|
/// - Bottom padding: `bottom`, of type `linear` relative to parent height.
|
||||||
|
///
|
||||||
|
/// # Return value
|
||||||
|
/// A template that pads the body at the sides.
|
||||||
pub fn pad(ctx: &mut EvalContext, args: &mut ValueArgs) -> Value {
|
pub fn pad(ctx: &mut EvalContext, args: &mut ValueArgs) -> Value {
|
||||||
let all = args.find(ctx);
|
let all = args.find(ctx);
|
||||||
let left = args.get(ctx, "left");
|
let left = args.get(ctx, "left");
|
||||||
|
@ -3,22 +3,33 @@ use crate::paper::{Paper, PaperClass};
|
|||||||
|
|
||||||
/// `page`: Configure pages.
|
/// `page`: Configure pages.
|
||||||
///
|
///
|
||||||
/// # Positional arguments
|
/// # Positional parameters
|
||||||
/// - Paper name: optional, of type `string`, see [here](crate::paper) for a
|
/// - Paper name: optional, of type `string`, see [here](crate::paper) for a
|
||||||
/// full list of all paper names.
|
/// full list of all paper names.
|
||||||
/// - Body: optional, of type `template`.
|
/// - Body: optional, of type `template`.
|
||||||
///
|
///
|
||||||
/// # Named arguments
|
/// # Named parameters
|
||||||
/// - Width of the page: `width`, of type `length`.
|
/// - Width of the page: `width`, of type `length`.
|
||||||
/// - Height of the page: `height`, of type `length`.
|
/// - Height of the page: `height`, of type `length`.
|
||||||
/// - Margins for all sides: `margins`, of type `linear` relative to sides.
|
/// - Margins for all sides: `margins`, of type `linear` relative to sides.
|
||||||
/// - Left margin: `left`, of type `linear` relative to width.
|
/// - Left margin: `left`, of type `linear` relative to width.
|
||||||
/// - Right margin: `right`, of type `linear` relative to width.
|
/// - Right margin: `right`, of type `linear` relative to width.
|
||||||
/// - Top margin: `top`, of type `linear` relative to height.
|
/// - Top margin: `top`, of type `linear` relative to height.
|
||||||
/// - Bottom margin: `bottom`, of type `linear` relative to height.
|
/// - Bottom margin: `bottom`, of type `linear` relative to height.
|
||||||
/// - Flip width and height: `flip`, of type `bool`.
|
/// - Flip width and height: `flip`, of type `bool`.
|
||||||
/// - Main layouting direction: `main-dir`, of type `direction`.
|
/// - Main layouting direction: `main-dir`, of type `direction`.
|
||||||
/// - Cross layouting direction: `cross-dir`, of type `direction`.
|
/// - Cross layouting direction: `cross-dir`, of type `direction`.
|
||||||
|
///
|
||||||
|
/// # Return value
|
||||||
|
/// A template that configures page properties. The effect is scoped to the body
|
||||||
|
/// if present.
|
||||||
|
///
|
||||||
|
/// # Relevant types and constants
|
||||||
|
/// - Type `direction`
|
||||||
|
/// - `ltr` (left to right)
|
||||||
|
/// - `rtl` (right to left)
|
||||||
|
/// - `ttb` (top to bottom)
|
||||||
|
/// - `btt` (bottom to top)
|
||||||
pub fn page(ctx: &mut EvalContext, args: &mut ValueArgs) -> Value {
|
pub fn page(ctx: &mut EvalContext, args: &mut ValueArgs) -> Value {
|
||||||
let paper = args.find::<Spanned<String>>(ctx).and_then(|name| {
|
let paper = args.find::<Spanned<String>>(ctx).and_then(|name| {
|
||||||
Paper::from_name(&name.v).or_else(|| {
|
Paper::from_name(&name.v).or_else(|| {
|
||||||
@ -96,6 +107,9 @@ pub fn page(ctx: &mut EvalContext, args: &mut ValueArgs) -> Value {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// `pagebreak`: Start a new page.
|
/// `pagebreak`: Start a new page.
|
||||||
|
///
|
||||||
|
/// # Return value
|
||||||
|
/// A template that starts a new page.
|
||||||
pub fn pagebreak(_: &mut EvalContext, args: &mut ValueArgs) -> Value {
|
pub fn pagebreak(_: &mut EvalContext, args: &mut ValueArgs) -> Value {
|
||||||
let span = args.span;
|
let span = args.span;
|
||||||
Value::template("pagebreak", move |ctx| {
|
Value::template("pagebreak", move |ctx| {
|
||||||
|
@ -2,22 +2,25 @@ use super::*;
|
|||||||
|
|
||||||
/// `rect`: Create a rectangular box.
|
/// `rect`: Create a rectangular box.
|
||||||
///
|
///
|
||||||
/// # Positional arguments
|
/// # Positional parameters
|
||||||
/// - Body: optional, of type `template`.
|
/// - Body: optional, of type `template`.
|
||||||
///
|
///
|
||||||
/// # Named arguments
|
/// # Named parameters
|
||||||
/// - Width of the box: `width`, of type `linear` relative to parent width.
|
/// - Width of the box: `width`, of type `linear` relative to parent width.
|
||||||
/// - Height of the box: `height`, of type `linear` relative to parent height.
|
/// - Height of the box: `height`, of type `linear` relative to parent height.
|
||||||
/// - Main layouting direction: `main-dir`, of type `direction`.
|
/// - Main layouting direction: `main-dir`, of type `direction`.
|
||||||
/// - Cross layouting direction: `cross-dir`, of type `direction`.
|
/// - Cross layouting direction: `cross-dir`, of type `direction`.
|
||||||
/// - Fill color of the box: `fill`, of type `color`.
|
/// - Fill color of the box: `fill`, of type `color`.
|
||||||
|
///
|
||||||
|
/// # Return value
|
||||||
|
/// A template that places the body into a rectangle.
|
||||||
///
|
///
|
||||||
/// # Relevant types and constants
|
/// # Relevant types and constants
|
||||||
/// - Type `direction`
|
/// - Type `direction`
|
||||||
/// - `ltr` (left to right)
|
/// - `ltr` (left to right)
|
||||||
/// - `rtl` (right to left)
|
/// - `rtl` (right to left)
|
||||||
/// - `ttb` (top to bottom)
|
/// - `ttb` (top to bottom)
|
||||||
/// - `btt` (bottom to top)
|
/// - `btt` (bottom to top)
|
||||||
pub fn rect(ctx: &mut EvalContext, args: &mut ValueArgs) -> Value {
|
pub fn rect(ctx: &mut EvalContext, args: &mut ValueArgs) -> Value {
|
||||||
let width = args.get(ctx, "width");
|
let width = args.get(ctx, "width");
|
||||||
let height = args.get(ctx, "height");
|
let height = args.get(ctx, "height");
|
||||||
|
@ -2,16 +2,22 @@ use super::*;
|
|||||||
|
|
||||||
/// `h`: Add horizontal spacing.
|
/// `h`: Add horizontal spacing.
|
||||||
///
|
///
|
||||||
/// # Positional arguments
|
/// # Positional parameters
|
||||||
/// - Amount of spacing: of type `linear` relative to current font size.
|
/// - Amount of spacing: of type `linear` relative to current font size.
|
||||||
|
///
|
||||||
|
/// # Return value
|
||||||
|
/// A template that adds horizontal spacing.
|
||||||
pub fn h(ctx: &mut EvalContext, args: &mut ValueArgs) -> Value {
|
pub fn h(ctx: &mut EvalContext, args: &mut ValueArgs) -> Value {
|
||||||
spacing(ctx, args, SpecAxis::Horizontal)
|
spacing(ctx, args, SpecAxis::Horizontal)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `v`: Add vertical spacing.
|
/// `v`: Add vertical spacing.
|
||||||
///
|
///
|
||||||
/// # Positional arguments
|
/// # Positional parameters
|
||||||
/// - Amount of spacing: of type `linear` relative to current font size.
|
/// - Amount of spacing: of type `linear` relative to current font size.
|
||||||
|
///
|
||||||
|
/// # Return value
|
||||||
|
/// A template that adds vertical spacing.
|
||||||
pub fn v(ctx: &mut EvalContext, args: &mut ValueArgs) -> Value {
|
pub fn v(ctx: &mut EvalContext, args: &mut ValueArgs) -> Value {
|
||||||
spacing(ctx, args, SpecAxis::Vertical)
|
spacing(ctx, args, SpecAxis::Vertical)
|
||||||
}
|
}
|
||||||
@ -19,7 +25,6 @@ pub fn v(ctx: &mut EvalContext, args: &mut ValueArgs) -> Value {
|
|||||||
/// Apply spacing along a specific axis.
|
/// Apply spacing along a specific axis.
|
||||||
fn spacing(ctx: &mut EvalContext, args: &mut ValueArgs, axis: SpecAxis) -> Value {
|
fn spacing(ctx: &mut EvalContext, args: &mut ValueArgs, axis: SpecAxis) -> Value {
|
||||||
let spacing: Option<Linear> = args.require(ctx, "spacing");
|
let spacing: Option<Linear> = args.require(ctx, "spacing");
|
||||||
|
|
||||||
Value::template("spacing", move |ctx| {
|
Value::template("spacing", move |ctx| {
|
||||||
if let Some(linear) = spacing {
|
if let Some(linear) = spacing {
|
||||||
let amount = linear.resolve(ctx.state.font.font_size());
|
let amount = linear.resolve(ctx.state.font.font_size());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user