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: StringThe 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: StringThe 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: StringThe 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
impl SourceBlock
Sourcepub fn text_excluding(&self, exclude: impl Fn(&SourceInline) -> bool) -> String
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
impl Clone for SourceBlock
Source§impl Debug for SourceBlock
impl Debug for SourceBlock
impl Eq for SourceBlock
Source§impl PartialEq for SourceBlock
impl PartialEq for SourceBlock
impl StructuralPartialEq for SourceBlock
Auto Trait Implementations§
impl Forget for SourceBlock
impl Freeze for SourceBlock
impl RefUnwindSafe for SourceBlock
impl Send for SourceBlock
impl Sync for SourceBlock
impl Unpin for SourceBlock
impl UnsafeUnpin for SourceBlock
impl UnwindSafe for SourceBlock
Blanket Implementations§
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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.