Skip to main content

Document

Struct Document 

Source
pub struct Document {
    pub blocks: Vec<Block>,
    pub block_meta: Vec<BlockMeta>,
    pub slot_only: bool,
    pub warnings: Vec<String>,
}
Expand description

A parsed markdown document body.

Wraps Vec<Block> with document-level flags. The frontmatter sits in crate::frontmatter::ParsedDocument; this struct is body-only. Higher-level code combines the two as needed.

Fields§

§blocks: Vec<Block>

Body content as a flat list of block-level nodes.

§block_meta: Vec<BlockMeta>

Parallel-to-blocks metadata. Invariant: block_meta.len() == blocks.len(). The renderer asserts this in debug builds and gracefully degrades (treats missing entries as BlockMeta::default()) in release builds.

Defaults to an all-BlockMeta::default() vec sized to match blocks when constructed via Document::from_blocks; only the parser populates source_line (under crate::ast::ParseConfig::emit_source_lines).

§slot_only: bool

True if this document is a slot file (e.g. footer.md) — its content fills a layout slot rather than being rendered as an article. The renderer suppresses auto-injected article chrome (<h1 class="moss-article-title">) when this is set.

Replaces the heading: false YAML synthesis hack at src-tauri/src/build/footer.rs:160. Lands in Phase A.5 of the typed-AST migration; in Phase A it’s available but not yet consumed by src-tauri.

§warnings: Vec<String>

Non-fatal problems found while parsing this body — today, every :::name fence whose name is not a registered shortcode.

The extractor has collected these since the unknown-name fallback landed, but nothing carried them out of the parse, so the only trace a misspelling left was a moss-unknown-shortcode div in the built HTML. An author (or an agent) got a page that had silently lost its gallery and a build that said nothing. This field is that missing hop; build::markdown::pipeline prints each entry against the file.

Scope, precisely: top-level fences, fences nested inside an unknown fence (that branch recurses through extract_with_state, threading one collection), AND fences nested inside a valid shortcode’s body — grid cells (parse_cell_to_blocks) and the hero overlay (parse_overlay_to_blocks) each re-parse their body as an independent fragment via parse_fragment_with_config; both now return that fragment Document’s warnings alongside its blocks, and parse_shortcode_block merges them into the Vec<String> it already threads into extract_with_state’s shared collection. So a misspelling inside :::grid or :::hero warns exactly like a top-level one; see unknown_shortcode_inside_a_valid_shortcode_warns and unknown_shortcode_inside_a_hero_overlay_warns.

Implementations§

Source§

impl Document

Source

pub fn new() -> Self

Construct an empty document.

Source

pub fn from_blocks(blocks: Vec<Block>) -> Self

Construct a document from a list of blocks. All block_meta entries are default (no source-line tracking). Use Document::from_blocks_with_meta when meta is known.

Source

pub fn from_blocks_with_meta( blocks: Vec<Block>, block_meta: Vec<BlockMeta>, ) -> Self

Construct a document from blocks + parallel meta. Panics in debug if the two slices have different lengths.

Source

pub fn has_shortcode(&self, kind: ShortcodeKind) -> bool

True if any top-level block is a shortcode of the given kind.

Shallow check: does NOT descend into nested blocks (e.g. a :::subscribe inside a :::grid cell would not be found by this query alone). Phase A models the shallow case; deeper has_shortcode_recursive lands when nested-shortcode AST queries are first needed.

Trait Implementations§

Source§

impl Clone for Document

Source§

fn clone(&self) -> Document

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 Document

Source§

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

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

impl Default for Document

Source§

fn default() -> Document

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Document

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 Eq for Document

Source§

impl PartialEq for Document

Source§

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

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 Document

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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