Skip to main content

Block

Enum Block 

Source
pub enum Block {
    Paragraph {
        content: Vec<Inline>,
        extra: Extra,
    },
    Heading {
        level: u8,
        content: Vec<Inline>,
        extra: Extra,
    },
    SceneBreak {
        extra: Extra,
    },
    BlockQuote {
        blocks: Vec<Block>,
        extra: Extra,
    },
    Verse {
        lines: Vec<Vec<Inline>>,
        indents: Vec<u8>,
        extra: Extra,
    },
    Image {
        asset: String,
        alt: String,
        caption: Option<Vec<Inline>>,
        width: Option<u8>,
        placement: ImagePlacement,
        side: ImageSide,
        extra: Extra,
    },
    List {
        ordered: bool,
        items: Vec<Vec<Block>>,
        extra: Extra,
    },
    Table(Table),
    PageBreak {
        extra: Extra,
    },
}
Expand description

Every variant carries extra (unknown fields, see Extra); build blocks with the constructors below and match with ...

Variants§

§

Paragraph

Fields

§content: Vec<Inline>
§extra: Extra
§

Heading

A sub-heading inside a section (rare in fiction). level counts from the section title: 1 is the first level below it (Markdown ##; in .docx the heading style one below the chapter style).

Fields

§level: u8
§content: Vec<Inline>
§extra: Extra
§

SceneBreak

Fields

§extra: Extra
§

BlockQuote

Fields

§blocks: Vec<Block>
§extra: Extra
§

Verse

Lines kept as written; stanzas separated by empty Vecs.

Fields

§lines: Vec<Vec<Inline>>
§indents: Vec<u8>

The indent level of each line (0 is flush), by position in lines; empty when no line is indented, and then not written. May be shorter or longer than lines in a damaged file: read it through Block::verse_indent, never by index.

§extra: Extra
§

Image

Fields

§asset: String
§caption: Option<Vec<Inline>>
§width: Option<u8>

Width as a percentage of the text block’s width, 10–100 (the app offers steps of 5). None: automatic, today’s fit, or 40 % beside the text. Read through Block::image_width.

§placement: ImagePlacement
§side: ImageSide

Which side a picture beside the text stands on; read only for Beside, kept when the placement changes.

§extra: Extra
§

List

Fields

§ordered: bool
§items: Vec<Vec<Block>>
§extra: Extra
§

Table(Table)

A table (ADR-0011). Its JSON is flat: the table’s own fields and its extra stand next to "type": "table". Draw it through Table::layout, never by indexing rows.

§

PageBreak

Fields

§extra: Extra

Implementations§

Source§

impl Block

Source

pub fn paragraph(content: Vec<Inline>) -> Self

Source

pub fn heading(level: u8, content: Vec<Inline>) -> Self

Source

pub fn scene_break() -> Self

Source

pub fn block_quote(blocks: Vec<Block>) -> Self

Source

pub fn verse(lines: Vec<Vec<Inline>>) -> Self

Source

pub fn with_indents(self, levels: Vec<u8>) -> Self

Set the indent level of each line of a verse block, by position in lines (other blocks are returned unchanged). All zeros is stored as none, so a verse without indents writes the same JSON as before. Levels are stored as given and capped on read.

Source

pub fn verse_indent(&self, line: usize) -> u8

The indent level of verse line line: 0 when the block has no level for it (none stored, a shorter list in a damaged file, a block that is not verse), at most MAX_VERSE_INDENT; levels beyond the lines are ignored. Always read the levels through this.

Source

pub fn image( asset: impl Into<String>, alt: impl Into<String>, caption: Option<Vec<Inline>>, ) -> Self

Source

pub fn with_width(self, percent: u8) -> Self

Set a picture’s width (percent of the text width); other blocks are returned unchanged. The value is stored as given and clamped on read.

Source

pub fn with_placement(self, to: ImagePlacement) -> Self

Source

pub fn with_side(self, to: ImageSide) -> Self

Source

pub fn image_width(&self) -> Option<u8>

A picture’s width as a percentage of the text block, clamped for a hand-edited file: 10–100, and 25–50 beside the text. None for automatic width and for other blocks.

Source

pub fn list(ordered: bool, items: Vec<Vec<Block>>) -> Self

Source

pub fn table(table: Table) -> Self

Source

pub fn page_break() -> Self

Source

pub fn extra(&self) -> &Extra

Unknown fields read with this block.

Trait Implementations§

Source§

impl Clone for Block

Source§

fn clone(&self) -> Self

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

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

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

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

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

impl PartialEq for Block

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl Serialize for Block

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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.