pub struct Content { /* private fields */ }
Expand description
A piece of document content.
This type is at the heart of Typst. All markup you write and most functions you call produce content values. You can create a content value by enclosing markup in square brackets. This is also how you pass content to functions.
§Example
Type of *Hello!* is
#type([*Hello!*])
Content can be added with the +
operator,
joined together and multiplied with integers. Wherever
content is expected, you can also pass a string or {none}
.
§Representation
Content consists of elements with fields. When constructing an element with its element function, you provide these fields as arguments and when you have a content value, you can access its fields with field access syntax.
Some fields are required: These must be provided when constructing an element and as a consequence, they are always available through field access on content of that type. Required fields are marked as such in the documentation.
Most fields are optional: Like required fields, they can be passed to the element function to configure them for a single element. However, these can also be configured with set rules to apply them to all elements within a scope. Optional fields are only available with field access syntax when they were explicitly passed to the element function, not when they result from a set rule.
Each element has a default appearance. However, you can also completely customize its appearance with a show rule. The show rule is passed the element. It can access the element’s field and produce arbitrary content from it.
In the web app, you can hover over a content variable to see exactly which
elements the content is composed of and what fields they have.
Alternatively, you can inspect the output of the [repr
] function.
Implementations§
source§impl Content
impl Content
sourcepub fn new<T: NativeElement>(elem: T) -> Self
pub fn new<T: NativeElement>(elem: T) -> Self
Creates a new content from an element.
sourcepub fn located(self, loc: Location) -> Self
pub fn located(self, loc: Location) -> Self
Assigns a location to the content.
This identifies the content and e.g. makes it linkable by
.linked(Destination::Location(loc))
.
Useful in combination with Location::variant
.
sourcepub fn set_location(&mut self, location: Location)
pub fn set_location(&mut self, location: Location)
Set the location of the content.
sourcepub fn is_guarded(&self, index: RecipeIndex) -> bool
pub fn is_guarded(&self, index: RecipeIndex) -> bool
Check whether a show rule recipe is disabled.
sourcepub fn guarded(self, index: RecipeIndex) -> Self
pub fn guarded(self, index: RecipeIndex) -> Self
Disable a show rule recipe.
sourcepub fn is_prepared(&self) -> bool
pub fn is_prepared(&self) -> bool
Whether this content has already been prepared.
sourcepub fn mark_prepared(&mut self)
pub fn mark_prepared(&mut self)
Mark this content as prepared.
sourcepub fn get(
&self,
id: u8,
styles: Option<StyleChain<'_>>,
) -> Result<Value, FieldAccessError>
pub fn get( &self, id: u8, styles: Option<StyleChain<'_>>, ) -> Result<Value, FieldAccessError>
Get a field by ID.
This is the preferred way to access fields. However, you can only use it
if you have set the field IDs yourself or are using the field IDs
generated by the #[elem]
macro.
sourcepub fn get_by_name(&self, name: &str) -> Result<Value, FieldAccessError>
pub fn get_by_name(&self, name: &str) -> Result<Value, FieldAccessError>
Get a field by name.
If you have access to the field IDs of the element, use Self::get
instead.
sourcepub fn field(&self, id: u8) -> StrResult<Value>
pub fn field(&self, id: u8) -> StrResult<Value>
Get a field by ID, returning a missing field error if it does not exist.
This is the preferred way to access fields. However, you can only use it
if you have set the field IDs yourself or are using the field IDs
generated by the #[elem]
macro.
sourcepub fn field_by_name(&self, name: &str) -> StrResult<Value>
pub fn field_by_name(&self, name: &str) -> StrResult<Value>
Get a field by name, returning a missing field error if it does not exist.
If you have access to the field IDs of the element, use Self::field
instead.
sourcepub fn materialize(&mut self, styles: StyleChain<'_>)
pub fn materialize(&mut self, styles: StyleChain<'_>)
Resolve all fields with the styles and save them in-place.
sourcepub fn sequence(iter: impl IntoIterator<Item = Self>) -> Self
pub fn sequence(iter: impl IntoIterator<Item = Self>) -> Self
Create a new sequence element from multiples elements.
sourcepub fn is<T: NativeElement>(&self) -> bool
pub fn is<T: NativeElement>(&self) -> bool
Whether the contained element is of type T
.
sourcepub fn to_packed<T: NativeElement>(&self) -> Option<&Packed<T>>
pub fn to_packed<T: NativeElement>(&self) -> Option<&Packed<T>>
Downcasts the element to a packed value.
sourcepub fn to_packed_mut<T: NativeElement>(&mut self) -> Option<&mut Packed<T>>
pub fn to_packed_mut<T: NativeElement>(&mut self) -> Option<&mut Packed<T>>
Downcasts the element to a mutable packed value.
sourcepub fn into_packed<T: NativeElement>(self) -> Result<Packed<T>, Self>
pub fn into_packed<T: NativeElement>(self) -> Result<Packed<T>, Self>
Downcasts the element into an owned packed value.
sourcepub fn unpack<T: NativeElement>(self) -> Result<T, Self>
pub fn unpack<T: NativeElement>(self) -> Result<T, Self>
Extract the raw underlying element.
sourcepub fn can<C>(&self) -> boolwhere
C: ?Sized + 'static,
pub fn can<C>(&self) -> boolwhere
C: ?Sized + 'static,
Whether the contained element has the given capability.
sourcepub fn with<C>(&self) -> Option<&C>where
C: ?Sized + 'static,
pub fn with<C>(&self) -> Option<&C>where
C: ?Sized + 'static,
Cast to a trait object if the contained element has the given capability.
sourcepub fn with_mut<C>(&mut self) -> Option<&mut C>where
C: ?Sized + 'static,
pub fn with_mut<C>(&mut self) -> Option<&mut C>where
C: ?Sized + 'static,
Cast to a mutable trait object if the contained element has the given capability.
sourcepub fn sequence_recursive_for_each<'a>(&'a self, f: &mut impl FnMut(&'a Self))
pub fn sequence_recursive_for_each<'a>(&'a self, f: &mut impl FnMut(&'a Self))
Also auto expands sequence of sequences into flat sequence
sourcepub fn styled_with_recipe(
self,
engine: &mut Engine<'_>,
context: Tracked<'_, Context<'_>>,
recipe: Recipe,
) -> SourceResult<Self>
pub fn styled_with_recipe( self, engine: &mut Engine<'_>, context: Tracked<'_, Context<'_>>, recipe: Recipe, ) -> SourceResult<Self>
Style this content with a recipe, eagerly applying it if possible.
sourcepub fn styled_with_map(self, styles: Styles) -> Self
pub fn styled_with_map(self, styles: Styles) -> Self
Style this content with a full style map.
sourcepub fn style_in_place(&mut self, styles: Styles)
pub fn style_in_place(&mut self, styles: Styles)
Style this content with a full style map in-place.
sourcepub fn query(&self, selector: Selector) -> Vec<Content>
pub fn query(&self, selector: Selector) -> Vec<Content>
Queries the content tree for all elements that match the given selector.
Elements produced in show
rules will not be included in the results.
sourcepub fn query_first(&self, selector: Selector) -> Option<Content>
pub fn query_first(&self, selector: Selector) -> Option<Content>
Queries the content tree for the first element that match the given selector.
Elements produced in show
rules will not be included in the results.
sourcepub fn plain_text(&self) -> EcoString
pub fn plain_text(&self) -> EcoString
Extracts the plain text of this content.
source§impl Content
impl Content
sourcepub fn underlined(self) -> Self
pub fn underlined(self) -> Self
Underline this content.
sourcepub fn linked(self, dest: Destination) -> Self
pub fn linked(self, dest: Destination) -> Self
Link the content somewhere.
source§impl Content
impl Content
sourcepub fn func(&self) -> Element
pub fn func(&self) -> Element
The content’s element function. This function can be used to create the element contained in this content. It can be used in set and show rules for the element. Can be compared with global functions to check whether you have a specific kind of element.
sourcepub fn at(&self, field: Str, default: Option<Value>) -> StrResult<Value>
pub fn at(&self, field: Str, default: Option<Value>) -> StrResult<Value>
Access the specified field on the content. Returns the default value if the field does not exist or fails with an error if no default value was specified.
Trait Implementations§
source§impl AddAssign<&Content> for Content
impl AddAssign<&Content> for Content
source§fn add_assign(&mut self, rhs: &Self)
fn add_assign(&mut self, rhs: &Self)
+=
operation. Read moresource§impl AddAssign for Content
impl AddAssign for Content
source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+=
operation. Read moresource§impl<T: NativeElement> From<T> for Content
impl<T: NativeElement> From<T> for Content
source§impl FromValue for Content
impl FromValue for Content
source§fn from_value(value: Value) -> HintedStrResult<Self>
fn from_value(value: Value) -> HintedStrResult<Self>
Self
.source§impl NativeScope for Content
impl NativeScope for Content
source§fn constructor() -> Option<&'static NativeFuncData>
fn constructor() -> Option<&'static NativeFuncData>
source§impl NativeType for Content
impl NativeType for Content
source§impl TryFrom<Content> for GridChild
impl TryFrom<Content> for GridChild
source§type Error = HintedString
type Error = HintedString
source§fn try_from(value: Content) -> HintedStrResult<Self>
fn try_from(value: Content) -> HintedStrResult<Self>
source§impl TryFrom<Content> for GridItem
impl TryFrom<Content> for GridItem
source§type Error = HintedString
type Error = HintedString
source§fn try_from(value: Content) -> HintedStrResult<Self>
fn try_from(value: Content) -> HintedStrResult<Self>
source§impl TryFrom<Content> for TableChild
impl TryFrom<Content> for TableChild
source§type Error = HintedString
type Error = HintedString
source§fn try_from(value: Content) -> HintedStrResult<Self>
fn try_from(value: Content) -> HintedStrResult<Self>
Auto Trait Implementations§
impl Freeze for Content
impl !RefUnwindSafe for Content
impl Send for Content
impl Sync for Content
impl Unpin for Content
impl !UnwindSafe for Content
Blanket Implementations§
source§impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
source§fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
source§fn adapt_into(self) -> D
fn adapt_into(self) -> D
source§impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
source§fn arrays_from(colors: C) -> T
fn arrays_from(colors: C) -> T
source§impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
source§fn arrays_into(self) -> C
fn arrays_into(self) -> C
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
source§type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
parameters
when converting.source§fn cam16_into_unclamped(
self,
parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>,
) -> T
fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>, ) -> T
self
into C
, using the provided parameters.source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
source§fn components_from(colors: C) -> T
fn components_from(colors: C) -> T
source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
source§impl<T> Filterable for T
impl<T> Filterable for T
source§fn filterable(
self,
filter_name: &'static str,
) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>
fn filterable( self, filter_name: &'static str, ) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>
source§impl<T> FromAngle<T> for T
impl<T> FromAngle<T> for T
source§fn from_angle(angle: T) -> T
fn from_angle(angle: T) -> T
angle
.source§impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
source§fn from_stimulus(other: U) -> T
fn from_stimulus(other: U) -> T
other
into Self
, while performing the appropriate scaling,
rounding and clamping.source§impl<T> FromValue<Spanned<Value>> for Twhere
T: FromValue,
impl<T> FromValue<Spanned<Value>> for Twhere
T: FromValue,
source§fn from_value(value: Spanned<Value>) -> Result<T, HintedString>
fn from_value(value: Spanned<Value>) -> Result<T, HintedString>
Self
.source§impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
source§fn into_angle(self) -> U
fn into_angle(self) -> U
T
.source§impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
source§type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
parameters
when converting.source§fn into_cam16_unclamped(
self,
parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>,
) -> T
fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>, ) -> T
self
into C
, using the provided parameters.source§impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
source§fn into_color(self) -> U
fn into_color(self) -> U
source§impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
source§fn into_color_unclamped(self) -> U
fn into_color_unclamped(self) -> U
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§impl<T> IntoResult for Twhere
T: IntoValue,
impl<T> IntoResult for Twhere
T: IntoValue,
source§fn into_result(self, _: Span) -> Result<Value, EcoVec<SourceDiagnostic>>
fn into_result(self, _: Span) -> Result<Value, EcoVec<SourceDiagnostic>>
source§impl<T> IntoStimulus<T> for T
impl<T> IntoStimulus<T> for T
source§fn into_stimulus(self) -> T
fn into_stimulus(self) -> T
self
into T
, while performing the appropriate scaling,
rounding and clamping.source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
source§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
source§impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
source§type Error = <C as TryFromComponents<T>>::Error
type Error = <C as TryFromComponents<T>>::Error
try_into_colors
fails to cast.source§fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
source§impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
source§fn try_into_color(self) -> Result<U, OutOfBounds<U>>
fn try_into_color(self) -> Result<U, OutOfBounds<U>>
OutOfBounds
error is returned which contains
the unclamped color. Read more