Phase 1 Wiki Template refactor
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
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: "notes", Alias: "UserBottomSection", Heading: "Notes", InitialHTML: "<h2>Notes</h2><p></p>"},
|
||||
{ID: "see_also", Heading: "See Also", InitialHTML: "<h2>See Also</h2><p></p>"},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user