Skip to main content

TextSegment

Struct TextSegment 

Source
pub struct TextSegment {
Show 14 fields pub start: usize, pub end: usize, pub tag: String, pub id: Option<String>, pub src: Option<String>, pub caption: Option<String>, pub indent: f32, pub styles: Vec<StyleRun>, pub list: Option<ListKind>, pub list_depth: u32, pub blockquote: BlockquoteKind, pub links: Vec<LinkRun>, pub svg: Option<String>, pub code_indent: bool,
}

Fields§

§start: usize

Inclusive start byte/char offset into the chapter text.

§end: usize

Exclusive end offset.

§tag: String

Element tag (e.g. p, h1, li, img, figure).

§id: Option<String>

The element’s id attribute if any (useful for anchoring).

§src: Option<String>

src for img/figure (None for text blocks).

§caption: Option<String>

figcaption text for a figure (None for non-figures).

§indent: f32

Left indent of the block, in em, resolved from the book’s stylesheet (see crate::html_text::style) plus any leading spaces the markup kept. 0 for ordinary prose. Serde-defaulted so offset caches written before indents existed still deserialize.

§styles: Vec<StyleRun>

Bold/italic spans within this segment, in chapter-text offsets.

§list: Option<ListKind>

For li segments: the parent list type and 1-based index.

§list_depth: u32

Nesting depth of this list item (0-based).

§blockquote: BlockquoteKind

Whether this segment is inside a <blockquote>.

§links: Vec<LinkRun>

Hyperlink destinations within this segment, in chapter-text offsets.

§svg: Option<String>

Markup for a figure the book draws inline rather than referencing as a file. src names no archive entry in that case, so the bytes have to travel with the segment. Serialised with the offset cache rather than skipped: a skipped field would make every inline diagram render on the first open of a book and vanish on the second.

§code_indent: bool

True only for an ordinary paragraph whose indent came from a Calibre code-listing margin (resolved via the IndentMap), i.e. the one case that should render as code. Table cards and nested lists also set TextSegment::indent but through other fields, so they default to false and render as prose. Serde-defaulted so offset caches written before this field existed decode as false.

Implementations§

Source§

impl TextSegment

Source

pub fn contains(&self, i: usize) -> bool

Source

pub fn list_marker(&self) -> Option<String>

The bullet or number this item draws, if any.

Nesting depth is not baked in here as leading spaces – it is carried by TextSegment::indent so the renderer insets the whole block in real pixels. Padding with spaces would only line up in a monospace face.

Trait Implementations§

Source§

impl Clone for TextSegment

Source§

fn clone(&self) -> TextSegment

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 TextSegment

Source§

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

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

impl<'de> Deserialize<'de> for TextSegment

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 TextSegment

Source§

fn eq(&self, other: &TextSegment) -> 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 TextSegment

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 TextSegment

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V