zyedidia / highlight

A Go package for syntax highlighting
Other
55 stars 32 forks source link

[Question] How to intelligently deal with runes as part of a highlighted line? #9

Closed japanoise closed 7 years ago

japanoise commented 7 years ago
runestring := "This… String" + " has → " + "runes in it"

Currently code like the above in my program causes a lot of graphical glitches; i.e. areas of the line getting highlighted the wrong colour. How can I iterate through characters in the string and avoid this? Perhaps as some variation on the range?

japanoise commented 7 years ago

Actually, not to worry. For anyone interested, the colors are stored in such a way that indexes must be the index of the rune in the string; that is the indexes in a string "…runes" would be:

0: …
1: r
2: u
3: n
4: e
5: s

...rather than the first couple of indices being the bytes needed to represent '…'.

This is different to what I expected, but workable.