Skip to content

Commit

Permalink
fix(ast): parse level 1 headings with emojis
Browse files Browse the repository at this point in the history
  • Loading branch information
Fuwn committed Mar 24, 2024
1 parent d1460de commit 6a859ea
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/ast/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 6a859ea

Please sign in to comment.