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: boolWhen 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: boolWhen 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: usizeAdded 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: boolWhen 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: boolWhen 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
impl Clone for ParseConfig
Source§fn clone(&self) -> ParseConfig
fn clone(&self) -> ParseConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more