typst_library/text/
linebreak.rs

1use typst_utils::singleton;
2
3use crate::foundations::{Content, NativeElement, elem};
4
5/// Inserts a line break.
6///
7/// Advances the paragraph to the next line. A single trailing line break at the
8/// end of a paragraph is ignored, but more than one creates additional empty
9/// lines.
10///
11/// # Example
12/// ```example
13/// *Date:* 26.12.2022 \
14/// *Topic:* Infrastructure Test \
15/// *Severity:* High \
16/// ```
17///
18/// # Syntax
19/// This function also has dedicated syntax: To insert a line break, simply write
20/// a backslash followed by whitespace. This always creates an unjustified
21/// break.
22#[elem(title = "Line Break")]
23pub struct LinebreakElem {
24    /// Whether to justify the line before the break.
25    ///
26    /// This is useful if you found a better line break opportunity in your
27    /// justified text than Typst did.
28    ///
29    /// ```example
30    /// #set par(justify: true)
31    /// #let jb = linebreak(justify: true)
32    ///
33    /// I have manually tuned the #jb
34    /// line breaks in this paragraph #jb
35    /// for an _interesting_ result. #jb
36    /// ```
37    #[default(false)]
38    pub justify: bool,
39}
40
41impl LinebreakElem {
42    /// Get the globally shared linebreak element.
43    pub fn shared() -> &'static Content {
44        singleton!(Content, LinebreakElem::new().pack())
45    }
46}