Unordered lists

This commit is contained in:
2026-07-14 13:41:51 +02:00
parent 70a1434b56
commit b4f5285a99
2 changed files with 19 additions and 0 deletions
+6
View File
@@ -31,6 +31,12 @@ print_token :: proc(token: ^Token, depth: int = 0) {
type_str = "Paragraph" type_str = "Paragraph"
case TokenType.Blockquote: case TokenType.Blockquote:
type_str = "Blockquote" type_str = "Blockquote"
case TokenType.UnorderedList:
type_str = "UnorderedList"
case TokenType.OrderedList:
type_str = "OrderedList"
case TokenType.ListItem:
type_str = "ListItem"
} }
value_str := "" value_str := ""
+13
View File
@@ -11,6 +11,9 @@ TokenType :: enum {
Paragraph, Paragraph,
Root, Root,
Blockquote, Blockquote,
UnorderedList,
OrderedList,
ListItem,
} }
TokenValue :: union { TokenValue :: union {
@@ -79,6 +82,16 @@ parse :: proc(lines: []string, allocator := context.allocator) -> Token {
continue continue
} }
if strings.has_prefix(text, ". ") || strings.has_prefix(text, "- ") {
if current_token.type != TokenType.UnorderedList {
current_token = push_token(&root, TokenType.UnorderedList, nil)
}
current_token = push_token(current_token, TokenType.ListItem, nil)
push_token(current_token, TokenType.Text, text[2:])
current_token = current_token.parent
continue
}
// LAST-CASE SCENARIO: NORMAL TEXT // LAST-CASE SCENARIO: NORMAL TEXT
if current_token.parent == nil { if current_token.parent == nil {