Scripts
This commit is contained in:
+69
-4
@@ -14,6 +14,34 @@ get_text_content :: proc(token: ^Token, b: ^strings.Builder) {
|
||||
}
|
||||
}
|
||||
|
||||
check_only_var_defs :: proc(token: ^Token) -> bool {
|
||||
for child in token.children {
|
||||
if child.type == .VariableDef || child.type == .BreakLine {
|
||||
continue
|
||||
}
|
||||
if child.type == .Text {
|
||||
if child.value != nil {
|
||||
if v, ok := child.value.(string); ok && v != "" {
|
||||
return false
|
||||
}
|
||||
}
|
||||
has_non_var_def := false
|
||||
for gc in child.children {
|
||||
if gc.type != .VariableDef {
|
||||
has_non_var_def = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if has_non_var_def {
|
||||
return false
|
||||
}
|
||||
continue
|
||||
}
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
slugifyifyifyify :: proc(text: string) -> string {
|
||||
lower := strings.to_lower(text, context.temp_allocator)
|
||||
res, _ := strings.replace_all(lower, " ", "-", context.temp_allocator)
|
||||
@@ -51,11 +79,20 @@ print_html :: proc(token: ^Token) {
|
||||
fmt.printf("</h%d>\n", level)
|
||||
|
||||
case TokenType.Paragraph:
|
||||
fmt.print("<p>")
|
||||
for child in token.children {
|
||||
print_html(child)
|
||||
only_var_defs := check_only_var_defs(token)
|
||||
if !only_var_defs {
|
||||
fmt.print("<p>")
|
||||
for child in token.children {
|
||||
print_html(child)
|
||||
}
|
||||
fmt.print("</p>\n")
|
||||
} else {
|
||||
for child in token.children {
|
||||
if child.type != .BreakLine {
|
||||
print_html(child)
|
||||
}
|
||||
}
|
||||
}
|
||||
fmt.print("</p>\n")
|
||||
|
||||
case TokenType.Blockquote:
|
||||
fmt.print("<blockquote>\n")
|
||||
@@ -316,6 +353,34 @@ print_html :: proc(token: ^Token) {
|
||||
fmt.printf("<script src=\"%s\"></script>", url)
|
||||
}
|
||||
|
||||
case TokenType.ScriptBlock:
|
||||
if content, ok := token.value.(string); ok {
|
||||
fmt.printf("<script>%s</script>", content)
|
||||
}
|
||||
|
||||
case TokenType.Variable:
|
||||
if name, ok := token.value.(string); ok {
|
||||
fmt.printf("<span data-tlm-var=\"%s\">", name)
|
||||
for child in token.children {
|
||||
print_html(child)
|
||||
}
|
||||
fmt.print("</span>")
|
||||
}
|
||||
|
||||
case TokenType.VariableDef:
|
||||
if name, ok := token.value.(string); ok {
|
||||
b := strings.builder_make(context.temp_allocator)
|
||||
for child in token.children {
|
||||
get_text_content(child, &b)
|
||||
}
|
||||
val := strings.to_string(b)
|
||||
fmt.printf(
|
||||
"<template data-tlm-def=\"%s\" data-tlm-value=\"%s\"></template>",
|
||||
name,
|
||||
val,
|
||||
)
|
||||
}
|
||||
|
||||
case TokenType.BreakLine:
|
||||
fmt.print("<br>\n")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user