Headers outside of paragraphs
This commit is contained in:
+9
-2
@@ -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(¤t_token.children, Token{TokenType.Paragraph, nil, nil, current_token})
|
||||
current_token = ¤t_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(
|
||||
¤t_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(¤t_token.children, Token{TokenType.Paragraph, nil, nil, current_token})
|
||||
current_token = ¤t_token.children[len(current_token.children) - 1]
|
||||
}
|
||||
|
||||
append(¤t_token.children, Token{TokenType.Text, line, nil, current_token})
|
||||
|
||||
// lvl, text := parse_header(trimmed)
|
||||
|
||||
Reference in New Issue
Block a user