refactor: Moved markdown code to a separate packge.

This commit is contained in:
Spencer Brower
2026-07-17 14:13:25 -04:00
parent 618fabf0e4
commit 085811b312
10 changed files with 112 additions and 100 deletions
+44
View File
@@ -0,0 +1,44 @@
package markdown
import "core:strings"
wrap_sections :: proc(html: string) -> string {
H2 :: "<h2"
sb := strings.builder_make()
defer strings.builder_destroy(&sb)
pos := 0
search_pos := 0
found := false
for {
rel := strings.index(html[search_pos:], H2)
if rel < 0 {
break
}
idx := search_pos + rel
found = true
if idx > pos {
strings.write_string(&sb, "<section>")
strings.write_string(&sb, html[pos:idx])
strings.write_string(&sb, "</section>")
}
pos = idx
search_pos = idx + len(H2)
}
if pos < len(html) {
strings.write_string(&sb, "<section>")
strings.write_string(&sb, html[pos:])
strings.write_string(&sb, "</section>")
found = true
}
if !found {
return html
}
return strings.to_string(sb)
}