From 522a8c79b0704871b4c073833caf6d145b40c370 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Sun, 24 Mar 2024 14:00:21 +0000 Subject: fix(ast): parse level 1 headings with emojis --- src/ast/container.rs | 19 +++++++++---------- 1 file 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, -- cgit v1.2.3