diff --git a/docs/src/lib.rs b/docs/src/lib.rs index 57f8657ef..1989970e7 100644 --- a/docs/src/lib.rs +++ b/docs/src/lib.rs @@ -136,7 +136,6 @@ fn reference_page(resolver: &dyn Resolver) -> PageModel { category_page(resolver, "calculate"), category_page(resolver, "construct"), category_page(resolver, "data-loading"), - category_page(resolver, "utility"), ]; page } diff --git a/library/src/compute/mod.rs b/library/src/compute/mod.rs index 5cfbe1582..cf0486db5 100644 --- a/library/src/compute/mod.rs +++ b/library/src/compute/mod.rs @@ -4,10 +4,8 @@ mod calc; mod construct; mod data; mod foundations; -mod utility; pub use self::calc::*; pub use self::construct::*; pub use self::data::*; pub use self::foundations::*; -pub use self::utility::*; diff --git a/library/src/layout/enum.rs b/library/src/layout/enum.rs index 866a6195f..53fc33276 100644 --- a/library/src/layout/enum.rs +++ b/library/src/layout/enum.rs @@ -1,7 +1,7 @@ use std::str::FromStr; -use crate::compute::{Numbering, NumberingPattern}; use crate::layout::{BlockNode, GridNode, ParNode, Sizing, Spacing}; +use crate::meta::{Numbering, NumberingPattern}; use crate::prelude::*; use crate::text::TextNode; diff --git a/library/src/lib.rs b/library/src/lib.rs index 412ebd415..8a2315319 100644 --- a/library/src/lib.rs +++ b/library/src/lib.rs @@ -42,6 +42,7 @@ fn global(math: Module, calc: Module) -> Module { global.def_func::("strike"); global.def_func::("overline"); global.def_func::("raw"); + global.def_func::("lorem"); // Math. global.define("math", math); @@ -86,6 +87,7 @@ fn global(math: Module, calc: Module) -> Module { global.def_func::("link"); global.def_func::("outline"); global.def_func::("heading"); + global.def_func::("numbering"); // Symbols. global.define("sym", symbols::sym()); @@ -110,8 +112,6 @@ fn global(math: Module, calc: Module) -> Module { global.def_func::("csv"); global.def_func::("json"); global.def_func::("xml"); - global.def_func::("lorem"); - global.def_func::("numbering"); // Calc. global.define("calc", calc); diff --git a/library/src/meta/heading.rs b/library/src/meta/heading.rs index b5b0fd9e8..c9032e888 100644 --- a/library/src/meta/heading.rs +++ b/library/src/meta/heading.rs @@ -1,6 +1,6 @@ use typst::font::FontWeight; -use crate::compute::Numbering; +use super::Numbering; use crate::layout::{BlockNode, VNode}; use crate::prelude::*; use crate::text::{SpaceNode, TextNode, TextSize}; diff --git a/library/src/meta/mod.rs b/library/src/meta/mod.rs index fd72a8cba..07f449a42 100644 --- a/library/src/meta/mod.rs +++ b/library/src/meta/mod.rs @@ -3,11 +3,13 @@ mod document; mod heading; mod link; +mod numbering; mod outline; mod reference; pub use self::document::*; pub use self::heading::*; pub use self::link::*; +pub use self::numbering::*; pub use self::outline::*; pub use self::reference::*; diff --git a/library/src/compute/utility.rs b/library/src/meta/numbering.rs similarity index 91% rename from library/src/compute/utility.rs rename to library/src/meta/numbering.rs index 2220c890b..c187c18db 100644 --- a/library/src/compute/utility.rs +++ b/library/src/meta/numbering.rs @@ -3,37 +3,6 @@ use std::str::FromStr; use crate::prelude::*; use crate::text::Case; -/// # Blind Text -/// Create blind text. -/// -/// This function yields a Latin-like _Lorem Ipsum_ blind text with the given -/// number of words. The sequence of words generated by the function is always -/// the same but randomly chosen. As usual for blind texts, it does not make any -/// sense. Use it as a placeholder to try layouts. -/// -/// ## Example -/// ```example -/// = Blind Text -/// #lorem(30) -/// -/// = More Blind Text -/// #lorem(15) -/// ``` -/// -/// ## Parameters -/// - words: `usize` (positional, required) -/// The length of the blind text in words. -/// -/// - returns: string -/// -/// ## Category -/// utility -#[func] -pub fn lorem(args: &mut Args) -> SourceResult { - let words: usize = args.expect("number of words")?; - Ok(Value::Str(lipsum::lipsum(words).into())) -} - /// # Numbering /// Apply a numbering to a sequence of numbers. /// @@ -93,7 +62,7 @@ pub fn lorem(args: &mut Args) -> SourceResult { /// - returns: any /// /// ## Category -/// utility +/// meta #[func] pub fn numbering(vm: &Vm, args: &mut Args) -> SourceResult { let numbering = args.expect::("pattern or function")?; diff --git a/library/src/text/misc.rs b/library/src/text/misc.rs index 184294d49..43aea021b 100644 --- a/library/src/text/misc.rs +++ b/library/src/text/misc.rs @@ -345,3 +345,34 @@ pub fn smallcaps(args: &mut Args) -> SourceResult { let body: Content = args.expect("content")?; Ok(Value::Content(body.styled(TextNode::SMALLCAPS, true))) } + +/// # Blind Text +/// Create blind text. +/// +/// This function yields a Latin-like _Lorem Ipsum_ blind text with the given +/// number of words. The sequence of words generated by the function is always +/// the same but randomly chosen. As usual for blind texts, it does not make any +/// sense. Use it as a placeholder to try layouts. +/// +/// ## Example +/// ```example +/// = Blind Text +/// #lorem(30) +/// +/// = More Blind Text +/// #lorem(15) +/// ``` +/// +/// ## Parameters +/// - words: `usize` (positional, required) +/// The length of the blind text in words. +/// +/// - returns: string +/// +/// ## Category +/// text +#[func] +pub fn lorem(args: &mut Args) -> SourceResult { + let words: usize = args.expect("number of words")?; + Ok(Value::Str(lipsum::lipsum(words).into())) +} diff --git a/tests/ref/compute/utility.png b/tests/ref/compute/utility.png deleted file mode 100644 index 79e3096d4..000000000 Binary files a/tests/ref/compute/utility.png and /dev/null differ diff --git a/tests/ref/meta/numbering.png b/tests/ref/meta/numbering.png new file mode 100644 index 000000000..ed97d891a Binary files /dev/null and b/tests/ref/meta/numbering.png differ diff --git a/tests/ref/text/lorem.png b/tests/ref/text/lorem.png new file mode 100644 index 000000000..ded763303 Binary files /dev/null and b/tests/ref/text/lorem.png differ diff --git a/tests/typ/meta/numbering.typ b/tests/typ/meta/numbering.typ new file mode 100644 index 000000000..63e453623 --- /dev/null +++ b/tests/typ/meta/numbering.typ @@ -0,0 +1,18 @@ +// Test integrated numbering patterns. + +--- +#for i in range(1, 9) { + numbering("*", i) + [ and ] + numbering("I.a", i, i) + [ for #i] + parbreak() +} + +--- +// Error: 17-18 number must be positive +#numbering("1", 0) + +--- +// Error: 17-19 number must be positive +#numbering("1", -1) diff --git a/tests/typ/compute/utility.typ b/tests/typ/text/lorem.typ similarity index 59% rename from tests/typ/compute/utility.typ rename to tests/typ/text/lorem.typ index 73bb2e2d9..944fd5be4 100644 --- a/tests/typ/compute/utility.typ +++ b/tests/typ/text/lorem.typ @@ -1,4 +1,4 @@ -// Test integrated numbering patterns. +// Test blind text. --- // Test basic call. @@ -30,20 +30,3 @@ --- // Error: 7-9 missing argument: number of words #lorem() - ---- -#for i in range(1, 9) { - numbering("*", i) - [ and ] - numbering("I.a", i, i) - [ for #i] - parbreak() -} - ---- -// Error: 17-18 number must be positive -#numbering("1", 0) - ---- -// Error: 17-19 number must be positive -#numbering("1", -1)