in cqlprotodoc/spec/spec.go [212:243]
func parseBody(s string) []Text {
var body []Text
lastIdx := 0
for _, m := range linkifyRegexp.FindAllStringSubmatchIndex(s, -1) {
body = append(body, Text{Text: s[lastIdx:m[0]]})
switch {
case m[sectionSubexpIdx] != -1:
sectionNo := s[m[sectionSubexpIdx]:m[sectionSubexpIdx+1]]
body = append(body, Text{Text: s[m[0]:m[1]], SectionRef: sectionNo})
case m[sectionsSubexpIdx] != -1:
body = append(body, Text{Text: s[m[0]:m[sectionsSubexpIdx]]})
sections := s[m[sectionsSubexpIdx]:m[sectionsSubexpIdx+1]]
lastIdx2 := 0
for _, m2 := range sectionsSplitRegexp.FindAllStringIndex(sections, -1) {
sectionNo := sections[lastIdx2:m2[0]]
body = append(body, Text{Text: sectionNo, SectionRef: sectionNo})
// separator
body = append(body, Text{Text: sections[m2[0]:m2[1]]})
lastIdx2 = m2[1]
}
sectionNo := sections[lastIdx2:]
body = append(body, Text{Text: sectionNo, SectionRef: sectionNo})
default:
href := s[m[0]:m[1]]
body = append(body, Text{Text: href, Href: href})
}
lastIdx = m[1]
}
body = append(body, Text{Text: s[lastIdx:]})
return body
}