Bold an italics (super scuffed)
This commit is contained in:
@@ -59,7 +59,66 @@ pass_through_children :: proc(token: ^Token) {
|
||||
}
|
||||
|
||||
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])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user