Skip to main content

Block

Struct Block 

Source
pub struct Block {
Show 13 fields pub span: Span, pub attribute_context: Arc<Attributes>, pub conversion_context: Option<Arc<Attributes>>, pub id: Option<String>, pub reftext: Option<Vec<Inline>>, pub roles: Vec<String>, pub title: Option<Vec<Inline>>, pub caption: Option<String>, pub caption_parts: Vec<AttributePart>, pub toc: Option<Box<Toc>>, pub attrs: BlockAttrs, pub simple: bool, pub kind: BlockKind,
}
Expand description

A block node: its source span, an optional id, and its kind.

id is the block’s anchor — the target a <<id>> resolves to. It comes from an explicit anchor ([[id]], set by the parser) or, for a section heading without one, an auto-generated sectids id assigned during the resolve pass. It is None for any block with no anchor, including an unanchored document title, and before resolution runs for an auto-id section.

reftext is the inline display text from an explicit [[id,reftext]] anchor; the resolve pass uses it as a textless reference’s display text (preferring it over a section’s own title when nonempty). None when no reftext was given. Block-anchor reftext executes an early attribute stage followed by c/q/r; even an empty result can retain source reference nodes for editor consumers.

roles are the CSS roles attached by a [.role] / [#id.role1.role2] shorthand block-attribute line — pure rendering metadata (the HTML backend emits them as a class), not part of cross-reference resolution. Empty when none were given. Order is source order.

attrs is the rest of a block-attribute list ([style, name=value, %option]): the block style, named attributes and %options. id and role are not here — they fold into id / roles above (the canonical anchor/role targets), regardless of whether they came from shorthand (#id / .role) or the longhand (id= / role=). See BlockAttrs.

Fields§

§span: Span§attribute_context: Arc<Attributes>

Immutable snapshot of attributes when this block finished parsing. A container sees assignments made while parsing its children; an already completed block keeps its own snapshot. Inline values retain the context in which they were scanned. Shared until an attribute assignment changes the parse context.

§conversion_context: Option<Arc<Attributes>>

The document attributes when this block converts, which Ruby’s converter reads (sectanchors, prewrap, toc-placement, …): the header snapshot with the declarations replayed up to the block and the effects of earlier conversions, taken on entry before its title and content. Unlike attribute_context, it has no reading-only effects (orphan declarations, section-title expressions). None until conversion visits the block; see Block::conversion_attributes.

§id: Option<String>§reftext: Option<Vec<Inline>>§roles: Vec<String>§title: Option<Vec<Inline>>

The block’s title — a .Title line preceding the block (asciidoctor’s BlockTitleRx). None when the block has no title. The text is parsed inlines (inline substitutions apply, e.g. .A *bold* caption), so it carries formatting. The title lives on the Block (not inside BlockKind) so it survives the type-changing style fixups — a .Title before a [NOTE]/[example] block stays on the resulting container, not on the wrapped child. An unrendered passthrough title keeps its source text unless it was evaluated during reading for an explicit block ID.

§caption: Option<String>

The block’s resolved caption — the counter prefix a titled block carries before its title, e.g. "Example 1. " (note the trailing space). Filled at parse completion and only for a titled BlockKind::Example (asciidoctor numbers example blocks via the example-caption attribute; an untitled example gets no caption and does not advance the counter). An explicit block/document caption replaces the prefix without advancing the counter, including an empty caption. A numbered section’s BlockKind::Heading carries its number prefix here instead ("1.2. ", "Chapter 3. ", "II: "), computed during conversion like asciidoctor’s convert_section (sectnumlevels and the signifiers at the section); backends render it before the inlines. None for every other block — a titled listing or paragraph renders its bare title, matching asciidoctor’s unset listing-caption. Stored pre-rendered, like asciidoctor’s @caption (#{caption}#{title}): backends prepend it to the title verbatim.

§caption_parts: Vec<AttributePart>

The caption’s semantic parts when it is not plain text, like the HTML Ruby stores in @caption: a caption attribute’s formatting or raw markup (pass:q[*Ex*]), a raw unquoted or substituted single-quoted caption=, a signifier. Empty when caption is plain text; caption is always the flat text of these parts.

§toc: Option<Box<Toc>>

The table of contents this block converts with: a toc::[] block’s (Ruby’s convert_toc) or a preamble’s with toc-placement=preamble (convert_preamble). None for other blocks and where Ruby renders no TOC (<!-- toc disabled --> for the macro).

§attrs: BlockAttrs§simple: bool

Ruby’s :simple content model: a container built from a styled paragraph ([NOTE]/NOTE:, [example], [sidebar], [open], [abstract], [partintro], [quote]) holding that paragraph as its only child. Converters write the paragraph’s inlines directly, without a paragraph element, like Ruby’s content of a simple block. false for every delimited or other block.

§kind: BlockKind

Implementations§

Source§

impl Block

Source

pub fn new(span: Span, kind: BlockKind) -> Block

A block with no anchor: id/reftext default to None and roles / attrs are empty. The parser fills them in from an explicit [[id]] / [[id,reftext]] anchor or a [style, #id.role, name=value] attribute line preceding the block; the resolve pass fills id for an auto-id section.

Source

pub fn set_caption(&mut self, parts: Option<Vec<AttributePart>>)

Set the caption from its parts (see caption_parts).

Source

pub fn conversion_attributes(&self) -> &Attributes

The attributes a converter reads for this block: its conversion_context, else (for a block conversion did not visit) its reading snapshot.

Trait Implementations§

Source§

impl Clone for Block

Source§

fn clone(&self) -> Block

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Block

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Block

Source§

fn eq(&self, other: &Block) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Block

Auto Trait Implementations§

§

impl Freeze for Block

§

impl RefUnwindSafe for Block

§

impl Send for Block

§

impl Sync for Block

§

impl Unpin for Block

§

impl UnsafeUnpin for Block

§

impl UnwindSafe for Block

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.