Streamline field names

This commit is contained in:
Laurenz 2023-03-08 10:54:04 +01:00
parent 1b2b53ecb9
commit e5eab73374
30 changed files with 102 additions and 74 deletions

View File

@ -5,7 +5,6 @@ authors = ["The Typst Project Developers"]
edition = "2021" edition = "2021"
[lib] [lib]
test = false
doctest = false doctest = false
bench = false bench = false

View File

@ -309,7 +309,10 @@ fn code_block(resolver: &dyn Resolver, lang: &str, text: &str) -> Html {
let world = DocWorld(source); let world = DocWorld(source);
let mut frames = match typst::compile(&world, &world.0) { let mut frames = match typst::compile(&world, &world.0) {
Ok(doc) => doc.pages, Ok(doc) => doc.pages,
Err(err) => panic!("failed to compile {text}: {err:?}"), Err(err) => {
let msg = &err[0].message;
panic!("while trying to compile {text}:\n\nerror: {msg}");
}
}; };
if let Some([x, y, w, h]) = zoom { if let Some([x, y, w, h]) = zoom {

View File

@ -745,3 +745,29 @@ const TYPE_ORDER: &[&str] = &[
"selector", "selector",
"stroke", "stroke",
]; ];
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_docs() {
provide(&TestResolver);
}
struct TestResolver;
impl Resolver for TestResolver {
fn link(&self, _: &str) -> Option<String> {
None
}
fn example(&self, _: Html, _: &[Frame]) -> Html {
Html::new(String::new())
}
fn image(&self, _: &str, _: &[u8]) -> String {
String::new()
}
}
}

View File

@ -85,8 +85,8 @@ fantasy encyclopedia.
#set heading(numbering: "(I)") #set heading(numbering: "(I)")
#show heading: it => block[ #show heading: it => block[
#set align(center) #set align(center)
\~ _#it.title;_
#set text(font: "Inria Serif") #set text(font: "Inria Serif")
\~ _#it.body;_
#it.numbers \~ #it.numbers \~
] ]

View File

@ -359,7 +359,7 @@ a way to set any of that, we need to write our own heading show rule.
#show heading: it => block[ #show heading: it => block[
#set align(center) #set align(center)
#set text(12pt, weight: "regular") #set text(12pt, weight: "regular")
#smallcaps(it.title) #smallcaps(it.body)
] ]
<<< ... <<< ...
@ -441,7 +441,7 @@ differentiate between section and subsection headings:
): it => block[ ): it => block[
#set align(center) #set align(center)
#set text(12pt, weight: "regular") #set text(12pt, weight: "regular")
#smallcaps(it.title) #smallcaps(it.body)
] ]
#show heading.where( #show heading.where(
@ -450,7 +450,7 @@ differentiate between section and subsection headings:
size: 11pt, size: 11pt,
weight: "regular", weight: "regular",
style: "italic", style: "italic",
it.title + [.], it.body + [.],
) )
>>> >>>
>>> #align(center, text( >>> #align(center, text(

View File

@ -107,7 +107,7 @@ previous chapter.
>>> text( >>> text(
>>> 13pt, >>> 13pt,
>>> weight: "regular", >>> weight: "regular",
>>> smallcaps(it.title), >>> smallcaps(it.body),
>>> ) >>> )
>>> ), >>> ),
>>> ) >>> )
@ -118,7 +118,7 @@ previous chapter.
>>> 11pt, >>> 11pt,
>>> weight: "regular", >>> weight: "regular",
>>> style: "italic", >>> style: "italic",
>>> it.title + [.], >>> it.body + [.],
>>> ) >>> )
>>> ) >>> )
@ -288,7 +288,7 @@ path of the file after the `{from}` keyword.
>>> text( >>> text(
>>> 13pt, >>> 13pt,
>>> weight: "regular", >>> weight: "regular",
>>> smallcaps(it.title), >>> smallcaps(it.body),
>>> ) >>> )
>>> ), >>> ),
>>> ) >>> )
@ -299,7 +299,7 @@ path of the file after the `{from}` keyword.
>>> 11pt, >>> 11pt,
>>> weight: "regular", >>> weight: "regular",
>>> style: "italic", >>> style: "italic",
>>> it.title + [.], >>> it.body + [.],
>>> ) >>> )
>>> ) >>> )
>>> >>>

