Skip to main content

MediaInfo

Struct MediaInfo 

Source
pub struct MediaInfo {
    pub rows_span: Range<usize>,
    pub kind: MediaKind,
    pub destination: String,
    pub sources: Vec<MediaSource>,
    pub alt: String,
    pub poster: String,
}
Expand description

A block-level image (![alt](url) on its own line), named by the single VisualMap::rows row it occupies.

Like CodeBlockInfo, the row is the block’s default rendering — a plain surface paints the 🖼 alt placeholder glyphs as-is. An image-capable frontend instead skips the row in rows_span and paints the resolved picture there, exactly as it skips a TableInfo’s box-drawn rows. Derived from [VRow::image] by [media_spans], so it survives the row reuse of BlockCache and build_spliced.

Fields§

§rows_span: Range<usize>

The VisualMap::rows rows this media’s placeholder occupies — what a capable frontend replaces with the picture or player.

§kind: MediaKind

Whether this is a picture, a movie, or a sound — which widget the frontend builds over rows_span. A frontend that handles only some kinds leaves the rest as core’s placeholder rows, which already read sensibly on their own.

§destination: String

The media’s link destination — a path, URL, or data: URI, verbatim from the AST. A frontend resolves a relative path against the document’s own directory; core does no I/O. For a <picture> this is the <img> fallback — the source used when no sources media query matches (or the frontend has no theme). Empty when a <video>/ <audio> carries no src and names its candidates in <source>s instead; resolve already accounts for that.

§sources: Vec<MediaSource>

The <source> alternatives in document order, or empty for a plain image. See MediaSource; a theme- or codec-aware frontend picks one and otherwise loads destination.

§alt: String

The media’s alt text, flattened from its inline children (empty when it has none).

§poster: String

A <video poster="…">’s still frame, or empty when there is none — an image destination, resolved exactly as destination is.

Implementations§

Source§

impl MediaInfo

Source

pub fn resolve(&self, scheme: ColorScheme) -> &str

The image URL to load under scheme: the first sources <source> whose media query matches, else the destination <img> fallback. The pick is a <source>’s first srcset URL or the destination — a frontend resolves whichever it gets against the document directory exactly as it resolves destination, and reserves/keys the picture under destination regardless, so a theme switch just re-picks without disturbing the layout.

Only prefers-color-scheme is understood (that’s what a light/dark banner uses); a <source> with any other media query is skipped, and one with no media at all always matches (an unconditional override). With no matching source — including every frontend that can’t/doesn’t theme and passes ColorScheme::Light to a dark-only picture — it’s the plain <img>.

Source

pub fn still(&self, scheme: ColorScheme) -> Option<&str>

The still picture that stands for this media under scheme, for a frontend that can rasterize an image but not play a movie — a terminal, or a GUI still growing its player. None when there is no picture to draw, which is the honest answer for audio and for a poster-less video: the caller leaves core’s labelled placeholder row, which already reads as a thing that isn’t text.

This exists so those frontends never hand a .mp4 to an image decoder. That fails harmlessly today (a failed decode falls back to the same placeholder), but it spends a file read and a decode attempt per frame to arrive where this gets in one match.

Trait Implementations§

Source§

impl Clone for MediaInfo

Source§

fn clone(&self) -> MediaInfo

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 MediaInfo

Source§

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

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

impl Eq for MediaInfo

Source§

impl PartialEq for MediaInfo

Source§

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

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<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 = 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.