fix(markup): enable handling of utf-8

Signed-off-by: Sphericalkat <amolele@gmail.com>
This commit is contained in:
Amogh Lele 2023-05-28 16:24:53 +05:30
parent 7b6e7d7edb
commit 665d33d9d3

View File

@ -36,7 +36,7 @@ func ranges(text string, markups []entities.Markup) []RangeWithMarkup {
// include the start and end indexes of the text
markupBoundaries = append([]int{0}, markupBoundaries...)
markupBoundaries = append(markupBoundaries, len(text))
markupBoundaries = append(markupBoundaries, len([]rune(text)))
// remove duplicates
markupBoundaries = unique(markupBoundaries)
@ -72,7 +72,8 @@ func ranges(text string, markups []entities.Markup) []RangeWithMarkup {
func ConvertMarkup(text string, markups []entities.Markup) string {
var markedUp strings.Builder
for _, r := range ranges(text, markups) {
textToWrap := string(text[r.Range[0]:r.Range[1]])
runeText := []rune(text) // very important otherwise we can't handle UTF-8
textToWrap := string(runeText[r.Range[0]:r.Range[1]])
markedUp.WriteString(wrapInMarkups(textToWrap, r.Markups))
}