diff options
Diffstat (limited to 'src/library')
26 files changed, 144 insertions, 144 deletions
diff --git a/src/library/graphics/hide.rs b/src/library/graphics/hide.rs index 861a1208..21fc58c2 100644 --- a/src/library/graphics/hide.rs +++ b/src/library/graphics/hide.rs @@ -6,8 +6,8 @@ pub struct HideNode(pub LayoutNode); #[class] impl HideNode { - fn construct(_: &mut Context, args: &mut Args) -> TypResult<Template> { - Ok(Template::inline(Self(args.expect("body")?))) + fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> { + Ok(Content::inline(Self(args.expect("body")?))) } } diff --git a/src/library/graphics/image.rs b/src/library/graphics/image.rs index 66fb8f4b..faf89850 100644 --- a/src/library/graphics/image.rs +++ b/src/library/graphics/image.rs @@ -12,7 +12,7 @@ impl ImageNode { /// How the image should adjust itself to a given area. pub const FIT: ImageFit = ImageFit::Cover; - fn construct(ctx: &mut Context, args: &mut Args) -> TypResult<Template> { + fn construct(ctx: &mut Context, args: &mut Args) -> TypResult<Content> { let path = args.expect::<Spanned<EcoString>>("path to image file")?; let full = ctx.resolve(&path.v); let id = ctx.images.load(&full).map_err(|err| { @@ -25,7 +25,7 @@ impl ImageNode { let width = args.named("width")?; let height = args.named("height")?; - Ok(Template::inline( + Ok(Content::inline( ImageNode(id).pack().sized(Spec::new(width, height)), )) } diff --git a/src/library/graphics/shape.rs b/src/library/graphics/shape.rs index 8b967412..fbe21347 100644 --- a/src/library/graphics/shape.rs +++ b/src/library/graphics/shape.rs @@ -30,7 +30,7 @@ impl<const S: ShapeKind> ShapeNode<S> { /// How much to pad the shape's content. pub const PADDING: Linear = Linear::zero(); - fn construct(_: &mut Context, args: &mut Args) -> TypResult<Template> { + fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> { let size = match S { SQUARE => args.named::<Length>("size")?.map(Linear::from), CIRCLE => args.named::<Length>("radius")?.map(|r| 2.0 * Linear::from(r)), @@ -47,7 +47,7 @@ impl<const S: ShapeKind> ShapeNode<S> { size => size, }; - Ok(Template::inline( + Ok(Content::inline( Self(args.find()?).pack().sized(Spec::new(width, height)), )) } diff --git a/src/library/graphics/transform.rs b/src/library/graphics/transform.rs index fafb37a4..fcd7528d 100644 --- a/src/library/graphics/transform.rs +++ b/src/library/graphics/transform.rs @@ -24,7 +24,7 @@ impl<const T: TransformKind> TransformNode<T> { /// The origin of the transformation. pub const ORIGIN: Spec<Option<Align>> = Spec::default(); - fn construct(_: &mut Context, args: &mut Args) -> TypResult<Template> { + fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> { let transform = match T { MOVE => { let tx = args.named("x")?.unwrap_or_default(); @@ -43,7 +43,7 @@ impl<const T: TransformKind> TransformNode<T> { } }; - Ok(Template::inline(Self { + Ok(Content::inline(Self { transform, child: args.expect("body")?, })) diff --git a/src/library/layout/align.rs b/src/library/layout/align.rs index 7fbe0d01..2a969524 100644 --- a/src/library/layout/align.rs +++ b/src/library/layout/align.rs @@ -12,10 +12,10 @@ pub struct AlignNode { #[class] impl AlignNode { - fn construct(_: &mut Context, args: &mut Args) -> TypResult<Template> { + fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> { let aligns: Spec<_> = args.find()?.unwrap_or_default(); let body: LayoutNode = args.expect("body")?; - Ok(Template::block(body.aligned(aligns))) + Ok(Content::block(body.aligned(aligns))) } } diff --git a/src/library/layout/columns.rs b/src/library/layout/columns.rs index 167e7068..9e461108 100644 --- a/src/library/layout/columns.rs +++ b/src/library/layout/columns.rs @@ -16,8 +16,8 @@ impl ColumnsNode { /// The size of the gutter space between each column. pub const GUTTER: Linear = Relative::new(0.04).into(); - fn construct(_: &mut Context, args: &mut Args) -> TypResult<Template> { - Ok(Template::block(Self { + fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> { + Ok(Content::block(Self { columns: args.expect("column count")?, child: args.expect("body")?, })) @@ -105,7 +105,7 @@ pub struct ColbreakNode; #[class] impl ColbreakNode { - fn construct(_: &mut Context, _: &mut Args) -> TypResult<Template> { - Ok(Template::Colbreak) + fn construct(_: &mut Context, _: &mut Args) -> TypResult<Content> { + Ok(Content::Colbreak) } } diff --git a/src/library/layout/container.rs b/src/library/layout/container.rs index 55579878..f7f4017c 100644 --- a/src/library/layout/container.rs +++ b/src/library/layout/container.rs @@ -5,11 +5,11 @@ pub struct BoxNode; #[class] impl BoxNode { - fn construct(_: &mut Context, args: &mut Args) -> TypResult<Template> { + fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> { let width = args.named("width")?; let height = args.named("height")?; let body: LayoutNode = args.find()?.unwrap_or_default(); - Ok(Template::inline(body.sized(Spec::new(width, height)))) + Ok(Content::inline(body.sized(Spec::new(width, height)))) } } @@ -18,7 +18,7 @@ pub struct BlockNode; #[class] impl BlockNode { - fn construct(_: &mut Context, args: &mut Args) -> TypResult<Template> { - Ok(Template::Block(args.find()?.unwrap_or_default())) + fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> { + Ok(Content::Block(args.find()?.unwrap_or_default())) } } diff --git a/src/library/layout/grid.rs b/src/library/layout/grid.rs index 63cd83b1..90cf6da3 100644 --- a/src/library/layout/grid.rs +++ b/src/library/layout/grid.rs @@ -13,13 +13,13 @@ pub struct GridNode { #[class] impl GridNode { - fn construct(_: &mut Context, args: &mut Args) -> TypResult<Template> { + fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> { let columns = args.named("columns")?.unwrap_or_default(); let rows = args.named("rows")?.unwrap_or_default(); let base_gutter: Vec<TrackSizing> = args.named("gutter")?.unwrap_or_default(); let column_gutter = args.named("column-gutter")?; let row_gutter = args.named("row-gutter")?; - Ok(Template::block(Self { + Ok(Content::block(Self { tracks: Spec::new(columns, rows), gutter: Spec::new( column_gutter.unwrap_or_else(|| base_gutter.clone()), diff --git a/src/library/layout/pad.rs b/src/library/layout/pad.rs index 175a54f0..835beef9 100644 --- a/src/library/layout/pad.rs +++ b/src/library/layout/pad.rs @@ -11,7 +11,7 @@ pub struct PadNode { #[class] impl PadNode { - fn construct(_: &mut Context, args: &mut Args) -> TypResult<Template> { + fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> { let all = args.find()?; let hor = args.named("horizontal")?; let ver = args.named("vertical")?; @@ -21,7 +21,7 @@ impl PadNode { let bottom = args.named("bottom")?.or(ver).or(all).unwrap_or_default(); let body: LayoutNode = args.expect("body")?; let padding = Sides::new(left, top, right, bottom); - Ok(Template::block(body.padded(padding))) + Ok(Content::block(body.padded(padding))) } } diff --git a/src/library/layout/page.rs b/src/library/layout/page.rs index 4b6d68c5..def2940e 100644 --- a/src/library/layout/page.rs +++ b/src/library/layout/page.rs @@ -32,8 +32,8 @@ impl PageNode { /// The page's footer. pub const FOOTER: Marginal = Marginal::None; - fn construct(_: &mut Context, args: &mut Args) -> TypResult<Template> { - Ok(Template::Page(Self(args.expect("body")?))) + fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> { + Ok(Content::Page(Self(args.expect("body")?))) } fn set(args: &mut Args, styles: &mut StyleMap) -> TypResult<()> { @@ -125,12 +125,12 @@ impl PageNode { (Length::zero(), padding.top, header), (size.y - padding.bottom, padding.bottom, footer), ] { - if let Some(template) = marginal.resolve(ctx, page)? { + if let Some(content) = marginal.resolve(ctx, page)? { let pos = Point::new(padding.left, y); let w = size.x - padding.left - padding.right; let area = Size::new(w, h); let pod = Regions::one(area, area, area.map(Length::is_finite)); - let sub = Layout::layout(&template, ctx, &pod, styles)?.remove(0); + let sub = Layout::layout(&content, ctx, &pod, styles)?.remove(0); Arc::make_mut(frame).push_frame(pos, sub); } } @@ -155,8 +155,8 @@ pub struct PagebreakNode; #[class] impl PagebreakNode { - fn construct(_: &mut Context, _: &mut Args) -> TypResult<Template> { - Ok(Template::Pagebreak) + fn construct(_: &mut Context, _: &mut Args) -> TypResult<Content> { + Ok(Content::Pagebreak) } } @@ -165,18 +165,18 @@ impl PagebreakNode { pub enum Marginal { /// Nothing, None, - /// A bare template. - Template(Template), - /// A closure mapping from a page number to a template. + /// Bare content. + Content(Content), + /// A closure mapping from a page number to content. Func(Func, Span), } impl Marginal { /// Resolve the marginal based on the page number. - pub fn resolve(&self, ctx: &mut Context, page: usize) -> TypResult<Option<Template>> { + pub fn resolve(&self, ctx: &mut Context, page: usize) -> TypResult<Option<Content>> { Ok(match self { Self::None => None, - Self::Template(template) => Some(template.clone()), + Self::Content(content) => Some(content.clone()), Self::Func(func, span) => { let args = Args::from_values(*span, [Value::Int(page as i64)]); func.call(ctx, args)?.cast().at(*span)? @@ -187,15 +187,15 @@ impl Marginal { impl Cast<Spanned<Value>> for Marginal { fn is(value: &Spanned<Value>) -> bool { - matches!(&value.v, Value::Template(_) | Value::Func(_)) + matches!(&value.v, Value::Content(_) | Value::Func(_)) } fn cast(value: Spanned<Value>) -> StrResult<Self> { match value.v { Value::None => Ok(Self::None), - Value::Template(v) => Ok(Self::Template(v)), + Value::Content(v) => Ok(Self::Content(v)), Value::Func(v) => Ok(Self::Func(v, value.span)), - _ => Err("expected none, template or function")?, + _ => Err("expected none, content or function")?, } } } diff --git a/src/library/layout/place.rs b/src/library/layout/place.rs index d65b3836..99ff5292 100644 --- a/src/library/layout/place.rs +++ b/src/library/layout/place.rs @@ -7,12 +7,12 @@ pub struct PlaceNode(pub LayoutNode); #[class] impl PlaceNode { - fn construct(_: &mut Context, args: &mut Args) -> TypResult<Template> { + fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> { let aligns = args.find()?.unwrap_or(Spec::with_x(Some(Align::Left))); let tx = args.named("dx")?.unwrap_or_default(); let ty = args.named("dy")?.unwrap_or_default(); let body: LayoutNode = args.expect("body")?; - Ok(Template::block(Self( + Ok(Content::block(Self( body.moved(Point::new(tx, ty)).aligned(aligns), ))) } diff --git a/src/library/layout/spacing.rs b/src/library/layout/spacing.rs index 3bebfb14..9a27a8b2 100644 --- a/src/library/layout/spacing.rs +++ b/src/library/layout/spacing.rs @@ -5,8 +5,8 @@ pub struct HNode; #[class] impl HNode { - fn construct(_: &mut Context, args: &mut Args) -> TypResult<Template> { - Ok(Template::Horizontal(args.expect("spacing")?)) + fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> { + Ok(Content::Horizontal(args.expect("spacing")?)) } } @@ -15,8 +15,8 @@ pub struct VNode; #[class] impl VNode { - fn construct(_: &mut Context, args: &mut Args) -> TypResult<Template> { - Ok(Template::Vertical(args.expect("spacing")?)) + fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> { + Ok(Content::Vertical(args.expect("spacing")?)) } } diff --git a/src/library/layout/stack.rs b/src/library/layout/stack.rs index 414490ef..88e27116 100644 --- a/src/library/layout/stack.rs +++ b/src/library/layout/stack.rs @@ -14,8 +14,8 @@ pub struct StackNode { #[class] impl StackNode { - fn construct(_: &mut Context, args: &mut Args) -> TypResult<Template> { - Ok(Template::block(Self { + fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> { + Ok(Content::block(Self { dir: args.named("dir")?.unwrap_or(Dir::TTB), spacing: args.named("spacing")?, children: args.all()?, @@ -76,12 +76,12 @@ impl Debug for StackChild { castable! { StackChild, - Expected: "linear, fractional or template", + Expected: "linear, fractional or content", Value::Length(v) => Self::Spacing(SpacingKind::Linear(v.into())), Value::Relative(v) => Self::Spacing(SpacingKind::Linear(v.into())), Value::Linear(v) => Self::Spacing(SpacingKind::Linear(v)), Value::Fractional(v) => Self::Spacing(SpacingKind::Fractional(v)), - Value::Template(v) => Self::Node(v.pack()), + Value::Content(v) => Self::Node(v.pack()), } /// Performs stack layout. diff --git a/src/library/math/mod.rs b/src/library/math/mod.rs index c5b79117..b43db22e 100644 --- a/src/library/math/mod.rs +++ b/src/library/math/mod.rs @@ -13,8 +13,8 @@ pub struct MathNode { #[class] impl MathNode { - fn construct(_: &mut Context, args: &mut Args) -> TypResult<Template> { - Ok(Template::show(Self { + fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> { + Ok(Content::show(Self { formula: args.expect("formula")?, display: args.named("display")?.unwrap_or(false), })) @@ -22,18 +22,18 @@ impl MathNode { } impl Show for MathNode { - fn show(&self, ctx: &mut Context, styles: StyleChain) -> TypResult<Template> { + fn show(&self, ctx: &mut Context, styles: StyleChain) -> TypResult<Content> { Ok(styles .show(self, ctx, [ Value::Str(self.formula.clone()), Value::Bool(self.display), ])? .unwrap_or_else(|| { - let mut template = Template::Text(self.formula.trim().into()); + let mut content = Content::Text(self.formula.trim().into()); if self.display { - template = Template::Block(template.pack()); + content = Content::Block(content.pack()); } - template.monospaced() + content.monospaced() })) } } diff --git a/src/library/mod.rs b/src/library/mod.rs index ceb5a557..b2e4e408 100644 --- a/src/library/mod.rs +++ b/src/library/mod.rs @@ -167,6 +167,6 @@ castable! { castable! { LayoutNode, - Expected: "template", - Value::Template(template) => template.pack(), + Expected: "content", + Value::Content(content) => content.pack(), } diff --git a/src/library/prelude.rs b/src/library/prelude.rs index 4d13a655..0cca718f 100644 --- a/src/library/prelude.rs +++ b/src/library/prelude.rs @@ -9,8 +9,8 @@ pub use typst_macros::class; pub use crate::diag::{with_alternative, At, StrResult, TypResult}; pub use crate::eval::{ - Arg, Args, Array, Cast, Construct, Dict, Func, Layout, LayoutNode, Merge, Property, - Regions, Scope, Set, Show, ShowNode, Smart, StyleChain, StyleMap, StyleVec, Template, + Arg, Args, Array, Cast, Construct, Content, Dict, Func, Layout, LayoutNode, Merge, + Property, Regions, Scope, Set, Show, ShowNode, Smart, StyleChain, StyleMap, StyleVec, Value, }; pub use crate::frame::*; diff --git a/src/library/structure/heading.rs b/src/library/structure/heading.rs index a67f4f24..f5565f3c 100644 --- a/src/library/structure/heading.rs +++ b/src/library/structure/heading.rs @@ -8,7 +8,7 @@ pub struct HeadingNode { /// default style, this controls the text size of the heading. pub level: usize, /// The heading's contents. - pub body: Template, + pub body: Content, } #[class] @@ -35,8 +35,8 @@ impl HeadingNode { /// Whether the heading is block-level. pub const BLOCK: Leveled<bool> = Leveled::Value(true); - fn construct(_: &mut Context, args: &mut Args) -> TypResult<Template> { - Ok(Template::show(Self { + fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> { + Ok(Content::show(Self { body: args.expect("body")?, level: args.named("level")?.unwrap_or(1), })) @@ -44,7 +44,7 @@ impl HeadingNode { } impl Show for HeadingNode { - fn show(&self, ctx: &mut Context, styles: StyleChain) -> TypResult<Template> { + fn show(&self, ctx: &mut Context, styles: StyleChain) -> TypResult<Content> { macro_rules! resolve { ($key:expr) => { styles.get_cloned($key).resolve(ctx, self.level)? @@ -55,7 +55,7 @@ impl Show for HeadingNode { let mut body = styles .show(self, ctx, [ Value::Int(self.level as i64), - Value::Template(self.body.clone()), + Value::Content(self.body.clone()), ])? .unwrap_or_else(|| self.body.clone()); @@ -90,22 +90,22 @@ impl Show for HeadingNode { let above = resolve!(Self::ABOVE); if !above.is_zero() { - seq.push(Template::Vertical(above.into())); + seq.push(Content::Vertical(above.into())); } seq.push(body); let below = resolve!(Self::BELOW); if !below.is_zero() { - seq.push(Template::Vertical(below.into())); + seq.push(Content::Vertical(below.into())); } - let mut template = Template::sequence(seq).styled_with_map(map); + let mut content = Content::sequence(seq).styled_with_map(map); if resolve!(Self::BLOCK) { - template = Template::block(template); + content = Content::block(content); } - Ok(template) + Ok(content) } } diff --git a/src/library/structure/list.rs b/src/library/structure/list.rs index 2c536e2a..2630d231 100644 --- a/src/library/structure/list.rs +++ b/src/library/structure/list.rs @@ -22,7 +22,7 @@ pub struct ListItem { /// The number of the item. pub number: Option<usize>, /// The node that produces the item's body. - pub body: Box<Template>, + pub body: Box<Content>, } /// An ordered list. @@ -43,8 +43,8 @@ impl<const L: ListKind> ListNode<L> { /// The extra padding below the list. pub const BELOW: Length = Length::zero(); - fn construct(_: &mut Context, args: &mut Args) -> TypResult<Template> { - Ok(Template::show(Self { + fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> { + Ok(Content::show(Self { start: args.named("start")?.unwrap_or(0), wide: args.named("wide")?.unwrap_or(false), items: args @@ -57,13 +57,13 @@ impl<const L: ListKind> ListNode<L> { } impl<const L: ListKind> Show for ListNode<L> { - fn show(&self, ctx: &mut Context, styles: StyleChain) -> TypResult<Template> { - let template = if let Some(template) = styles.show( + fn show(&self, ctx: &mut Context, styles: StyleChain) -> TypResult<Content> { + let content = if let Some(content) = styles.show( self, ctx, - self.items.iter().map(|item| Value::Template((*item.body).clone())), + self.items.iter().map(|item| Value::Content((*item.body).clone())), )? { - template + content } else { let mut children = vec![]; let mut number = self.start; @@ -91,7 +91,7 @@ impl<const L: ListKind> Show for ListNode<L> { let indent = styles.get(Self::INDENT).resolve(em); let body_indent = styles.get(Self::BODY_INDENT).resolve(em); - Template::block(GridNode { + Content::block(GridNode { tracks: Spec::with_x(vec![ TrackSizing::Linear(indent.into()), TrackSizing::Auto, @@ -106,17 +106,17 @@ impl<const L: ListKind> Show for ListNode<L> { let mut seq = vec![]; let above = styles.get(Self::ABOVE); if !above.is_zero() { - seq.push(Template::Vertical(above.into())); + seq.push(Content::Vertical(above.into())); } - seq.push(template); + seq.push(content); let below = styles.get(Self::BELOW); if !below.is_zero() { - seq.push(Template::Vertical(below.into())); + seq.push(Content::Vertical(below.into())); } - Ok(Template::sequence(seq)) + Ok(Content::sequence(seq)) } } @@ -135,15 +135,15 @@ pub const UNORDERED: ListKind = 0; /// Ordered list labelling style. pub const ORDERED: ListKind = 1; -/// Either a template or a closure mapping to a template. +/// Either content or a closure mapping to content. #[derive(Debug, Clone, PartialEq, Hash)] pub enum Label { /// The default labelling. Default, /// A pattern with prefix, numbering, lower / upper case and suffix. Pattern(EcoString, Numbering, bool, EcoString), - /// A bare template. - Template(Template), + /// Bare content. + Content(Content), /// A closure mapping from an item number to a value. Func(Func, Span), } @@ -155,18 +155,18 @@ impl Label { ctx: &mut Context, kind: ListKind, number: usize, - ) -> TypResult<Template> { + ) -> TypResult<Content> { Ok(match self { Self::Default => match kind { - UNORDERED => Template::Text('•'.into()), - ORDERED | _ => Template::Text(format_eco!("{}.", number)), + UNORDERED => Content::Text('•'.into()), + ORDERED | _ => Content::Text(format_eco!("{}.", number)), }, Self::Pattern(prefix, numbering, upper, suffix) => { let fmt = numbering.apply(number); let mid = if *upper { fmt.to_uppercase() } else { fmt.to_lowercase() }; - Template::Text(format_eco!("{}{}{}", prefix, mid, suffix)) + Content::Text(format_eco!("{}{}{}", prefix, mid, suffix)) } - Self::Template(template) => template.clone(), + Self::Content(content) => content.clone(), Self::Func(func, span) => { let args = Args::from_values(*span, [Value::Int(number as i64)]); func.call(ctx, args)?.cast().at(*span)? @@ -177,7 +177,7 @@ impl Label { impl Cast<Spanned<Value>> for Label { fn is(value: &Spanned<Value>) -> bool { - matches!(&value.v, Value::Template(_) | Value::Func(_)) + matches!(&value.v, Value::Content(_) | Value::Func(_)) } fn cast(value: Spanned<Value>) -> StrResult<Self> { @@ -200,9 +200,9 @@ impl Cast<Spanned<Value>> for Label { let suffix = s.rest().into(); Ok(Self::Pattern(prefix.into(), numbering, upper, suffix)) } - Value::Template(v) => Ok(Self::Template(v)), + Value::Content(v) => Ok(Self::Content(v)), Value::Func(v) => Ok(Self::Func(v, value.span)), - _ => Err("expected pattern, template or function")?, + _ => Err("expected pattern, content or function")?, } } } diff --git a/src/library/structure/table.rs b/src/library/structure/table.rs index 555dcc44..42b62eac 100644 --- a/src/library/structure/table.rs +++ b/src/library/structure/table.rs @@ -9,7 +9,7 @@ pub struct TableNode { /// Defines sizing of gutter rows and columns between content. pub gutter: Spec<Vec<TrackSizing>>, /// The nodes to be arranged in the table. - pub children: Vec<Template>, + pub children: Vec<Content>, } #[class] @@ -25,13 +25,13 @@ impl TableNode { /// How much to pad the cells's content. pub const PADDING: Linear = Length::pt(5.0).into(); - fn construct(_: &mut Context, args: &mut Args) -> TypResult<Template> { + fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> { let columns = args.named("columns")?.unwrap_or_default(); let rows = args.named("rows")?.unwrap_or_default(); let base_gutter: Vec<TrackSizing> = args.named("gutter")?.unwrap_or_default(); let column_gutter = args.named("column-gutter")?; let row_gutter = args.named("row-gutter")?; - Ok(Template::show(Self { + Ok(Content::show(Self { tracks: Spec::new(columns, rows), gutter: Spec::new( column_gutter.unwrap_or_else(|| base_gutter.clone()), @@ -53,13 +53,13 @@ impl TableNode { } impl Show for TableNode { - fn show(&self, ctx: &mut Context, styles: StyleChain) -> TypResult<Template> { - if let Some(template) = styles.show( + fn show(&self, ctx: &mut Context, styles: StyleChain) -> TypResult<Content> { + if let Some(content) = styles.show( self, ctx, - self.children.iter().map(|child| Value::Template(child.clone())), + self.children.iter().map(|child| Value::Content(child.clone())), )? { - return Ok(template); + return Ok(content); } let primary = styles.get(Self::PRIMARY); @@ -91,7 +91,7 @@ impl Show for TableNode { }) .collect(); - Ok(Template::block(GridNode { + Ok(Content::block(GridNode { tracks: self.tracks.clone(), gutter: self.gutter.clone(), children, diff --git a/src/library/text/deco.rs b/src/library/text/deco.rs index a288c995..608ebb18 100644 --- a/src/library/text/deco.rs +++ b/src/library/text/deco.rs @@ -7,7 +7,7 @@ use crate::library::prelude::*; /// Typeset underline, stricken-through or overlined text. #[derive(Debug, Hash)] -pub struct DecoNode<const L: DecoLine>(pub Template); +pub struct DecoNode<const L: DecoLine>(pub Content); /// Typeset underlined text. pub type UnderlineNode = DecoNode<UNDERLINE>; @@ -37,15 +37,15 @@ impl<const L: DecoLine> DecoNode<L> { /// with the glyphs. Does not apply to strikethrough. pub const EVADE: bool = true; - fn construct(_: &mut Context, args: &mut Args) -> TypResult<Template> { - Ok(Template::show(Self(args.expect::<Template>("body")?))) + fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> { + Ok(Content::show(Self(args.expect::<Content>("body")?))) } } impl<const L: DecoLine> Show for DecoNode<L> { - fn show(&self, ctx: &mut Context, styles: StyleChain) -> TypResult<Template> { + fn show(&self, ctx: &mut Context, styles: StyleChain) -> TypResult<Content> { Ok(styles - .show(self, ctx, [Value::Template(self.0.clone())])? + .show(self, ctx, [Value::Content(self.0.clone())])? .unwrap_or_else(|| { self.0.clone().styled(TextNode::LINES, vec![Decoration { line: L, diff --git a/src/library/text/link.rs b/src/library/text/link.rs index 29f41927..e0041df5 100644 --- a/src/library/text/link.rs +++ b/src/library/text/link.rs @@ -8,7 +8,7 @@ pub struct LinkNode { /// The url the link points to. pub url: EcoString, /// How the link is represented. - pub body: Option<Template>, + pub body: Option<Content>, } #[class] @@ -19,8 +19,8 @@ impl LinkNode { /// Whether to underline link. pub const UNDERLINE: bool = true; - fn construct(_: &mut Context, args: &mut Args) -> TypResult<Template> { - Ok(Template::show(Self { + fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> { + Ok(Content::show(Self { url: args.expect::<EcoString>("url")?, body: args.find()?, })) @@ -28,12 +28,12 @@ impl LinkNode { } impl Show for LinkNode { - fn show(&self, ctx: &mut Context, styles: StyleChain) -> TypResult<Template> { + fn show(&self, ctx: &mut Context, styles: StyleChain) -> TypResult<Content> { let mut body = styles .show(self, ctx, [ Value::Str(self.url.clone()), match &self.body { - Some(body) => Value::Template(body.clone()), + Some(body) => Value::Content(body.clone()), None => Value::None, }, ])? @@ -45,7 +45,7 @@ impl Show for LinkNode { text = text.trim_start_matches(prefix); } let shorter = text.len() < url.len(); - Template::Text(if shorter { text.into() } else { url.clone() }) + Content::Text(if shorter { text.into() } else { url.clone() }) }); let mut map = StyleMap::new(); diff --git a/src/library/text/mod.rs b/src/library/text/mod.rs index 197971d0..dbc486fb 100644 --- a/src/library/text/mod.rs +++ b/src/library/text/mod.rs @@ -110,7 +110,7 @@ impl TextNode { #[skip] pub const LINK: Option<EcoString> = None; - fn construct(_: &mut Context, args: &mut Args) -> TypResult<Template> { + fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> { // The text constructor is special: It doesn't create a text node. // Instead, it leaves the passed argument structurally unchanged, but // styles all text in it. @@ -120,38 +120,38 @@ impl TextNode { /// Strong text, rendered in boldface. #[derive(Debug, Hash)] -pub struct StrongNode(pub Template); +pub struct StrongNode(pub Content); #[class] impl StrongNode { - fn construct(_: &mut Context, args: &mut Args) -> TypResult<Template> { - Ok(Template::show(Self(args.expect("body")?))) + fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> { + Ok(Content::show(Self(args.expect("body")?))) } } impl Show for StrongNode { - fn show(&self, ctx: &mut Context, styles: StyleChain) -> TypResult<Template> { + fn show(&self, ctx: &mut Context, styles: StyleChain) -> TypResult<Content> { Ok(styles - .show(self, ctx, [Value::Template(self.0.clone())])? + .show(self, ctx, [Value::Content(self.0.clone())])? .unwrap_or_else(|| self.0.clone().styled(TextNode::STRONG, true))) } } /// Emphasized text, rendered with an italic face. #[derive(Debug, Hash)] -pub struct EmphNode(pub Template); +pub struct EmphNode(pub Content); #[class] impl EmphNode { - fn construct(_: &mut Context, args: &mut Args) -> TypResult<Template> { - Ok(Template::show(Self(args.expect("body")?))) + fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> { + Ok(Content::show(Self(args.expect("body")?))) } } impl Show for EmphNode { - fn show(&self, ctx: &mut Context, styles: StyleChain) -> TypResult<Template> { + fn show(&self, ctx: &mut Context, styles: StyleChain) -> TypResult<Content> { Ok(styles - .show(self, ctx, [Value::Template(self.0.clone())])? + .show(self, ctx, [Value::Content(self.0.clone())])? .unwrap_or_else(|| self.0.clone().styled(TextNode::EMPH, true))) } } diff --git a/src/library/text/par.rs b/src/library/text/par.rs index 70cac1be..dc888637 100644 --- a/src/library/text/par.rs +++ b/src/library/text/par.rs @@ -45,12 +45,12 @@ impl ParNode { /// The indent the first line of a consecutive paragraph should have. pub const INDENT: Linear = Linear::zero(); - fn construct(_: &mut Context, args: &mut Args) -> TypResult<Template> { + fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> { // The paragraph constructor is special: It doesn't create a paragraph // since that happens automatically through markup. Instead, it just // lifts the passed body to the block level so that it won't merge with // adjacent stuff and it styles the contained paragraphs. - Ok(Template::Block(args.expect("body")?)) + Ok(Content::Block(args.expect("body")?)) } fn set(args: &mut Args, styles: &mut StyleMap) -> TypResult<()> { @@ -185,8 +185,8 @@ pub struct ParbreakNode; #[class] impl ParbreakNode { - fn construct(_: &mut Context, _: &mut Args) -> TypResult<Template> { - Ok(Template::Parbreak) + fn construct(_: &mut Context, _: &mut Args) -> TypResult<Content> { + Ok(Content::Parbreak) } } @@ -195,8 +195,8 @@ pub struct LinebreakNode; #[class] impl LinebreakNode { - fn construct(_: &mut Context, _: &mut Args) -> TypResult<Template> { - Ok(Template::Linebreak) + fn construct(_: &mut Context, _: &mut Args) -> TypResult<Content> { + Ok(Content::Linebreak) } } diff --git a/src/library/text/raw.rs b/src/library/text/raw.rs index 97857f11..988bd04e 100644 --- a/src/library/text/raw.rs +++ b/src/library/text/raw.rs @@ -29,8 +29,8 @@ impl RawNode { /// The language to syntax-highlight in. pub const LANG: Option<EcoString> = None; - fn construct(_: &mut Context, args: &mut Args) -> TypResult<Template> { - Ok(Template::show(Self { + fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> { + Ok(Content::show(Self { text: args.expect("text")?, block: args.named("block")?.unwrap_or(false), })) @@ -38,10 +38,10 @@ impl RawNode { } impl Show for RawNode { - fn show(&self, ctx: &mut Context, styles: StyleChain) -> TypResult<Template> { + fn show(&self, ctx: &mut Context, styles: StyleChain) -> TypResult<Content> { let lang = styles.get_ref(Self::LANG).as_ref(); - if let Some(template) = styles.show(self, ctx, [ + if let Some(content) = styles.show(self, ctx, [ Value::Str(self.text.clone()), match lang { Some(lang) => Value::Str(lang.clone()), @@ -49,7 +49,7 @@ impl Show for RawNode { }, Value::Bool(self.block), ])? { - return Ok(template); + return Ok(content); } let foreground = THEME @@ -59,7 +59,7 @@ impl Show for RawNode { .unwrap_or(Color::BLACK) .into(); - let mut template = if matches!( + let mut content = if matches!( lang.map(|s| s.to_lowercase()).as_deref(), Some("typ" | "typst") ) { @@ -72,7 +72,7 @@ impl Show for RawNode { seq.push(styled(&self.text[range], foreground, style)); }); - Template::sequence(seq) + Content::sequence(seq) } else if let Some(syntax) = lang.and_then(|token| SYNTAXES.find_syntax_by_token(&token)) { @@ -80,7 +80,7 @@ impl Show for RawNode { let mut highlighter = HighlightLines::new(syntax, &THEME); for (i, line) in self.text.lines().enumerate() { if i != 0 { - seq.push(Template::Linebreak); + seq.push(Content::Linebreak); } for (style, piece) in highlighter.highlight(line, &SYNTAXES) { @@ -88,23 +88,23 @@ impl Show for RawNode { } } - Template::sequence(seq) + Content::sequence(seq) } else { - Template::Text(self.text.clone()) + Content::Text(self.text.clone()) }; if self.block { - template = Template::Block(template.pack()); + content = Content::Block(content.pack()); } - Ok(template.monospaced()) + Ok(content.monospaced()) } } /// Style a piece of text with a syntect style. -fn styled(piece: &str, foreground: Paint, style: Style) -> Template { +fn styled(piece: &str, foreground: Paint, style: Style) -> Content { let mut styles = StyleMap::new(); - let mut body = Template::Text(piece.into()); + let mut body = Content::Text(piece.into()); let paint = style.foreground.into(); if paint != foreground { diff --git a/src/library/utility/math.rs b/src/library/utility/math.rs index 795f39fd..9389b4b9 100644 --- a/src/library/utility/math.rs +++ b/src/library/utility/math.rs @@ -39,7 +39,7 @@ fn minmax(args: &mut Args, goal: Ordering) -> TypResult<Value> { } None => bail!( span, - "cannot compare {} with {}", + "cannot compare {} and {}", extremum.type_name(), v.type_name(), ), diff --git a/src/library/utility/mod.rs b/src/library/utility/mod.rs index 886cdc13..d85c3f12 100644 --- a/src/library/utility/mod.rs +++ b/src/library/utility/mod.rs @@ -170,13 +170,13 @@ pub fn upper(_: &mut Context, args: &mut Args) -> TypResult<Value> { case(Case::Upper, args) } -/// Change the case of a string or template. +/// Change the case of a string or content. fn case(case: Case, args: &mut Args) -> TypResult<Value> { - let Spanned { v, span } = args.expect("string or template")?; + let Spanned { v, span } = args.expect("string or content")?; Ok(match v { Value::Str(v) => Value::Str(case.apply(&v).into()), - Value::Template(v) => Value::Template(v.styled(TextNode::CASE, Some(case))), - v => bail!(span, "expected string or template, found {}", v.type_name()), + Value::Content(v) => Value::Content(v.styled(TextNode::CASE, Some(case))), + v => bail!(span, "expected string or content, found {}", v.type_name()), }) } |
