Bold an italics (super scuffed)

This commit is contained in:
2026-07-14 15:18:34 +02:00
parent e61011ca5f
commit 1bbeebf1a3
2 changed files with 61 additions and 0 deletions
+2
View File
@@ -29,3 +29,5 @@ The **VARIABLE** is $(variable)
> Bon apetit! > Bon apetit!
Text under a blockquote Text under a blockquote
**This *is* bold *and* italics *mixed** TOGETHER*
+59
View File
@@ -59,7 +59,66 @@ pass_through_children :: proc(token: ^Token) {
} }
if token.type == TokenType.Text { if token.type == TokenType.Text {
str, ok := token.value.(string)
if !ok || !strings.contains(str, "*") {
return
}
token.value = nil
is_bold := false
is_italic := false
current_node := token
i := 0
start := 0
for i < len(str) {
if str[i] == '*' {
if i > start {
push_token(current_node, TokenType.Text, str[start:i])
}
asterisks := 0
for i < len(str) && str[i] == '*' {
asterisks += 1
i += 1
}
for asterisks >= 3 {
is_bold = !is_bold
is_italic = !is_italic
asterisks -= 3
}
if asterisks == 2 {
is_bold = !is_bold
} else if asterisks == 1 {
is_italic = !is_italic
}
current_node = token
if is_bold {
last :=
current_node.children[len(current_node.children) - 1] if len(current_node.children) > 0 else nil
current_node =
last if last != nil && last.type == .Bold else push_token(current_node, TokenType.Bold, nil)
}
if is_italic {
last :=
current_node.children[len(current_node.children) - 1] if len(current_node.children) > 0 else nil
current_node =
last if last != nil && last.type == .Italics else push_token(current_node, TokenType.Italics, nil)
}
start = i
} else {
i += 1
}
}
if i > start {
push_token(current_node, TokenType.Text, str[start:i])
}
} }
} }