From 28581ff44e9b6d98879807ecc78c8cd709af371a Mon Sep 17 00:00:00 2001 From: Fuwn Date: Thu, 11 Sep 2025 05:57:01 +0000 Subject: fix(ast): Improve UTF-8 handling --- src/ast/container.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/ast/container.rs b/src/ast/container.rs index bf4166c..46c548b 100644 --- a/src/ast/container.rs +++ b/src/ast/container.rs @@ -224,10 +224,14 @@ impl Ast { nodes.push(Node::Heading { level, - // Here, we are `get`ing the `&str` starting at the `level`-th - // index, then trimming the start. These operations - // effectively off the line identifier. - text: line.get(level..).unwrap_or("").trim_start().to_string(), + // Here, the text after the heading markers is safely extracted. + // `chars().skip()` is used to safely handle UTF-8 boundaries. + text: line + .chars() + .skip(level) + .collect::() + .trim_start() + .to_string(), }); break; -- cgit v1.2.3