mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Add blind text function
This commit is contained in:
parent
7163b4a6c5
commit
649c101f07
41
Cargo.lock
generated
41
Cargo.lock
generated
@ -334,6 +334,15 @@ dependencies = [
|
|||||||
"safemem",
|
"safemem",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lipsum"
|
||||||
|
version = "0.8.0"
|
||||||
|
source = "git+https://github.com/reknih/lipsum#c97ce95ba01ed2cce1d1b0b230b6b78295b0720b"
|
||||||
|
dependencies = [
|
||||||
|
"rand",
|
||||||
|
"rand_chacha",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lock_api"
|
name = "lock_api"
|
||||||
version = "0.4.6"
|
version = "0.4.6"
|
||||||
@ -543,6 +552,12 @@ dependencies = [
|
|||||||
"miniz_oxide 0.5.1",
|
"miniz_oxide 0.5.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ppv-lite86"
|
||||||
|
version = "0.2.16"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.36"
|
version = "1.0.36"
|
||||||
@ -561,6 +576,31 @@ dependencies = [
|
|||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand"
|
||||||
|
version = "0.8.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
||||||
|
dependencies = [
|
||||||
|
"rand_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_chacha"
|
||||||
|
version = "0.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
||||||
|
dependencies = [
|
||||||
|
"ppv-lite86",
|
||||||
|
"rand_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_core"
|
||||||
|
version = "0.6.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rctree"
|
name = "rctree"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
@ -854,6 +894,7 @@ dependencies = [
|
|||||||
"iai",
|
"iai",
|
||||||
"image",
|
"image",
|
||||||
"kurbo",
|
"kurbo",
|
||||||
|
"lipsum",
|
||||||
"memmap2",
|
"memmap2",
|
||||||
"miniz_oxide 0.4.4",
|
"miniz_oxide 0.4.4",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
|
@ -17,6 +17,7 @@ typst-macros = { path = "./macros" }
|
|||||||
bytemuck = "1"
|
bytemuck = "1"
|
||||||
either = "1"
|
either = "1"
|
||||||
fxhash = "0.2"
|
fxhash = "0.2"
|
||||||
|
lipsum = { git = "https://github.com/reknih/lipsum", default-features = false }
|
||||||
once_cell = "1"
|
once_cell = "1"
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
typed-arena = "2"
|
typed-arena = "2"
|
||||||
|
@ -88,6 +88,7 @@ pub fn new() -> Scope {
|
|||||||
std.def_fn("letter", utility::letter);
|
std.def_fn("letter", utility::letter);
|
||||||
std.def_fn("roman", utility::roman);
|
std.def_fn("roman", utility::roman);
|
||||||
std.def_fn("symbol", utility::symbol);
|
std.def_fn("symbol", utility::symbol);
|
||||||
|
std.def_fn("lipsum", utility::lipsum);
|
||||||
|
|
||||||
// Predefined colors.
|
// Predefined colors.
|
||||||
std.def_const("black", Color::BLACK);
|
std.def_const("black", Color::BLACK);
|
||||||
|
9
src/library/utility/blind.rs
Normal file
9
src/library/utility/blind.rs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
use lipsum::lipsum_from_seed;
|
||||||
|
|
||||||
|
use crate::library::prelude::*;
|
||||||
|
|
||||||
|
/// Create blind text.
|
||||||
|
pub fn lipsum(_: &mut Context, args: &mut Args) -> TypResult<Value> {
|
||||||
|
let words: usize = args.expect("number of words")?;
|
||||||
|
Ok(Value::Str(lipsum_from_seed(words, 97).into()))
|
||||||
|
}
|
@ -1,9 +1,11 @@
|
|||||||
//! Computational utility functions.
|
//! Computational utility functions.
|
||||||
|
|
||||||
|
mod blind;
|
||||||
mod color;
|
mod color;
|
||||||
mod math;
|
mod math;
|
||||||
mod string;
|
mod string;
|
||||||
|
|
||||||
|
pub use blind::*;
|
||||||
pub use color::*;
|
pub use color::*;
|
||||||
pub use math::*;
|
pub use math::*;
|
||||||
pub use string::*;
|
pub use string::*;
|
||||||
|
BIN
tests/ref/utility/blind.png
Normal file
BIN
tests/ref/utility/blind.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 27 KiB |
32
tests/typ/utility/blind.typ
Normal file
32
tests/typ/utility/blind.typ
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
// Test blind text.
|
||||||
|
|
||||||
|
---
|
||||||
|
// Test basic call.
|
||||||
|
#lipsum(19)
|
||||||
|
|
||||||
|
---
|
||||||
|
// Test custom paragraphs with user code.
|
||||||
|
#set text(8pt)
|
||||||
|
|
||||||
|
{
|
||||||
|
let sentences = lipsum(59)
|
||||||
|
.split(".")
|
||||||
|
.filter(s => s != "")
|
||||||
|
.map(s => s + ".")
|
||||||
|
|
||||||
|
let used = 0
|
||||||
|
for s in sentences {
|
||||||
|
if used < 2 {
|
||||||
|
used += 1
|
||||||
|
} else {
|
||||||
|
parbreak()
|
||||||
|
used = 0
|
||||||
|
}
|
||||||
|
s.trim()
|
||||||
|
[ ]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
---
|
||||||
|
// Error: 8-10 missing argument: number of words
|
||||||
|
#lipsum()
|
Loading…
x
Reference in New Issue
Block a user