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
+2
View File
@@ -27,3 +27,5 @@ The **VARIABLE** is $(variable)
> This is a sample blockquote > This is a sample blockquote
> Bon apetit! > Bon apetit!
Text under a blockquote
+1 -1
View File
@@ -16,7 +16,7 @@ get_ext :: proc(url: string) -> string {
return "" return ""
} }
detect_type :: proc(url: string) -> string { detect_embed_type :: proc(url: string) -> string {
ext := get_ext(url) ext := get_ext(url)
switch ext { switch ext {
case ".jpg", case ".jpg",
+2
View File
@@ -29,6 +29,8 @@ print_token :: proc(token: Token, depth: int = 0) {
type_str = "Header" type_str = "Header"
case TokenType.Paragraph: case TokenType.Paragraph:
type_str = "Paragraph" type_str = "Paragraph"
case TokenType.Blockquote:
type_str = "Blockquote"
} }
value_str := "" value_str := ""
+20 -14
View File
@@ -11,6 +11,7 @@ TokenType :: enum {
Header, Header,
Paragraph, Paragraph,
Root, Root,
Blockquote,
} }
TokenValue :: union { TokenValue :: union {
@@ -90,26 +91,31 @@ parse :: proc(lines: []string, allocator := context.allocator) -> Token {
continue 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 { if current_token.parent == nil {
append(&current_token.children, Token{TokenType.Paragraph, nil, nil, current_token}) append(&current_token.children, Token{TokenType.Paragraph, nil, nil, current_token})
current_token = &current_token.children[len(current_token.children) - 1] 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}) 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 return root