55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
package topdata
|
|
|
|
import "strings"
|
|
|
|
func normalizePreservedSectionBodies(content string) string {
|
|
var out strings.Builder
|
|
offset := 0
|
|
for {
|
|
startRel := strings.Index(content[offset:], manualStartMarkerPrefix)
|
|
if startRel < 0 {
|
|
out.WriteString(content[offset:])
|
|
break
|
|
}
|
|
start := offset + startRel
|
|
startEndRel := strings.Index(content[start:], "-->")
|
|
if startEndRel < 0 {
|
|
out.WriteString(content[offset:])
|
|
break
|
|
}
|
|
startMarker := content[start : start+startEndRel+len("-->")]
|
|
id := markerID(startMarker)
|
|
if id == "" {
|
|
out.WriteString(content[offset : start+len(startMarker)])
|
|
offset = start + len(startMarker)
|
|
continue
|
|
}
|
|
endPrefix := manualEndMarkerPrefix + " id=\"" + id + "\""
|
|
endRel := strings.Index(content[start+len(startMarker):], endPrefix)
|
|
if endRel < 0 {
|
|
out.WriteString(content[offset:])
|
|
break
|
|
}
|
|
end := start + len(startMarker) + endRel
|
|
endEndRel := strings.Index(content[end:], "-->")
|
|
if endEndRel < 0 {
|
|
out.WriteString(content[offset:])
|
|
break
|
|
}
|
|
endMarker := content[end : end+endEndRel+len("-->")]
|
|
out.WriteString(content[offset:start])
|
|
out.WriteString(startMarker)
|
|
out.WriteString("\n<!-- preserved-section-body -->\n")
|
|
out.WriteString(endMarker)
|
|
offset = end + len(endMarker)
|
|
}
|
|
return out.String()
|
|
}
|
|
|
|
func defaultWikiManualSections() []wikiManualSection {
|
|
return []wikiManualSection{
|
|
{ID: "user_top", Alias: "UserTopSection", Heading: "", InitialHTML: "<p></p>"},
|
|
{ID: "user_bottom", Alias: "UserBottomSection", Heading: "", InitialHTML: "<p></p>"},
|
|
}
|
|
}
|