Blockquote parsing
This commit is contained in:
+20
-14
@@ -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(
|
||||
¤t_token.children,
|
||||
Token{TokenType.Blockquote, nil, nil, current_token},
|
||||
)
|
||||
current_token = ¤t_token.children[len(current_token.children) - 1]
|
||||
}
|
||||
append(¤t_token.children, Token{TokenType.Text, text[2:], nil, current_token})
|
||||
continue
|
||||
}
|
||||
|
||||
// LAST-CASE SCENARIO: NORMAL TEXT
|
||||
|
||||
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]
|
||||
}
|
||||
|
||||
#partial switch current_token.parent.type {
|
||||
case TokenType.Blockquote:
|
||||
current_token = current_token.parent
|
||||
}
|
||||
|
||||
append(¤t_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
|
||||
|
||||
Reference in New Issue
Block a user