wayver's git archive


an obsidian renderer
git clone https://git.wayver.dev/sable

sable-renderer/src/templates/funcs.rs@main

raw
Date Commit Message Author Files + -
2026-02-23 01:55 initial mvp wayverd 139 17808 0
...

1#![allow(clippy::items_after_test_module)]
2
3#[derive(Debug, Clone, PartialEq, Eq)]
4pub(super) struct Heading {
5    pub level: usize,
6    pub title: String,
7    pub children: Vec<Self>,
8}
9
10pub(super) fn extract_headings(contents: &str) -> Vec<Heading> {
11    let mut headings = Vec::new();
12    let mut in_code_block = false;
13
14    for line in contents.lines() {
15        if line.trim_start().starts_with("```") {
16            in_code_block = !in_code_block;
17            continue;
18        }
19
20        if in_code_block {
21            continue;
22        }
23
24        if line.starts_with('#') {
25            let level = line.chars().take_while(|&c| c == '#').count();
26            let title = line[level..].trim().to_string();
27
28            headings.push(Heading {
29                level,
30                title,
31                children: vec![],
32            });
33        }
34    }
35
36    headings
37}
38
39#[cfg(test)]
40mod test_extract_headings {
41    use super::extract_headings;
42
43    #[test]
44    fn test_() {}
45}
46