mirror of
https://github.com/typst/typst
synced 2025-08-18 08:58:33 +08:00
58 lines
1.7 KiB
Rust
58 lines
1.7 KiB
Rust
use crate::diag::SourceResult;
|
|
use crate::engine::Engine;
|
|
use crate::foundations::{
|
|
elem, Content, NativeElement, Packed, Show, StyleChain, TargetElem,
|
|
};
|
|
use crate::html::{tag, HtmlElem};
|
|
use crate::introspection::Locatable;
|
|
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"], Locatable, 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> {
|
|
let body = self.body.clone();
|
|
Ok(if styles.get(TargetElem::target).is_html() {
|
|
HtmlElem::new(tag::strong)
|
|
.with_body(Some(body))
|
|
.pack()
|
|
.spanned(self.span())
|
|
} else {
|
|
body.set(TextElem::delta, WeightDelta(self.delta.get(styles)))
|
|
})
|
|
}
|
|
}
|