Skip to main content

ParseConfig

Struct ParseConfig 

Source
pub struct ParseConfig {
    pub emit_source_lines: bool,
    pub implicit_figure: bool,
    pub source_line_offset: usize,
    pub math: bool,
    pub hard_line_breaks: bool,
}
Expand description

Parser configuration flags.

Threaded through parse_with_config to gate optional parser behaviors that the renderer needs to coordinate with (source-line tracking for preview scroll sync, implicit-figure promotion).

Default = “production preview off” — emit_source_lines: false, implicit_figure: true. The implicit_figure default mirrors today’s always-on behavior of the parser before this config existed; flipping it off is opt-in for the small set of fragment-render call sites that need bare <img> (none today, but the flag exists for symmetry with the legacy transform_events API and the production site_config field).

Fields§

§emit_source_lines: bool

When true, populates BlockMeta::source_line for top-level blocks. The renderer emits data-source-line="N" on the opening tag for any block whose meta carries Some(N).

Production wires this from process_markdown_file’s emit_source_lines argument (true during preview builds, false during ship-stage publish builds — data-source-line is stripped at ship time anyway, but emitting fewer attrs upstream is cheaper and keeps published HTML clean from earlier stages).

§implicit_figure: bool

When true (default), image-only paragraphs promote to Block::Figure via [try_promote_to_figure]. When false, they stay as Block::Paragraph containing one Inline::Image.

Production wires this from site_config.implicit_figure (default true). The flag mirrors the legacy transform_events implicit-figure pass: sites that prefer bare <img> (no <figure> wrap) can opt out.

§source_line_offset: usize

Added to every computed source_line so the emitted data-source-line / data-source-range values match the editor’s REAL FILE line numbers (CM6 doc.lineAt), not body-relative lines.

The parser only ever sees the markdown BODY (frontmatter is stripped upstream), so its byte offsets — and thus LineLookup — are body-relative. The editor, however, reports raw-file lines including the frontmatter. Without this offset, every annotation is short by the frontmatter line count, so editor→preview scroll-sync maps to the wrong element (the home page’s grid scrolled the preview to the bottom). Set to the number of lines the frontmatter consumes (0 when there is none). See process_markdown_file and docs/reference/editor-preview-sync.md “Known defect — source-line coordinate-system mismatch”.

§math: bool

When true, $…$ / $$…$$ parse as math (Options::ENABLE_MATH) and render as escaped LaTeX source in <code class="moss-math">. When false (default), $ is an ordinary character and math source passes through as literal text.

Default is false — unlike the other flags, this one changes what the characters mean, so every in-crate parse() caller and every committed snapshot fixture keeps today’s behavior until a site opts in. Production wires it from site_config.math ([site].math, default on), which is where the “is $5 currency or an unclosed equation?” judgment belongs.

§hard_line_breaks: bool

When true, a single newline inside a paragraph renders as <br>, matching Obsidian’s default (strictLineBreaks = false, i.e. remark breaks: true). When false, CommonMark applies and the newline is a space.

Default is false for the same reason math is: it changes what the author’s characters mean, so every in-crate parse() caller and every committed fixture keeps today’s behavior until a site opts in. Production wires it from site_config.hard_line_breaks.

Trait Implementations§

Source§

impl Clone for ParseConfig

Source§

fn clone(&self) -> ParseConfig

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 Copy for ParseConfig

Source§

impl Debug for ParseConfig

Source§

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

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

impl Default for ParseConfig

Source§

fn default() -> Self

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

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.