From a08db23a31b5c2fb6535ebe0977a7420848019b8 Mon Sep 17 00:00:00 2001 From: Bernhard B Date: Sun, 16 Aug 2026 22:51:31 +0200 Subject: [PATCH] fixed bug in textstyleparser * the textstyleparser now properly handles `***` and marks the text as bold and italic. see #879 --- src/utils/textstyleparser.go | 35 ++++++++++++++++++++++++------- src/utils/textstyleparser_test.go | 8 ++++++- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/utils/textstyleparser.go b/src/utils/textstyleparser.go index 9b267c9..f8b4beb 100644 --- a/src/utils/textstyleparser.go +++ b/src/utils/textstyleparser.go @@ -23,6 +23,7 @@ const ( MonoSpaceBegin = 6 StrikethroughBegin = 8 SpoilerBegin = 9 + BoldItalicBegin = 10 ) const EscapeCharacter rune = '\\' @@ -119,7 +120,14 @@ func (l *TextstyleParser) handleToken(tokenType int, signalCliStylingType string } else { if l.tokens.Peek().Token == tokenType { tokenBeginState := l.tokens.Pop() - l.signalCliFormatStrings = append(l.signalCliFormatStrings, strconv.Itoa(tokenBeginState.BeginPos)+":"+strconv.Itoa(getUtf16StringLength(l.fullString)-tokenBeginState.BeginPos)+":"+signalCliStylingType) + length := getUtf16StringLength(l.fullString) - tokenBeginState.BeginPos + + if tokenType == BoldItalicBegin { + l.signalCliFormatStrings = append(l.signalCliFormatStrings, strconv.Itoa(tokenBeginState.BeginPos)+":"+strconv.Itoa(length)+":"+Bold) + l.signalCliFormatStrings = append(l.signalCliFormatStrings, strconv.Itoa(tokenBeginState.BeginPos)+":"+strconv.Itoa(length)+":"+Italic) + } else { + l.signalCliFormatStrings = append(l.signalCliFormatStrings, strconv.Itoa(tokenBeginState.BeginPos)+":"+strconv.Itoa(length)+":"+signalCliStylingType) + } } else { l.tokens.Push(TokenState{BeginPos: getUtf16StringLength(l.fullString), Token: tokenType}) } @@ -137,14 +145,27 @@ func (l *TextstyleParser) Parse() (string, []string) { nextRune := l.peek() if c == '*' { - if nextRune == '*' { //Bold + if nextRune == '*' { l.next() - if prevChar == EscapeCharacter { - prevChar = c - l.fullString += "**" - continue + + if l.peek() == '*' { // Check for *** before treating it as ** + l.next() + + if prevChar == EscapeCharacter { + prevChar = c + l.fullString += "***" + continue + } + + l.handleToken(BoldItalicBegin, "BOLD_ITALIC") + } else { + if prevChar == EscapeCharacter { + prevChar = c + l.fullString += "**" + continue + } + l.handleToken(BoldBegin, Bold) } - l.handleToken(BoldBegin, Bold) } else { //Italic if prevChar == EscapeCharacter { prevChar = c diff --git a/src/utils/textstyleparser_test.go b/src/utils/textstyleparser_test.go index 480a1fd..0ad3237 100644 --- a/src/utils/textstyleparser_test.go +++ b/src/utils/textstyleparser_test.go @@ -155,5 +155,11 @@ func TestEscapeNew(t *testing.T) { message, signalCliFormatStrings := textstyleParser.Parse() expectMessageEqual(t, message, "Test ** * ~ Escape") expectFormatStringsEqual(t, signalCliFormatStrings, []string{}) - +} + +func TestBoldItalic(t *testing.T) { + textstyleParser := NewTextstyleParser("***Bold Italic Text***") + message, signalCliFormatStrings := textstyleParser.Parse() + expectMessageEqual(t, message, "Bold Italic Text") + expectFormatStringsEqual(t, signalCliFormatStrings, []string{"0:16:BOLD", "0:16:ITALIC"}) }