Fix footnotes. Again.
This commit is contained in:
+26
-3
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import "core:fmt"
|
||||
import "core:strings"
|
||||
import "core:unicode"
|
||||
|
||||
escape_html :: proc(s: string, allocator := context.temp_allocator) -> string {
|
||||
b := strings.builder_make(allocator)
|
||||
@@ -62,8 +63,30 @@ check_only_var_defs :: proc(token: ^Token) -> bool {
|
||||
}
|
||||
|
||||
slugifyifyifyify :: proc(text: string) -> string {
|
||||
lower := strings.to_lower(text, context.temp_allocator)
|
||||
res, _ := strings.replace_all(lower, " ", "-", context.temp_allocator)
|
||||
b := strings.builder_make(context.temp_allocator)
|
||||
|
||||
for ch in text {
|
||||
lower_ch := unicode.to_lower(ch)
|
||||
|
||||
if unicode.is_letter(lower_ch) || unicode.is_digit(lower_ch) {
|
||||
strings.write_rune(&b, lower_ch)
|
||||
} else if lower_ch == ' ' || lower_ch == '_' || lower_ch == '-' {
|
||||
strings.write_rune(&b, '-')
|
||||
}
|
||||
}
|
||||
|
||||
res := strings.to_string(b)
|
||||
|
||||
for {
|
||||
new_res, replaced := strings.replace_all(res, "--", "-", context.temp_allocator)
|
||||
if !replaced {
|
||||
break
|
||||
}
|
||||
res = new_res
|
||||
}
|
||||
|
||||
res = strings.trim(res, "-")
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
@@ -91,7 +114,7 @@ print_html :: proc(token: ^Token) {
|
||||
}
|
||||
slug := slugifyifyifyify(strings.to_string(b))
|
||||
|
||||
fmt.printf("<h%d id=\"%s\">", level, slug)
|
||||
fmt.printf("<h%d id=\"%s\">", level, escape_html(slug))
|
||||
for child in token.children {
|
||||
print_html(child)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user