Blockquote parsing

This commit is contained in:
2026-07-14 00:29:38 +02:00
parent 943aeef332
commit 3651d5b6d0
4 changed files with 25 additions and 15 deletions
+20 -14
View File
@@ -11,6 +11,7 @@ TokenType :: enum {
Header,
Paragraph,
Root,
Blockquote,
}
TokenValue :: union {
@@ -90,26 +91,31 @@ parse :: proc(lines: []string, allocator := context.allocator) -> Token {
continue
}
if text[0:2] == "> " {
if current_token.type != TokenType.Blockquote {
append(
&current_token.children,
Token{TokenType.Blockquote, nil, nil, current_token},
)
current_token = &current_token.children[len(current_token.children) - 1]
}
append(&current_token.children, Token{TokenType.Text, text[2:], nil, current_token})
continue
}
// LAST-CASE SCENARIO: NORMAL TEXT
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]
}
#partial switch current_token.parent.type {
case TokenType.Blockquote:
current_token = current_token.parent
}
append(&current_token.children, Token{TokenType.Text, line, nil, current_token})
// lvl, text := parse_header(trimmed)
// is_header := lvl > 0
// if is_header {
// fmt.sbprintf(&builder, "<h%d>", lvl)
// strings.write_string(&builder, text)
// fmt.sbprintf(&builder, "</h%d>", lvl)
// } else {
// strings.write_string(&builder, text)
// strings.write_string(&builder, "<br>")
// }
// strings.write_string(&builder, "\n")
}
return root