Headers outside of paragraphs

This commit is contained in:
2026-07-13 23:58:20 +02:00
parent beabb0a0e4
commit 63abf43f5f
+9 -2
View File
@@ -53,8 +53,6 @@ parse_header :: proc(line: string) -> (int, string) {
parse :: proc(lines: []string, allocator := context.allocator) -> Token {
root := Token{TokenType.Root, nil, nil, nil}
current_token := &root
append(&current_token.children, Token{TokenType.Paragraph, nil, nil, current_token})
current_token = &current_token.children[0]
for untrimmed_line, line_index in lines {
line := strings.trim_space(untrimmed_line)
@@ -71,6 +69,10 @@ parse :: proc(lines: []string, allocator := context.allocator) -> Token {
header_level, text := parse_header(line)
if header_level > 0 {
if current_token.parent != nil {
current_token = current_token.parent
}
append(
&current_token.children,
Token{TokenType.Header, header_level, nil, current_token},
@@ -81,6 +83,11 @@ parse :: proc(lines: []string, allocator := context.allocator) -> Token {
continue
}
if current_token.parent == nil {
append(&current_token.children, Token{TokenType.Paragraph, nil, nil, current_token})
current_token = &current_token.children[len(current_token.children) - 1]
}
append(&current_token.children, Token{TokenType.Text, line, nil, current_token})
// lvl, text := parse_header(trimmed)