package uiimport ()// StylingRegion represents a region to apply styling.typeStylingRegionstruct {diag.RangingStylingStylingPriorityint}// StyleRegions applies styling to the specified regions in s.//// The regions are sorted by start position. If multiple Regions share the same// starting position, the one with the highest priority is kept; the other// regions are removed. If a Region starts before the end of the previous// Region, it is also removed.func ( string, []StylingRegion) Text { = fixRegions()varText := 0for , := range {if .From > {// Add text between regions or before the first region. = append(, &Segment{Text: [:.From]}) } = append(,StyleSegment(&Segment{Text: [.From:.To]}, .Styling)) = .To }iflen() > {// Add text after the last region. = append(, &Segment{Text: [:]}) }return}func ( []StylingRegion) []StylingRegion { = append([]StylingRegion(nil), ...)// Sort regions by their start positions. Regions with the same start // position are sorted by decreasing priority.sort.Slice(, func(, int) bool { , := [], []return .From < .From || (.From == .From && .Priority > .Priority) })// Remove overlapping regions, preferring the ones that appear earlier.var []StylingRegion := 0for , := range {if .From < {// Overlaps with the last onecontinue } = append(, ) = .To }return}
The pages are generated with Goldsv0.2.8-preview. (GOOS=darwin GOARCH=arm64)