From 3651d5b6d063f9b441a27aaa9df9c7beb0256ce3 Mon Sep 17 00:00:00 2001 From: "N0\\A" Date: Tue, 14 Jul 2026 00:29:38 +0200 Subject: [PATCH] Blockquote parsing --- README.tlm | 2 ++ src/embed.odin | 2 +- src/main.odin | 2 ++ src/parser.odin | 34 ++++++++++++++++++++-------------- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/README.tlm b/README.tlm index e3d90a4..840e05f 100644 --- a/README.tlm +++ b/README.tlm @@ -27,3 +27,5 @@ The **VARIABLE** is $(variable) > This is a sample blockquote > Bon apetit! + +Text under a blockquote diff --git a/src/embed.odin b/src/embed.odin index d10c6bd..0aaf3bb 100644 --- a/src/embed.odin +++ b/src/embed.odin @@ -16,7 +16,7 @@ get_ext :: proc(url: string) -> string { return "" } -detect_type :: proc(url: string) -> string { +detect_embed_type :: proc(url: string) -> string { ext := get_ext(url) switch ext { case ".jpg", diff --git a/src/main.odin b/src/main.odin index 5046078..4e4d90a 100644 --- a/src/main.odin +++ b/src/main.odin @@ -29,6 +29,8 @@ print_token :: proc(token: Token, depth: int = 0) { type_str = "Header" case TokenType.Paragraph: type_str = "Paragraph" + case TokenType.Blockquote: + type_str = "Blockquote" } value_str := "" diff --git a/src/parser.odin b/src/parser.odin index b0156e0..6c2803c 100644 --- a/src/parser.odin +++ b/src/parser.odin @@ -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, "", lvl) - // strings.write_string(&builder, text) - // fmt.sbprintf(&builder, "", lvl) - // } else { - // strings.write_string(&builder, text) - // strings.write_string(&builder, "
") - // } - - // strings.write_string(&builder, "\n") } return root