mirror of
https://github.com/sbrow/thor.git
synced 2026-08-26 11:23:32 -04:00
feat: Added sectionate content processor.
This commit is contained in:
@@ -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[:], "")
|
||||
}
|
||||
Reference in New Issue
Block a user