diff --git a/src/library/structure/heading.rs b/src/library/structure/heading.rs index 70589de06..1cfcb6d01 100644 --- a/src/library/structure/heading.rs +++ b/src/library/structure/heading.rs @@ -1,6 +1,6 @@ use crate::library::layout::BlockSpacing; use crate::library::prelude::*; -use crate::library::text::{FontFamily, TextNode, TextSize, Toggle}; +use crate::library::text::{FontFamily, TextNode, TextSize}; /// A section heading. #[derive(Debug, Hash)] @@ -103,11 +103,11 @@ impl Show for HeadingNode { } if resolve!(Self::STRONG) { - map.set(TextNode::STRONG, Toggle); + realized = realized.strong(); } if resolve!(Self::EMPH) { - map.set(TextNode::EMPH, Toggle); + realized = realized.emph(); } if resolve!(Self::UNDERLINE) { diff --git a/src/library/text/mod.rs b/src/library/text/mod.rs index ae7024e59..1b83b0f4f 100644 --- a/src/library/text/mod.rs +++ b/src/library/text/mod.rs @@ -110,10 +110,10 @@ impl TextNode { /// Whether the font weight should be increased by 300. #[property(skip, fold)] - pub const STRONG: Toggle = false; + pub const BOLD: Toggle = false; /// Whether the the font style should be inverted. #[property(skip, fold)] - pub const EMPH: Toggle = false; + pub const ITALIC: Toggle = false; /// A case transformation that should be applied to the text. #[property(skip)] pub const CASE: Option = None; @@ -508,7 +508,7 @@ impl Fold for Decoration { } } -/// Strong text, rendered in boldface. +/// Strong text, rendered in boldface by default. #[derive(Debug, Hash)] pub struct StrongNode(pub Content); @@ -529,11 +529,11 @@ impl Show for StrongNode { } fn realize(&self, _: &mut Context, _: StyleChain) -> TypResult { - Ok(self.0.clone().styled(TextNode::STRONG, Toggle)) + Ok(self.0.clone().styled(TextNode::BOLD, Toggle)) } } -/// Emphasized text, rendered with an italic face. +/// Emphasized text, rendered with an italic face by default. #[derive(Debug, Hash)] pub struct EmphNode(pub Content); @@ -554,6 +554,6 @@ impl Show for EmphNode { } fn realize(&self, _: &mut Context, _: StyleChain) -> TypResult { - Ok(self.0.clone().styled(TextNode::EMPH, Toggle)) + Ok(self.0.clone().styled(TextNode::ITALIC, Toggle)) } } diff --git a/src/library/text/raw.rs b/src/library/text/raw.rs index 9db9c4434..75964efe6 100644 --- a/src/library/text/raw.rs +++ b/src/library/text/raw.rs @@ -7,7 +7,7 @@ use syntect::highlighting::{ }; use syntect::parsing::SyntaxSet; -use super::{FontFamily, Hyphenate, TextNode, Toggle}; +use super::{FontFamily, Hyphenate, TextNode}; use crate::library::layout::BlockSpacing; use crate::library::prelude::*; use crate::source::SourceId; @@ -137,27 +137,26 @@ impl Show for RawNode { /// Style a piece of text with a syntect style. fn styled(piece: &str, foreground: Paint, style: Style) -> Content { - let mut styles = StyleMap::new(); let mut body = Content::Text(piece.into()); let paint = style.foreground.into(); if paint != foreground { - styles.set(TextNode::FILL, paint); + body = body.styled(TextNode::FILL, paint); } if style.font_style.contains(FontStyle::BOLD) { - styles.set(TextNode::STRONG, Toggle); + body = body.strong(); } if style.font_style.contains(FontStyle::ITALIC) { - styles.set(TextNode::EMPH, Toggle); + body = body.emph(); } if style.font_style.contains(FontStyle::UNDERLINE) { body = body.underlined(); } - body.styled_with_map(styles) + body } /// The lazily-loaded syntect syntax definitions. diff --git a/src/library/text/shaping.rs b/src/library/text/shaping.rs index 29973bc79..68499a013 100644 --- a/src/library/text/shaping.rs +++ b/src/library/text/shaping.rs @@ -517,11 +517,11 @@ pub fn variant(styles: StyleChain) -> FontVariant { styles.get(TextNode::STRETCH), ); - if styles.get(TextNode::STRONG) { + if styles.get(TextNode::BOLD) { variant.weight = variant.weight.thicken(300); } - if styles.get(TextNode::EMPH) { + if styles.get(TextNode::ITALIC) { variant.style = match variant.style { FontStyle::Normal => FontStyle::Italic, FontStyle::Italic => FontStyle::Normal, diff --git a/src/model/content.rs b/src/model/content.rs index 6956d3806..ff10de5d4 100644 --- a/src/model/content.rs +++ b/src/model/content.rs @@ -14,7 +14,9 @@ use crate::diag::StrResult; use crate::library::layout::{FlowChild, FlowNode, PageNode, PlaceNode, Spacing}; use crate::library::prelude::*; use crate::library::structure::{DocNode, ListItem, ListNode, ORDERED, UNORDERED}; -use crate::library::text::{DecoNode, ParChild, ParNode, UNDERLINE}; +use crate::library::text::{ + DecoNode, EmphNode, ParChild, ParNode, StrongNode, UNDERLINE, +}; use crate::util::EcoString; /// Composable representation of styled content. @@ -164,6 +166,16 @@ impl Content { self.clone().styled_with_entry(StyleEntry::Unguard(sel)) } + /// Make this content strong. + pub fn strong(self) -> Self { + Self::show(StrongNode(self)) + } + + /// Make this content emphasized. + pub fn emph(self) -> Self { + Self::show(EmphNode(self)) + } + /// Underline this content. pub fn underlined(self) -> Self { Self::show(DecoNode::(self)) diff --git a/tests/ref/structure/heading.png b/tests/ref/structure/heading.png index 7ad228ab3..96ffcb80a 100644 Binary files a/tests/ref/structure/heading.png and b/tests/ref/structure/heading.png differ diff --git a/tests/typ/structure/heading.typ b/tests/typ/structure/heading.typ index 496181bd0..d37d8796a 100644 --- a/tests/typ/structure/heading.typ +++ b/tests/typ/structure/heading.typ @@ -46,6 +46,8 @@ multiline. = Heading #set heading(family: "Roboto", fill: eastern) +#show it: heading as it.body +#show it: strong as it.body + [!] ===== Heading 🌍 #heading(level: 5)[Heading]