summaryrefslogtreecommitdiff
path: root/crates/typst-library/src/model/strong.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/typst-library/src/model/strong.rs')
-rw-r--r--crates/typst-library/src/model/strong.rs48
1 files changed, 48 insertions, 0 deletions
diff --git a/crates/typst-library/src/model/strong.rs b/crates/typst-library/src/model/strong.rs
new file mode 100644
index 00000000..0e23179e
--- /dev/null
+++ b/crates/typst-library/src/model/strong.rs
@@ -0,0 +1,48 @@
+use crate::diag::SourceResult;
+use crate::engine::Engine;
+use crate::foundations::{elem, Content, Packed, Show, StyleChain};
+use crate::text::{TextElem, WeightDelta};
+
+/// Strongly emphasizes content by increasing the font weight.
+///
+/// Increases the current font weight by a given `delta`.
+///
+/// # Example
+/// ```example
+/// This is *strong.* \
+/// This is #strong[too.] \
+///
+/// #show strong: set text(red)
+/// And this is *evermore.*
+/// ```
+///
+/// # Syntax
+/// This function also has dedicated syntax: To strongly emphasize content,
+/// simply enclose it in stars/asterisks (`*`). Note that this only works at
+/// word boundaries. To strongly emphasize part of a word, you have to use the
+/// function.
+#[elem(title = "Strong Emphasis", keywords = ["bold", "weight"], Show)]
+pub struct StrongElem {
+ /// The delta to apply on the font weight.
+ ///
+ /// ```example
+ /// #set strong(delta: 0)
+ /// No *effect!*
+ /// ```
+ #[default(300)]
+ pub delta: i64,
+
+ /// The content to strongly emphasize.
+ #[required]
+ pub body: Content,
+}
+
+impl Show for Packed<StrongElem> {
+ #[typst_macros::time(name = "strong", span = self.span())]
+ fn show(&self, _: &mut Engine, styles: StyleChain) -> SourceResult<Content> {
+ Ok(self
+ .body()
+ .clone()
+ .styled(TextElem::set_delta(WeightDelta(self.delta(styles)))))
+ }
+}