diff --git a/src/diag.rs b/src/diag.rs index 70a5bdaf8..329e9a8a9 100644 --- a/src/diag.rs +++ b/src/diag.rs @@ -108,3 +108,13 @@ impl Trace for TypResult { }) } } + +/// Transform `expected X, found Y` into `expected X or A, found Y`. +pub fn with_alternative(msg: String, alt: &str) -> String { + let mut parts = msg.split(", found "); + if let (Some(a), Some(b)) = (parts.next(), parts.next()) { + format!("{} or {}, found {}", a, alt, b) + } else { + msg + } +} diff --git a/src/eval/value.rs b/src/eval/value.rs index fffa729a9..2de210d57 100644 --- a/src/eval/value.rs +++ b/src/eval/value.rs @@ -531,7 +531,7 @@ impl Cast for Smart { } /// Transform `expected X, found Y` into `expected X or A, found Y`. -fn with_alternative(msg: String, alt: &str) -> String { +pub fn with_alternative(msg: String, alt: &str) -> String { let mut parts = msg.split(", found "); if let (Some(a), Some(b)) = (parts.next(), parts.next()) { format!("{} or {}, found {}", a, alt, b) diff --git a/src/library/heading.rs b/src/library/heading.rs index 2044355ed..dd78b1471 100644 --- a/src/library/heading.rs +++ b/src/library/heading.rs @@ -15,24 +15,25 @@ pub struct HeadingNode { #[class] impl HeadingNode { - /// The heading's font family. - pub const FAMILY: Smart = Smart::Auto; - /// The size of text in the heading. Just the surrounding text size if - /// `auto`. - pub const SIZE: Smart = Smart::Auto; - /// The fill color of text in the heading. Just the surrounding text color - /// if `auto`. - pub const FILL: Smart = Smart::Auto; + /// The heading's font family. Just the normal text family if `auto`. + pub const FAMILY: Leveled> = Leveled::Value(Smart::Auto); + /// The color of text in the heading. Just the normal text color if `auto`. + pub const FILL: Leveled> = Leveled::Value(Smart::Auto); + /// The size of text in the heading. + pub const SIZE: Leveled = Leveled::Mapping(|level| { + let upscale = (1.6 - 0.1 * level as f64).max(0.75); + Relative::new(upscale).into() + }); /// Whether text in the heading is strengthend. - pub const STRONG: bool = true; + pub const STRONG: Leveled = Leveled::Value(true); /// Whether text in the heading is emphasized. - pub const EMPH: bool = false; + pub const EMPH: Leveled = Leveled::Value(false); /// Whether the heading is underlined. - pub const UNDERLINE: bool = false; + pub const UNDERLINE: Leveled = Leveled::Value(false); /// The extra padding above the heading. - pub const ABOVE: Length = Length::zero(); + pub const ABOVE: Leveled = Leveled::Value(Length::zero()); /// The extra padding below the heading. - pub const BELOW: Length = Length::zero(); + pub const BELOW: Leveled = Leveled::Value(Length::zero()); fn construct(_: &mut Vm, args: &mut Args) -> TypResult