View File

@ -20,11 +20,6 @@ use crate::prelude::*;
styles.set(Self::ALIGNMENT, aligns); styles.set(Self::ALIGNMENT, aligns);
})] })]
pub struct AlignNode { pub struct AlignNode {
/// The content to align.
#[positional]
#[required]
pub body: Content,
/// The alignment along both axes. /// The alignment along both axes.
/// ///
/// Possible values for horizontal alignments are: /// Possible values for horizontal alignments are:
@ -62,6 +57,11 @@ pub struct AlignNode {
#[skip] #[skip]
#[default(Axes::new(GenAlign::Start, GenAlign::Specific(Align::Top)))] #[default(Axes::new(GenAlign::Start, GenAlign::Specific(Align::Top)))]
pub alignment: Axes<Option<GenAlign>>, pub alignment: Axes<Option<GenAlign>>,
/// The content to align.
#[positional]
#[required]
pub body: Content,
} }
impl Show for AlignNode { impl Show for AlignNode {

View File

@ -26,7 +26,7 @@ pub struct BoxNode {
/// The contents of the box. /// The contents of the box.
#[positional] #[positional]
#[default] #[default]
pub body: Content, pub body: Option<Content>,
/// The width of the box. /// The width of the box.
/// ///
@ -133,16 +133,16 @@ impl Layout for BoxNode {
.unwrap_or(regions.base()); .unwrap_or(regions.base());
// Apply inset. // Apply inset.
let mut child = self.body(); let mut body = self.body().unwrap_or_default();
let inset = styles.get(Self::INSET); let inset = styles.get(Self::INSET);
if inset.iter().any(|v| !v.is_zero()) { if inset.iter().any(|v| !v.is_zero()) {
child = child.padded(inset.map(|side| side.map(Length::from))); body = body.padded(inset.map(|side| side.map(Length::from)));
} }
// Select the appropriate base and expansion for the child depending // Select the appropriate base and expansion for the child depending
// on whether it is automatically or relatively sized. // on whether it is automatically or relatively sized.
let pod = Regions::one(size, expand); let pod = Regions::one(size, expand);
let mut frame = child.layout(vt, styles, pod)?.into_frame(); let mut frame = body.layout(vt, styles, pod)?.into_frame();
// Apply baseline shift. // Apply baseline shift.
let shift = styles.get(Self::BASELINE).relative_to(frame.height()); let shift = styles.get(Self::BASELINE).relative_to(frame.height());
@ -191,11 +191,11 @@ impl Layout for BoxNode {
/// Blocks are also useful to force elements that would otherwise be inline to /// Blocks are also useful to force elements that would otherwise be inline to
/// become block-level, especially when writing show rules. /// become block-level, especially when writing show rules.
/// ```example /// ```example
/// #show heading: it => it.title /// #show heading: it => it.body
/// = Blockless /// = Blockless
/// More text. /// More text.
/// ///
/// #show heading: it => block(it.title) /// #show heading: it => block(it.body)
/// = Blocky /// = Blocky
/// More text. /// More text.
/// ``` /// ```
@ -236,7 +236,7 @@ pub struct BlockNode {
/// The contents of the block. /// The contents of the block.
#[positional] #[positional]
#[default] #[default]
pub body: Content, pub body: Option<Content>,
/// The block's width. /// The block's width.
/// ///
@ -360,10 +360,10 @@ impl Layout for BlockNode {
regions: Regions, regions: Regions,
) -> SourceResult<Fragment> { ) -> SourceResult<Fragment> {
// Apply inset. // Apply inset.
let mut child = self.body(); let mut body = self.body().unwrap_or_default();
let inset = styles.get(Self::INSET); let inset = styles.get(Self::INSET);
if inset.iter().any(|v| !v.is_zero()) { if inset.iter().any(|v| !v.is_zero()) {
child = child.clone().padded(inset.map(|side| side.map(Length::from))); body = body.clone().padded(inset.map(|side| side.map(Length::from)));
} }
// Resolve the sizing to a concrete size. // Resolve the sizing to a concrete size.
@ -380,7 +380,7 @@ impl Layout for BlockNode {
// Measure to ensure frames for all regions have the same width. // Measure to ensure frames for all regions have the same width.
if sizing.x == Smart::Auto { if sizing.x == Smart::Auto {
let pod = Regions::one(size, Axes::splat(false)); let pod = Regions::one(size, Axes::splat(false));
let frame = child.layout(vt, styles, pod)?.into_frame(); let frame = body.layout(vt, styles, pod)?.into_frame();
size.x = frame.width(); size.x = frame.width();
expand.x = true; expand.x = true;
} }
@ -407,10 +407,10 @@ impl Layout for BlockNode {
pod.last = None; pod.last = None;
} }
child.layout(vt, styles, pod)?.into_frames() body.layout(vt, styles, pod)?.into_frames()
} else { } else {
let pod = Regions::one(size, expand); let pod = Regions::one(size, expand);
child.layout(vt, styles, pod)?.into_frames() body.layout(vt, styles, pod)?.into_frames()
}; };
// Prepare fill and stroke. // Prepare fill and stroke.

View File

@ -77,7 +77,7 @@ pub struct EnumNode {
/// ) [+ #phase] /// ) [+ #phase]
/// ``` /// ```
#[variadic] #[variadic]
pub items: Vec<EnumItem>, pub children: Vec<EnumItem>,
/// If this is `{false}`, the items are spaced apart with /// If this is `{false}`, the items are spaced apart with
/// [enum spacing]($func/enum.spacing). If it is `{true}`, they use normal /// [enum spacing]($func/enum.spacing). If it is `{true}`, they use normal
@ -203,7 +203,7 @@ impl Layout for EnumNode {
let mut parents = styles.get(Self::PARENTS); let mut parents = styles.get(Self::PARENTS);
let full = styles.get(Self::FULL); let full = styles.get(Self::FULL);
for item in self.items() { for item in self.children() {
number = item.number().unwrap_or(number); number = item.number().unwrap_or(number);
let resolved = if full { let resolved = if full {

View File

@ -34,7 +34,7 @@ impl Layout for FlowNode {
if let Some(node) = child.to::<StyledNode>() { if let Some(node) = child.to::<StyledNode>() {
map = node.map(); map = node.map();
styles = outer.chain(&map); styles = outer.chain(&map);
child = node.sub(); child = node.body();
} }
if let Some(node) = child.to::<VNode>() { if let Some(node) = child.to::<VNode>() {

View File

@ -73,7 +73,7 @@ pub struct GridNode {
/// ///
/// The cells are populated in row-major order. /// The cells are populated in row-major order.
#[variadic] #[variadic]
pub cells: Vec<Content>, pub children: Vec<Content>,
/// Defines the column sizes. /// Defines the column sizes.
/// ///
@ -114,7 +114,7 @@ impl Layout for GridNode {
regions: Regions, regions: Regions,
) -> SourceResult<Fragment> { ) -> SourceResult<Fragment> {
// Prepare grid layout by unifying content and gutter tracks. // Prepare grid layout by unifying content and gutter tracks.
let cells = self.cells(); let cells = self.children();
let layouter = GridLayouter::new( let layouter = GridLayouter::new(
vt, vt,
Axes::new(&self.columns().0, &self.rows().0), Axes::new(&self.columns().0, &self.rows().0),

View File

@ -49,7 +49,7 @@ pub struct ListNode {
/// ] /// ]
/// ``` /// ```
#[variadic] #[variadic]
pub items: Vec<ListItem>, pub children: Vec<ListItem>,
/// If this is `{false}`, the items are spaced apart with [list /// If this is `{false}`, the items are spaced apart with [list
/// spacing]($func/list.spacing). If it is `{true}`, they use normal /// spacing]($func/list.spacing). If it is `{true}`, they use normal
@ -141,7 +141,7 @@ impl Layout for ListNode {
let marker = styles.get(Self::MARKER).resolve(vt.world(), depth)?; let marker = styles.get(Self::MARKER).resolve(vt.world(), depth)?;
let mut cells = vec![]; let mut cells = vec![];
for item in self.items() { for item in self.children() {
cells.push(Content::empty()); cells.push(Content::empty());
cells.push(marker.clone()); cells.push(marker.clone());
cells.push(Content::empty()); cells.push(Content::empty());

View File

@ -307,7 +307,7 @@ impl<'a, 'v, 't> Builder<'a, 'v, 't> {
) -> SourceResult<()> { ) -> SourceResult<()> {
let map = self.scratch.maps.alloc(styled.map()); let map = self.scratch.maps.alloc(styled.map());
let stored = self.scratch.styles.alloc(styles); let stored = self.scratch.styles.alloc(styles);
let content = self.scratch.content.alloc(styled.sub()); let content = self.scratch.content.alloc(styled.body());
let styles = stored.chain(map); let styles = stored.chain(map);
self.interrupt_style(&map, None)?; self.interrupt_style(&map, None)?;
self.accept(content, styles)?; self.accept(content, styles)?;

View File

@ -521,7 +521,7 @@ fn collect<'a>(
let outer = styles; let outer = styles;
let mut styles = *styles; let mut styles = *styles;
if let Some(node) = child.to::<StyledNode>() { if let Some(node) = child.to::<StyledNode>() {
child = Box::leak(Box::new(node.sub())); child = Box::leak(Box::new(node.body()));
styles = outer.chain(Box::leak(Box::new(node.map()))); styles = outer.chain(Box::leak(Box::new(node.map())));
} }

View File

@ -40,7 +40,7 @@ use crate::prelude::*;
pub struct TableNode { pub struct TableNode {
/// The contents of the table cells. /// The contents of the table cells.
#[variadic] #[variadic]
pub cells: Vec<Content>, pub children: Vec<Content>,
/// Defines the column sizes. /// Defines the column sizes.
/// See the [grid documentation]($func/grid) for more information on track /// See the [grid documentation]($func/grid) for more information on track
@ -135,7 +135,7 @@ impl Layout for TableNode {
let gutter = Axes::new(self.column_gutter().0, self.row_gutter().0); let gutter = Axes::new(self.column_gutter().0, self.row_gutter().0);
let cols = tracks.x.len().max(1); let cols = tracks.x.len().max(1);
let cells: Vec<_> = self let cells: Vec<_> = self
.cells() .children()
.into_iter() .into_iter()
.enumerate() .enumerate()
.map(|(i, child)| { .map(|(i, child)| {

View File

@ -36,7 +36,7 @@ pub struct TermsNode {
/// ) [/ #product: Born in #year.] /// ) [/ #product: Born in #year.]
/// ``` /// ```
#[variadic] #[variadic]
pub items: Vec<TermItem>, pub children: Vec<TermItem>,
/// If this is `{false}`, the items are spaced apart with [term list /// If this is `{false}`, the items are spaced apart with [term list
/// spacing]($func/terms.spacing). If it is `{true}`, they use normal /// spacing]($func/terms.spacing). If it is `{true}`, they use normal
@ -101,12 +101,12 @@ impl Layout for TermsNode {
}; };
let mut cells = vec![]; let mut cells = vec![];
for item in self.items() { for child in self.children() {
let body = Content::sequence(vec![ let body = Content::sequence(vec![
HNode::new((-body_indent).into()).pack(), HNode::new((-body_indent).into()).pack(),
(item.term() + TextNode::packed(':')).strong(), (child.term() + TextNode::packed(':')).strong(),
SpaceNode::new().pack(), SpaceNode::new().pack(),
item.description(), child.description(),
]); ]);
cells.push(Content::empty()); cells.push(Content::empty());

View File

@ -79,12 +79,12 @@ pub struct ScriptsNode {
/// The base to attach the scripts to. /// The base to attach the scripts to.
#[positional] #[positional]
#[required] #[required]
pub base: Content, pub body: Content,
} }
impl LayoutMath for ScriptsNode { impl LayoutMath for ScriptsNode {
fn layout_math(&self, ctx: &mut MathContext) -> SourceResult<()> { fn layout_math(&self, ctx: &mut MathContext) -> SourceResult<()> {
self.base().layout_math(ctx) self.body().layout_math(ctx)
} }
} }
@ -102,12 +102,12 @@ pub struct LimitsNode {
/// The base to attach the limits to. /// The base to attach the limits to.
#[positional] #[positional]
#[required] #[required]
pub base: Content, pub body: Content,
} }
impl LayoutMath for LimitsNode { impl LayoutMath for LimitsNode {
fn layout_math(&self, ctx: &mut MathContext) -> SourceResult<()> { fn layout_math(&self, ctx: &mut MathContext) -> SourceResult<()> {
self.base().layout_math(ctx) self.body().layout_math(ctx)
} }
} }

View File

@ -20,7 +20,7 @@ const VERTICAL_PADDING: Ratio = Ratio::new(0.1);
pub struct VecNode { pub struct VecNode {
/// The elements of the vector. /// The elements of the vector.
#[variadic] #[variadic]
pub elements: Vec<Content>, pub children: Vec<Content>,
/// The delimiter to use. /// The delimiter to use.
/// ///
@ -36,7 +36,7 @@ pub struct VecNode {
impl LayoutMath for VecNode { impl LayoutMath for VecNode {
fn layout_math(&self, ctx: &mut MathContext) -> SourceResult<()> { fn layout_math(&self, ctx: &mut MathContext) -> SourceResult<()> {
let delim = ctx.styles().get(Self::DELIM); let delim = ctx.styles().get(Self::DELIM);
let frame = layout_vec_body(ctx, &self.elements(), Align::Center)?; let frame = layout_vec_body(ctx, &self.children(), Align::Center)?;
layout_delimiters(ctx, frame, Some(delim.open()), Some(delim.close())) layout_delimiters(ctx, frame, Some(delim.open()), Some(delim.close()))
} }
} }
@ -141,7 +141,7 @@ impl LayoutMath for MatNode {
pub struct CasesNode { pub struct CasesNode {
/// The branches of the case distinction. /// The branches of the case distinction.
#[variadic] #[variadic]
pub branches: Vec<Content>, pub children: Vec<Content>,
/// The delimiter to use. /// The delimiter to use.
/// ///
@ -157,7 +157,7 @@ pub struct CasesNode {
impl LayoutMath for CasesNode { impl LayoutMath for CasesNode {
fn layout_math(&self, ctx: &mut MathContext) -> SourceResult<()> { fn layout_math(&self, ctx: &mut MathContext) -> SourceResult<()> {
let delim = ctx.styles().get(Self::DELIM); let delim = ctx.styles().get(Self::DELIM);
let frame = layout_vec_body(ctx, &self.branches(), Align::Left)?; let frame = layout_vec_body(ctx, &self.children(), Align::Left)?;
layout_delimiters(ctx, frame, Some(delim.open()), None) layout_delimiters(ctx, frame, Some(delim.open()), None)
} }
} }

View File

@ -242,7 +242,7 @@ impl LayoutMath for Content {
let prev_size = ctx.size; let prev_size = ctx.size;
ctx.map.apply(prev_map.clone()); ctx.map.apply(prev_map.clone());
ctx.size = ctx.styles().get(TextNode::SIZE); ctx.size = ctx.styles().get(TextNode::SIZE);
styled.sub().layout_math(ctx)?; styled.body().layout_math(ctx)?;
ctx.size = prev_size; ctx.size = prev_size;
ctx.map = prev_map; ctx.map = prev_map;
return Ok(()); return Ok(());

View File

@ -44,7 +44,7 @@ impl LayoutRoot for DocumentNode {
if let Some(node) = child.to::<StyledNode>() { if let Some(node) = child.to::<StyledNode>() {
map = node.map(); map = node.map();
styles = outer.chain(&map); styles = outer.chain(&map);
child = node.sub(); child = node.body();
} }
if let Some(page) = child.to::<PageNode>() { if let Some(page) = child.to::<PageNode>() {

View File

@ -45,7 +45,7 @@ pub struct HeadingNode {
/// The heading's title. /// The heading's title.
#[positional] #[positional]
#[required] #[required]
pub title: Content, pub body: Content,
/// The logical nesting depth of the heading, starting from one. /// The logical nesting depth of the heading, starting from one.
#[named] #[named]
@ -120,14 +120,14 @@ impl Prepare for HeadingNode {
impl Show for HeadingNode { impl Show for HeadingNode {
fn show(&self, _: &mut Vt, this: &Content, _: StyleChain) -> SourceResult<Content> { fn show(&self, _: &mut Vt, this: &Content, _: StyleChain) -> SourceResult<Content> {
let mut realized = self.title(); let mut realized = self.body();
let numbers = this.field("numbers").unwrap(); let numbers = this.field("numbers").unwrap();
if *numbers != Value::None { if *numbers != Value::None {
realized = numbers.clone().display() realized = numbers.clone().display()
+ HNode::new(Em::new(0.3).into()).with_weak(true).pack() + HNode::new(Em::new(0.3).into()).with_weak(true).pack()
+ realized; + realized;
} }
Ok(BlockNode::new().with_body(realized).pack()) Ok(BlockNode::new().with_body(Some(realized)).pack())
} }
} }

View File

@ -103,7 +103,7 @@ impl Show for OutlineNode {
) -> SourceResult<Content> { ) -> SourceResult<Content> {
let mut seq = vec![ParbreakNode::new().pack()]; let mut seq = vec![ParbreakNode::new().pack()];
if let Some(title) = styles.get(Self::TITLE) { if let Some(title) = styles.get(Self::TITLE) {
let body = title.clone().unwrap_or_else(|| { let title = title.clone().unwrap_or_else(|| {
TextNode::packed(match styles.get(TextNode::LANG) { TextNode::packed(match styles.get(TextNode::LANG) {
Lang::GERMAN => "Inhaltsverzeichnis", Lang::GERMAN => "Inhaltsverzeichnis",
Lang::ENGLISH | _ => "Contents", Lang::ENGLISH | _ => "Contents",
@ -111,7 +111,7 @@ impl Show for OutlineNode {
}); });
seq.push( seq.push(
HeadingNode::new(body) HeadingNode::new(title)
.pack() .pack()
.styled(HeadingNode::NUMBERING, None) .styled(HeadingNode::NUMBERING, None)
.styled(HeadingNode::OUTLINED, false), .styled(HeadingNode::OUTLINED, false),
@ -161,7 +161,7 @@ impl Show for OutlineNode {
} }
// Format the numbering. // Format the numbering.
let mut start = heading.title(); let mut start = heading.body();
let numbers = node.field("numbers").unwrap(); let numbers = node.field("numbers").unwrap();
if *numbers != Value::None { if *numbers != Value::None {
start = numbers.clone().display() + SpaceNode::new().pack() + start; start = numbers.clone().display() + SpaceNode::new().pack() + start;
@ -175,7 +175,7 @@ impl Show for OutlineNode {
seq.push(SpaceNode::new().pack()); seq.push(SpaceNode::new().pack());
seq.push( seq.push(
BoxNode::new() BoxNode::new()
.with_body(filler.clone()) .with_body(Some(filler.clone()))
.with_width(Fr::one().into()) .with_width(Fr::one().into())
.pack(), .pack(),
); );

View File

@ -171,7 +171,7 @@ impl Show for RawNode {
}; };
if self.block() { if self.block() {
realized = BlockNode::new().with_body(realized).pack(); realized = BlockNode::new().with_body(Some(realized)).pack();
} }
Ok(realized) Ok(realized)

View File

@ -55,7 +55,7 @@ impl Content {
/// Attach a span to the content. /// Attach a span to the content.
pub fn spanned(mut self, span: Span) -> Self { pub fn spanned(mut self, span: Span) -> Self {
if let Some(styled) = self.to::<StyledNode>() { if let Some(styled) = self.to::<StyledNode>() {
self = StyledNode::new(styled.sub().spanned(span), styled.map()).pack(); self = StyledNode::new(styled.body().spanned(span), styled.map()).pack();
} }
self.span = Some(span); self.span = Some(span);
self self
@ -83,7 +83,7 @@ impl Content {
} else if let Some(styled) = self.to::<StyledNode>() { } else if let Some(styled) = self.to::<StyledNode>() {
let mut map = styled.map(); let mut map = styled.map();
map.apply(styles); map.apply(styles);
StyledNode::new(styled.sub(), map).pack() StyledNode::new(styled.body(), map).pack()
} else { } else {
StyledNode::new(self, styles).pack() StyledNode::new(self, styles).pack()
} }
@ -268,7 +268,7 @@ impl Debug for Content {
if let Some(styled) = self.to::<StyledNode>() { if let Some(styled) = self.to::<StyledNode>() {
styled.map().fmt(f)?; styled.map().fmt(f)?;
styled.sub().fmt(f) styled.body().fmt(f)
} else if let Some(seq) = self.to::<SequenceNode>() { } else if let Some(seq) = self.to::<SequenceNode>() {
f.debug_list().entries(&seq.children()).finish() f.debug_list().entries(&seq.children()).finish()
} else if self.id.name() == "space" { } else if self.id.name() == "space" {
@ -334,7 +334,7 @@ pub struct StyledNode {
/// The styled content. /// The styled content.
#[positional] #[positional]
#[required] #[required]
pub sub: Content, pub body: Content,
/// The styles. /// The styles.
#[positional] #[positional]

View File

@ -165,7 +165,7 @@ pub enum Expr {
Let(LetBinding), Let(LetBinding),
/// A set rule: `set text(...)`. /// A set rule: `set text(...)`.
Set(SetRule), Set(SetRule),
/// A show rule: `show heading: it => [*{it.body}*]`. /// A show rule: `show heading: it => emph(it.body)`.
Show(ShowRule), Show(ShowRule),
/// An if-else conditional: `if x { y } else { z }`. /// An if-else conditional: `if x { y } else { z }`.
Conditional(Conditional), Conditional(Conditional),
@ -1591,7 +1591,7 @@ impl SetRule {
} }
node! { node! {
/// A show rule: `show heading: it => [*{it.body}*]`. /// A show rule: `show heading: it => emph(it.body)`.
ShowRule ShowRule
} }

View File

@ -224,7 +224,7 @@ pub enum SyntaxKind {
LetBinding, LetBinding,
/// A set rule: `set text(...)`. /// A set rule: `set text(...)`.
SetRule, SetRule,
/// A show rule: `show heading: it => [*{it.body}*]`. /// A show rule: `show heading: it => emph(it.body)`.
ShowRule, ShowRule,
/// An if-else conditional: `if x { y } else { z }`. /// An if-else conditional: `if x { y } else { z }`.
Conditional, Conditional,

View File

@ -15,7 +15,7 @@
--- ---
// Test field on node. // Test field on node.
#show list: node => { #show list: node => {
test(node.items.len(), 3) test(node.children.len(), 3)
} }
- A - A

View File

@ -2,7 +2,7 @@
--- ---
// Override lists. // Override lists.
#show list: it => "(" + it.items.map(item => item.body).join(", ") + ")" #show list: it => "(" + it.children.map(v => v.body).join(", ") + ")"
- A - A
- B - B
@ -31,9 +31,9 @@ my heading?
box(move(dy: -1pt)[📖]) box(move(dy: -1pt)[📖])
h(5pt) h(5pt)
if it.level == 1 { if it.level == 1 {
underline(text(1.25em, blue, it.title)) underline(text(1.25em, blue, it.body))
} else { } else {
text(red, it.title) text(red, it.body)
} }
}) })
@ -51,7 +51,7 @@ Another text.
#show heading: it => { #show heading: it => {
set text(red) set text(red)
show "ding": [🛎] show "ding": [🛎]
it.title it.body
} }
= Heading = Heading

View File

@ -35,7 +35,7 @@
#show terms: it => table( #show terms: it => table(
columns: 2, columns: 2,
inset: 3pt, inset: 3pt,
..it.items.map(item => (emph(item.term), item.description)).flatten(), ..it.children.map(v => (emph(v.term), v.description)).flatten(),
) )
/ A: One letter / A: One letter

View File

@ -38,7 +38,7 @@ multiline.
--- ---
// Test styling. // Test styling.
#show heading.where(level: 5): it => block( #show heading.where(level: 5): it => block(
text(font: "Roboto", fill: eastern, it.title + [!]) text(font: "Roboto", fill: eastern, it.body + [!])
) )
= Heading = Heading