Skip to main content

parse

Function parse 

Source
pub fn parse(text: &str) -> Option<Parsed>
Expand description

Parse a concept’s leading frontmatter, or None when the text does not open with a --- fence (the only frontmatter form OKF defines).

Recognised scalar fields are typed; tags accepts both the flow form (tags: [a, b]) and the block form (tags: then - a). parseable is set by handing the inner block to yaml-edit, which is what conformance checks for; field extraction itself is lenient.

§Examples

use coding_tools::okf::parse;

let doc = "---\ntype: Playbook\ntitle: Onboarding\ntags: [ops, hr]\n---\n# Steps\n";
let p = parse(doc).unwrap();
assert_eq!(p.fm.type_.as_deref(), Some("Playbook"));
assert_eq!(p.fm.tags, ["ops", "hr"]);
assert!(p.parseable);
assert_eq!(p.body_start_line, 6);

assert!(parse("# no frontmatter here\n").is_none());