feat: Added sectionate content processor.

This commit is contained in:
Spencer Brower
2026-07-14 11:24:06 -04:00
parent d23eec448b
commit b90496b5a2
6 changed files with 76 additions and 17 deletions
+40
View File
@@ -0,0 +1,40 @@
package main
import "core:strings"
wrap_sections :: proc(html: string) -> string {
H2 :: "<h2"
parts: [dynamic]string
defer delete(parts)
pos := 0
search_pos := 0
for {
rel := strings.index(html[search_pos:], H2)
if rel < 0 {
break
}
idx := search_pos + rel
if idx > pos {
append(&parts, "<section>")
append(&parts, html[pos:idx])
append(&parts, "</section>")
}
pos = idx
search_pos = idx + len(H2)
}
if pos < len(html) {
append(&parts, "<section>")
append(&parts, html[pos:])
append(&parts, "</section>")
}
if len(parts) == 0 {
return html
}
return strings.join(parts[:], "")
}