diff options
| author | Fuwn <[email protected]> | 2024-03-24 14:00:21 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-03-24 14:00:21 +0000 |
| commit | 522a8c79b0704871b4c073833caf6d145b40c370 (patch) | |
| tree | 5fb63731bf3a958130842c8e19f139eaca1fcfcf /src | |
| parent | fix(meta): use generic lifetime for initialiser (diff) | |
| download | germ-522a8c79b0704871b4c073833caf6d145b40c370.tar.xz germ-522a8c79b0704871b4c073833caf6d145b40c370.zip | |
fix(ast): parse level 1 headings with emojis
Diffstat (limited to 'src')
| -rw-r--r-- | src/ast/container.rs | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/src/ast/container.rs b/src/ast/container.rs index d3f6f5a..51931c6 100644 --- a/src/ast/container.rs +++ b/src/ast/container.rs @@ -183,16 +183,15 @@ impl Ast { "#" => { // If the Gemtext line starts with an "#", it is a heading, so let's // find out how deep it goes. - let level = line.get(0..3).map_or(0, |root| { - if root.contains("###") { - 3 - } else if root.contains("##") { - 2 - } else { - // Converting the boolean response of `contains` to an integer - usize::from(root.contains('#')) - } - }); + let level = + line.trim_start().chars().take_while(|&c| c == '#').count(); + let level = if level > 0 + && line.chars().nth(level).map_or(true, char::is_whitespace) + { + level + } else { + 0 + }; nodes.push(Node::Heading { level, |