FetchRangedExcerpt returns a ranged excerpt from the HTML string. Note: offset is a rune index, not a byte index
(html, trimMarker string, offset int, limit int)
| 151 | // FetchRangedExcerpt returns a ranged excerpt from the HTML string. |
| 152 | // Note: offset is a rune index, not a byte index |
| 153 | func FetchRangedExcerpt(html, trimMarker string, offset int, limit int) (text string) { |
| 154 | if len(html) == 0 { |
| 155 | text = html |
| 156 | return |
| 157 | } |
| 158 | |
| 159 | runeText := []rune(ClearText(html)) |
| 160 | begin, end := getRuneRange(runeText, offset, limit) |
| 161 | text = string(runeText[begin:end]) |
| 162 | |
| 163 | if begin > 0 { |
| 164 | text = trimMarker + text |
| 165 | } |
| 166 | if end < len(runeText) { |
| 167 | text += trimMarker |
| 168 | } |
| 169 | |
| 170 | return |
| 171 | } |
| 172 | |
| 173 | // FetchMatchedExcerpt returns the matched excerpt according to the words |
| 174 | func FetchMatchedExcerpt(html string, words []string, trimMarker string, trimLength int) string { |