Skip to main content

SourceBlock

Struct SourceBlock 

Source
pub struct SourceBlock {
    pub tag: String,
    pub id: Option<String>,
    pub class: Option<String>,
    pub attrs: Vec<(String, String)>,
    pub path: String,
    pub text: String,
    pub items: Vec<usize>,
    pub omitted: Option<BlockOmission>,
    pub inlines: Vec<SourceInline>,
}
Expand description

A block of the source document (#903, #904): the original element an item was made from — or one that produced no item, with the reason — so a caller can tie converted items back to the source, tell two identical texts apart, and read a block’s text on its own terms, free of any serializer’s separators.

The HTML backend enumerates, in document order, every element that produced an item, every non-inline element with text of its own (text nodes reached through inline elements only — a <span>’s text belongs to the block around it), and every empty <p>, heading, <li>, <dt>, <dd>, <td>/<th>, <pre> or <caption>. Pure containers (a layout <div> with nothing but blocks inside) are not blocks. Every text node of the source thus belongs to exactly one block.

Fields§

§tag: String

The element’s tag name (p, div, li, table, img, …).

§id: Option<String>

Its id attribute, when it has one.

§class: Option<String>

Its class attribute, as written.

§attrs: Vec<(String, String)>

Every attribute of the element, by name (#910): id and class among them, and whatever else the source put there — style, aria-hidden, a RIS element’s typ.

§path: String

The element’s path from the document root — each step the tag and the 1-based position among the parent’s same-tag element children, html/body/div[3]/p[1] — stable for the document and unique to the element, with or without an id.

§text: String

The block’s own text: its text nodes (and those of the inline elements inside it, not of nested blocks) in source order, whitespace runs collapsed to one space, trimmed. Independent of what the items made of it hold — a hidden block’s text is here too.

§items: Vec<usize>

The items made from this block, in creation order — the top-level ones (an inline group, not the runs inside it; a list group, not its items, which have their <li> blocks). Empty when it produced none: see omitted.

§omitted: Option<BlockOmission>

Why no item was made from this block; None when items is not empty.

§inlines: Vec<SourceInline>

The inline elements inside the block (#911) — a <span class="sr-only">, a <b>, an <a> — each with its range in text, in document order, nested ones after the ones they sit in.

Implementations§

Source§

impl SourceBlock

Source

pub fn text_excluding(&self, exclude: impl Fn(&SourceInline) -> bool) -> String

The block’s text without the inline elements exclude selects (#911): their ranges cut out, whitespace normalized again. A screen-reader alternative (.sr-only) left out, say — the caller chooses, nothing is inferred from a class.

Trait Implementations§

Source§

impl Clone for SourceBlock

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 SourceBlock

Source§

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

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

impl Eq for SourceBlock

Source§

impl PartialEq for SourceBlock

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 StructuralPartialEq for SourceBlock

Auto Trait Implementations§

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> 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 = !

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.