Lift an intent from its frontmatter spine and markdown body.
(frontmatter: &Map<String, Value>, body: &str)
| 37 | |
| 38 | /// Lift an intent from its frontmatter spine and markdown body. |
| 39 | pub fn lift_intent(frontmatter: &Map<String, Value>, body: &str) -> Result<CanonicalNode> { |
| 40 | directive::check_embedded_directives(body)?; |
| 41 | let human_key = require_str(frontmatter, "id")?; |
| 42 | let uid = opt_str(frontmatter, "uid").unwrap_or_else(|| slug(&human_key)); |
| 43 | let node_id = format!("urn:atomic:intent:{uid}"); |
| 44 | |
| 45 | let directives = directive::parse(body)?; |
| 46 | |
| 47 | let mut why = None; |
| 48 | let mut acs = Vec::new(); |
| 49 | let mut tasks = Vec::new(); |
| 50 | let mut scope_in = Vec::new(); |
| 51 | let mut scope_out = Vec::new(); |
| 52 | let mut constraints = Vec::new(); |
| 53 | let mut deps = Vec::new(); |
| 54 | let mut ac_n = 0usize; |
| 55 | let mut task_n = 0usize; |
| 56 | let mut scope_in_n = 0usize; |
| 57 | let mut scope_out_n = 0usize; |
| 58 | let mut constraint_n = 0usize; |
| 59 | |
| 60 | for d in &directives { |
| 61 | // Inline (and nested-leaf) `:ref` children of any container sit on the |
| 62 | // intent's dependency chain, same rules as a top-level `:::ref`. The |
| 63 | // container prose keeps the inline mention verbatim. |
| 64 | for child in &d.children { |
| 65 | if child.name == "ref" { |
| 66 | deps.push(lift_ref(child)?); |
| 67 | } |
| 68 | } |
| 69 | match d.name.as_str() { |
| 70 | "why" => { |
| 71 | // Single authoring site: first `:::why` wins; the reason is |
| 72 | // unconstrained prose, lifted verbatim, never inspected. |
| 73 | if why.is_none() { |
| 74 | why = Some(d.body.clone()); |
| 75 | } |
| 76 | } |
| 77 | "acceptance-criterion" => { |
| 78 | ac_n += 1; |
| 79 | acs.push(lift_ac(d, &human_key, ac_n)?); |
| 80 | } |
| 81 | "task" => { |
| 82 | task_n += 1; |
| 83 | tasks.push(lift_task(d, &human_key, task_n)); |
| 84 | } |
| 85 | "scope-in" => { |
| 86 | scope_in_n += 1; |
| 87 | scope_in.push(lift_scope(d, &human_key, "scope-in", scope_in_n)); |
| 88 | } |
| 89 | "scope-out" => { |
| 90 | scope_out_n += 1; |
| 91 | scope_out.push(lift_scope(d, &human_key, "scope-out", scope_out_n)); |
| 92 | } |
| 93 | "constraint" => { |
| 94 | constraint_n += 1; |
| 95 | constraints.push(lift_constraint(d, &human_key, constraint_n)); |
| 96 | } |