Skip to main content

Block

Enum Block 

Source
pub enum Block {
Show 25 variants Paragraph { id: Option<String>, children: Vec<Text>, attributes: BlockAttributes, }, Heading { id: Option<String>, level: u8, children: Vec<Text>, attributes: BlockAttributes, }, List { id: Option<String>, ordered: bool, start: Option<u32>, children: Vec<Block>, attributes: BlockAttributes, }, ListItem { id: Option<String>, checked: Option<bool>, children: Vec<Block>, attributes: BlockAttributes, }, Blockquote { id: Option<String>, children: Vec<Block>, attributes: BlockAttributes, }, CodeBlock { id: Option<String>, language: Option<String>, highlighting: Option<String>, tokens: Option<Vec<CodeToken>>, children: Vec<Text>, attributes: BlockAttributes, }, HorizontalRule { id: Option<String>, }, Image(ImageBlock), Table { id: Option<String>, children: Vec<Block>, attributes: BlockAttributes, }, TableRow { id: Option<String>, header: bool, children: Vec<Block>, attributes: BlockAttributes, }, TableCell(TableCellBlock), Math(MathBlock), Break { id: Option<String>, }, DefinitionList(DefinitionListBlock), DefinitionItem { id: Option<String>, children: Vec<Block>, attributes: BlockAttributes, }, DefinitionTerm { id: Option<String>, children: Vec<Text>, attributes: BlockAttributes, }, DefinitionDescription { id: Option<String>, children: Vec<Block>, attributes: BlockAttributes, }, Measurement(MeasurementBlock), Signature(SignatureBlock), Svg(SvgBlock), Barcode(BarcodeBlock), Figure(FigureBlock), FigCaption(FigCaptionBlock), Admonition(AdmonitionBlock), Extension(ExtensionBlock),
}
Expand description

A content block in the document tree.

Blocks are the structural elements of a document, containing either other blocks (containers) or text content (leaves).

§Serialization

Blocks serialize as JSON objects with a "type" field. Core block types use camelCase names (e.g., "paragraph", "codeBlock"). Extension blocks use colon-delimited types (e.g., "forms:textInput", "academic:theorem").

Variants§

§

Paragraph

Standard paragraph block.

Fields

§id: Option<String>

Optional unique identifier.

§children: Vec<Text>

Text content.

§attributes: BlockAttributes

Block attributes.

§

Heading

Section heading (levels 1-6).

Fields

§id: Option<String>

Optional unique identifier.

§level: u8

Heading level (1-6).

§children: Vec<Text>

Text content.

§attributes: BlockAttributes

Block attributes.

§

List

Ordered or unordered list.

Fields

§id: Option<String>

Optional unique identifier.

§ordered: bool

Whether the list is ordered (numbered).

§start: Option<u32>

Starting number for ordered lists.

§children: Vec<Block>

List items (must be ListItem blocks).

§attributes: BlockAttributes

Block attributes.

§

ListItem

Item within a list.

Fields

§id: Option<String>

Optional unique identifier.

§checked: Option<bool>

Checkbox state (None = not a checkbox).

§children: Vec<Block>

Block content.

§attributes: BlockAttributes

Block attributes.

§

Blockquote

Quoted content block.

Fields

§id: Option<String>

Optional unique identifier.

§children: Vec<Block>

Block content.

§attributes: BlockAttributes

Block attributes.

§

CodeBlock

Source code or preformatted text.

Fields

§id: Option<String>

Optional unique identifier.

§language: Option<String>

Programming language identifier.

§highlighting: Option<String>

Syntax highlighting theme.

§tokens: Option<Vec<CodeToken>>

Pre-tokenized syntax highlighting.

§children: Vec<Text>

Code content (single text node, no marks).

§attributes: BlockAttributes

Block attributes.

§

HorizontalRule

Thematic break between sections.

Fields

§id: Option<String>

Optional unique identifier.

§

Image(ImageBlock)

Embedded or referenced image.

§

Table

Tabular data.

Fields

§id: Option<String>

Optional unique identifier.

§children: Vec<Block>

Table rows.

§attributes: BlockAttributes

Block attributes.

§

TableRow

Row within a table.

Fields

§id: Option<String>

Optional unique identifier.

§header: bool

Whether this is a header row.

§children: Vec<Block>

Table cells.

§attributes: BlockAttributes

Block attributes.

§

TableCell(TableCellBlock)

Cell within a table row.

§

Math(MathBlock)

Mathematical content.

§

Break

Line break within a block.

Fields

§id: Option<String>

Optional unique identifier.

§

DefinitionList(DefinitionListBlock)

Definition list.

§

DefinitionItem

Definition item (term + description pair).

Fields

§id: Option<String>

Optional unique identifier.

