Skip to main content

decode_document

Function decode_document 

Source
pub fn decode_document(text: &str) -> DocValue
Expand description

Parse document text into a DocValue, recording per-block byte offsets and heading paths.

Headings are #-prefixed lines (levels 1-6); everything else groups into paragraphs split on blank lines. The format is reported as DocFormat::Markdown when any heading is present, otherwise DocFormat::Text. The returned value’s text is the input verbatim.

§Examples

use sim_codec_doc::{DocBlockKind, DocFormat, decode_document};

let doc = decode_document("# Guide\n\nAlpha beta.\n");
assert_eq!(doc.format, DocFormat::Markdown);
assert_eq!(doc.blocks.len(), 2);
assert_eq!(doc.blocks[0].kind, DocBlockKind::Heading);
assert_eq!(doc.blocks[1].text, "Alpha beta.");
assert_eq!(doc.blocks[1].heading_path, vec!["Guide".to_owned()]);