Blockquote parsing
This commit is contained in:
@@ -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
@@ -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",
|
||||||
|
|||||||
@@ -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
@@ -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(
|
||||||
|
¤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 {
|
if current_token.parent == nil {
|
||||||
append(¤t_token.children, Token{TokenType.Paragraph, nil, nil, current_token})
|
append(¤t_token.children, Token{TokenType.Paragraph, nil, nil, current_token})
|
||||||
current_token = ¤t_token.children[len(current_token.children) - 1]
|
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})
|
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
|
return root
|
||||||
|
|||||||
Reference in New Issue
Block a user