§children: Vec<Block>

Children (typically DefinitionTerm and DefinitionDescription).

§attributes: BlockAttributes

Block attributes.

§

DefinitionTerm

Definition term.

Fields

§id: Option<String>

Optional unique identifier.

§children: Vec<Text>

Term text content.

§attributes: BlockAttributes

Block attributes.

§

DefinitionDescription

Definition description.

Fields

§id: Option<String>

Optional unique identifier.

§children: Vec<Block>

Description content (blocks).

§attributes: BlockAttributes

Block attributes.

§

Measurement(MeasurementBlock)

Scientific/technical measurement.

§

Signature(SignatureBlock)

Block-level signature.

§

Svg(SvgBlock)

SVG image.

§

Barcode(BarcodeBlock)

Barcode (QR, Data Matrix, etc.).

§

Figure(FigureBlock)

Figure container.

§

FigCaption(FigCaptionBlock)

Figure caption.

§

Admonition(AdmonitionBlock)

Admonition block (note, warning, tip, etc.).

§

Extension(ExtensionBlock)

Extension block for custom/unknown block types.

Extension blocks use namespaced types like “forms:textInput” or “semantic:citation”. When parsing, unknown types are preserved as extension blocks with their raw attributes intact.

Implementations§

Source§

impl Block

Source

pub fn paragraph(children: Vec<Text>) -> Self

Create a paragraph block.

Source

pub fn heading(level: u8, children: Vec<Text>) -> Self

Create a heading block.

Source

pub fn unordered_list(items: Vec<Block>) -> Self

Create an unordered list.

Source

pub fn ordered_list(items: Vec<Block>) -> Self

Create an ordered list.

Source

pub fn list_item(children: Vec<Block>) -> Self

Create a list item.

Source

pub fn checkbox(checked: bool, children: Vec<Block>) -> Self

Create a checkbox list item.

Source

pub fn blockquote(children: Vec<Block>) -> Self

Create a blockquote.

Source

pub fn code_block(code: impl Into<String>, language: Option<String>) -> Self

Create a code block.

Source

pub fn horizontal_rule() -> Self

Create a horizontal rule.

Source

pub fn image(src: impl Into<String>, alt: impl Into<String>) -> Self

Create an image block.

Source

pub fn table(rows: Vec<Block>) -> Self

Create a table.

Source

pub fn table_row(cells: Vec<Block>, header: bool) -> Self

Create a table row.

Source

pub fn table_cell(children: Vec<Text>) -> Self

Create a table cell.

Source

pub fn math(value: impl Into<String>, format: MathFormat, display: bool) -> Self

Create a math block.

Source

pub fn line_break() -> Self

Create a line break.

Source

pub fn definition_list(items: Vec<Block>) -> Self

Create a definition list.

Source

pub fn definition_item(children: Vec<Block>) -> Self

Create a definition item.

Source

pub fn definition_term(children: Vec<Text>) -> Self

Create a definition term.

Source

pub fn definition_description(children: Vec<Block>) -> Self

Create a definition description.

Source

pub fn measurement(value: f64, display: impl Into<String>) -> Self

Create a measurement block.

Source

pub fn signature(signature_type: BlockSignatureType) -> Self

Create a signature block.

Source

pub fn svg_from_src(src: impl Into<String>) -> Self

Create an SVG block from a source reference.

Source

pub fn svg_from_content(content: impl Into<String>) -> Self

Create an SVG block from inline content.

Source

pub fn barcode( format: BarcodeFormat, data: impl Into<String>, alt: impl Into<String>, ) -> Self

Create a barcode block.

Source

pub fn figure(children: Vec<Block>) -> Self

Create a figure block.

Source

pub fn figcaption(children: Vec<Text>) -> Self

Create a figure caption.

Source

pub fn admonition(variant: AdmonitionVariant, children: Vec<Block>) -> Self

Create an admonition block.

Source

pub fn block_type(&self) -> Cow<'_, str>

Get the block type as a string.

For core blocks, returns the camelCase type name. For extension blocks, returns the colon-delimited type (e.g., "forms:textInput").

Source

pub fn id(&self) -> Option<&str>

Get the block’s ID if it has one.

Source

pub fn extension( namespace: impl Into<String>, block_type: impl Into<String>, ) -> Self

Create an extension block.

Source

pub fn is_extension(&self) -> bool

Check if this is an extension block.

Source

pub fn as_extension(&self) -> Option<&ExtensionBlock>

Get the extension block if this is one.

Trait Implementations§

Source§

impl Clone for Block

Source§

fn clone(&self) -> Block

Returns a duplicate of the value. Read more
1.0.0 · 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

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

impl<'de> Deserialize<'de> for Block

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Block

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Block

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. 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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,