match numbers and letters on highlight.

This commit is contained in:
fiatjaf
2023-12-31 15:23:32 -03:00
parent 5bc8b5bbde
commit d1d172b96c

View File

@@ -487,7 +487,7 @@ func shapeText(rawText []rune, fontSize int) (shaping.Output, []bool, []hlstate)
case hlNormal:
if glyph.Codepoint == '#' &&
len(buf.Info) > i+1 &&
unicode.In(buf.Info[i+1].Codepoint, unicode.Letter) {
unicode.In(buf.Info[i+1].Codepoint, unicode.Nl) {
hlState = hlHashtag
} else if glyph.Codepoint == 'h' &&
len(buf.Info) > i+1 &&
@@ -509,7 +509,8 @@ func shapeText(rawText []rune, fontSize int) (shaping.Output, []bool, []hlstate)
}
} else if glyph.Codepoint == '@' &&
len(buf.Info) > i+1 &&
unicode.In(buf.Info[i+1].Codepoint, unicode.Letter) {
unicode.In(buf.Info[i+1].Codepoint,
unicode.Nl, unicode.Number) {
hlState = hlMention
}
case hlLink:
@@ -518,11 +519,11 @@ func shapeText(rawText []rune, fontSize int) (shaping.Output, []bool, []hlstate)
hlState = hlNormal
}
case hlMention:
if !unicode.In(glyph.Codepoint, unicode.Letter) {
if !unicode.In(glyph.Codepoint, unicode.Nl) {
hlState = hlNormal
}
case hlHashtag:
if !unicode.In(glyph.Codepoint, unicode.Letter) {
if !unicode.In(glyph.Codepoint, unicode.Nl) {
hlState = hlNormal
}
}