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 ( 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: MediaKindWhether 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: StringThe 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: StringThe media’s alt text, flattened from its inline children (empty when it has none).
poster: StringA <video poster="…">’s still frame, or empty when there is none — an
image destination, resolved exactly as destination is.
Implementations§
Source§impl MediaInfo
impl MediaInfo
Sourcepub fn resolve(&self, scheme: ColorScheme) -> &str
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>.
Sourcepub fn still(&self, scheme: ColorScheme) -> Option<&str>
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.