Skip to main content

Module edit

Module edit 

Source
Expand description

Body and section editing — the corpus-write primitives behind dbmd body set/append and dbmd section set/append.

Everything here is a pure &str -> String transformation over a file’s markdown BODY (the verbatim text after the frontmatter block); reading the file, the frozen-page policy, the updated re-stamp, the atomic write, and the index write-through all belong to the caller (the CLI bodies), exactly as with every other mutation.

Section addressing shares the extractor’s boundary rule via [parser::extract_section_spans] — a section runs from its heading line to the next heading at an equal-or-shallower level (an # H1 terminates a span without being a section), fenced code blocks hide headings, and the span text is verbatim. Replacing a section therefore replaces its whole subtree (deeper ###… sub-sections included), which is the same unit the read views (sections, outline, section get) present.

Newline discipline: section edits are STRUCTURAL — inserted content is newline-terminated so a following heading always starts on its own line — while append_body is RAW (the joint gains a newline when the existing body lacks one, the appended content itself rides verbatim). dbmd body set is rawer still and does not come through here: the new body is stored exactly as given.

Structs§

SectionEdit
The result of a section edit: the new body plus where the edited (or created) section sits — line is 1-based within the body, the [parser::Section::line] frame.

Enums§

EditError
A section-addressing failure. Whole-body operations cannot fail.

Functions§

append_body
Append raw content at the end of the body. The joint gains a newline when the existing body lacks one; the content itself rides verbatim.
append_section
Append a NEW section at the end of the body: one separating blank line, the #-run heading at level (2–6), then the newline-terminated content.
append_to_section
Append content at the end of the addressed section (before the next sibling-or-shallower heading), newline-terminated.
find_section
Find the one section addressed by heading (exact text match on the extracted heading, surrounding whitespace trimmed from the query).
replace_section
Replace the addressed section’s content — everything under its heading line to the span end, deeper sub-sections included — with content. The heading line itself is preserved byte-for-byte (gaining a terminating newline only when unterminated content must follow it).