diff options
Diffstat (limited to 'crates/typst-library/src/meta/context.rs')
| -rw-r--r-- | crates/typst-library/src/meta/context.rs | 83 |
1 files changed, 16 insertions, 67 deletions
diff --git a/crates/typst-library/src/meta/context.rs b/crates/typst-library/src/meta/context.rs index a42c6980..3a82a925 100644 --- a/crates/typst-library/src/meta/context.rs +++ b/crates/typst-library/src/meta/context.rs @@ -2,9 +2,9 @@ use crate::prelude::*; /// Provides access to the location of content. /// -/// This is useful in combination with [queries]($func/query), -/// [counters]($func/counter), [state]($func/state), and [links]($func/link). -/// See their documentation for more details. +/// This is useful in combination with [queries]($query), [counters]($counter), +/// [state]($state), and [links]($link). See their documentation for more +/// details. /// /// ```example /// #locate(loc => [ @@ -12,44 +12,10 @@ use crate::prelude::*; /// #loc.position()! /// ]) /// ``` -/// -/// ## Methods -/// ### page() -/// Returns the page number for this location. -/// -/// Note that this does not return the value of the [page counter]($func/counter) -/// at this location, but the true page number (starting from one). -/// -/// If you want to know the value of the page counter, use -/// `{counter(page).at(loc)}` instead. -/// -/// - returns: integer -/// -/// ### position() -/// Returns a dictionary with the page number and the x, y position for this -/// location. The page number starts at one and the coordinates are measured -/// from the top-left of the page. -/// -/// If you only need the page number, use `page()` instead as it allows Typst -/// to skip unnecessary work. -/// -/// - returns: dictionary -/// -/// ### page-numbering() -/// Returns the page numbering pattern of the page at this location. This can be -/// used when displaying the page counter in order to obtain the local numbering. -/// This is useful if you are building custom indices or outlines. -/// -/// If the page numbering is set to `none` at that location, this function returns `none`. -/// -/// - returns: string or function or none -/// -/// Display: Locate -/// Category: meta #[func] pub fn locate( - /// A function that receives a `location`. Its return value is displayed - /// in the document. + /// A function that receives a [`location`]($location). Its return value is + /// displayed in the document. /// /// This function is called once for each time the content returned by /// `locate` appears in the document. That makes it possible to generate @@ -60,10 +26,7 @@ pub fn locate( } /// Executes a `locate` call. -/// -/// Display: Locate -/// Category: special -#[element(Locatable, Show)] +#[elem(Locatable, Show)] struct LocateElem { /// The function to call with the location. #[required] @@ -83,9 +46,9 @@ impl Show for LocateElem { /// Provides access to active styles. /// /// The styles are currently opaque and only useful in combination with the -/// [`measure`]($func/measure) function. See its documentation for more details. -/// In the future, the provided styles might also be directly accessed to look -/// up styles defined by [set rules]($styling/#set-rules). +/// [`measure`]($measure) function. See its documentation for more details. In +/// the future, the provided styles might also be directly accessed to look up +/// styles defined by [set rules]($styling/#set-rules). /// /// ```example /// #let thing(body) = style(styles => { @@ -96,9 +59,6 @@ impl Show for LocateElem { /// #thing[Hey] \ /// #thing[Welcome] /// ``` -/// -/// Display: Style -/// Category: meta #[func] pub fn style( /// A function to call with the styles. Its return value is displayed @@ -113,10 +73,7 @@ pub fn style( } /// Executes a style access. -/// -/// Display: Style -/// Category: special -#[element(Show)] +#[elem(Show)] struct StyleElem { /// The function to call with the styles. #[required] @@ -134,10 +91,8 @@ impl Show for StyleElem { /// (width and height). /// /// The given function must accept a single parameter, `size`, which is a -/// dictionary with keys `width` and `height`, both of type -/// [`length`]($type/length). +/// dictionary with keys `width` and `height`, both of type [`length`]($length). /// - /// ```example /// #let text = lorem(30) /// #layout(size => style(styles => [ @@ -155,9 +110,9 @@ impl Show for StyleElem { /// and a height of `{400pt}`, then the specified function will be given the /// parameter `{(width: 800pt, height: 400pt)}`. If it placed directly into the /// page it receives the page's dimensions minus its margins. This is mostly -/// useful in combination with [measurement]($func/measure). +/// useful in combination with [measurement]($measure). /// -/// You can also use this function to resolve [`ratio`]($type/ratio) to fixed +/// You can also use this function to resolve [`ratio`]($ratio) to fixed /// lengths. This might come in handy if you're building your own layout /// abstractions. /// @@ -170,16 +125,13 @@ impl Show for StyleElem { /// /// Note that this function will provide an infinite width or height if one of /// the page width or height is `auto`, respectively. -/// -/// Display: Layout -/// Category: meta #[func] pub fn layout( /// A function to call with the outer container's size. Its return value is /// displayed in the document. /// - /// The container's size is given as a [dictionary]($type/dictionary) with - /// the keys `width` and `height`. + /// The container's size is given as a [dictionary]($dictionary) with the + /// keys `width` and `height`. /// /// This function is called once for each time the content returned by /// `layout` appears in the document. That makes it possible to generate @@ -190,10 +142,7 @@ pub fn layout( } /// Executes a `layout` call. -/// -/// Display: Layout -/// Category: special -#[element(Layout)] +#[elem(Layout)] struct LayoutElem { /// The function to call with the outer container's (or page's) size. #[required] |
