Skip to content

Commit

Permalink
change smallcaps into element function
Browse files Browse the repository at this point in the history
  • Loading branch information
Coekjan committed Apr 30, 2024
1 parent 1247c6d commit f3b899f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion crates/typst/src/text/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ pub(super) fn define(global: &mut Scope) {
global.define_elem::<OverlineElem>();
global.define_elem::<StrikeElem>();
global.define_elem::<HighlightElem>();
global.define_elem::<SmallCapsElem>();
global.define_elem::<RawElem>();
global.define_func::<lower>();
global.define_func::<upper>();
global.define_func::<smallcaps>();
global.define_func::<lorem>();
}

Expand Down
21 changes: 14 additions & 7 deletions crates/typst/src/text/smallcaps.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::foundations::{func, Content};
use crate::diag::SourceResult;
use crate::engine::Engine;
use crate::foundations::{elem, Content, Packed, Show, StyleChain};
use crate::text::TextElem;

/// Displays text in small capitals.
Expand All @@ -23,10 +25,15 @@ use crate::text::TextElem;
/// = Introduction
/// #lorem(40)
/// ```
#[func(title = "Small Capitals")]
pub fn smallcaps(
/// The text to display to small capitals.
body: Content,
) -> Content {
body.styled(TextElem::set_smallcaps(true))
#[elem(name = "smallcaps", title = "Small Capitals", Show)]
pub struct SmallCapsElem {
#[required]
pub body: Content,
}

impl Show for Packed<SmallCapsElem> {
#[typst_macros::time(name = "smallcaps", span = self.span())]
fn show(&self, _: &mut Engine, _: StyleChain) -> SourceResult<Content> {
Ok(self.body().clone().styled(TextElem::set_smallcaps(true)))
}
}

0 comments on commit f3b899f

Please sign in to comment.