mirror of
https://github.com/aljazceru/signal-cli-rest-api.git
synced 2025-12-21 08:34:22 +01:00
added spoiler to textstyleparser
This commit is contained in:
@@ -10,6 +10,7 @@ const (
|
|||||||
Italic = "ITALIC"
|
Italic = "ITALIC"
|
||||||
Monospace = "MONOSPACE"
|
Monospace = "MONOSPACE"
|
||||||
Strikethrough = "STRIKETHROUGH"
|
Strikethrough = "STRIKETHROUGH"
|
||||||
|
Spoiler = "SPOILER"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -23,6 +24,10 @@ const (
|
|||||||
MonoSpaceEnd = 7
|
MonoSpaceEnd = 7
|
||||||
StrikethroughBegin = 8
|
StrikethroughBegin = 8
|
||||||
StrikethroughEnd = 9
|
StrikethroughEnd = 9
|
||||||
|
SpoilerBegin1 = 10
|
||||||
|
SpoilerBegin = 11
|
||||||
|
SpoilerEnd1 = 12
|
||||||
|
SpoilerEnd2 = 13
|
||||||
)
|
)
|
||||||
|
|
||||||
func getUtf16CharacterCount(s string) int {
|
func getUtf16CharacterCount(s string) int {
|
||||||
@@ -76,6 +81,20 @@ func ParseMarkdownMessage(message string) (string, []string) {
|
|||||||
state = BoldEnd2
|
state = BoldEnd2
|
||||||
}
|
}
|
||||||
numOfControlChars += 1
|
numOfControlChars += 1
|
||||||
|
} else if v == '|' {
|
||||||
|
if state == None {
|
||||||
|
state = SpoilerBegin1
|
||||||
|
} else if state == SpoilerBegin1 && lastChar == "|" {
|
||||||
|
state = SpoilerBegin
|
||||||
|
textFormat = Spoiler
|
||||||
|
textFormatBegin = i - numOfControlChars + additionalCharacterCount
|
||||||
|
textFormatLength = 0
|
||||||
|
} else if state == SpoilerBegin {
|
||||||
|
state = SpoilerEnd1
|
||||||
|
} else if state == SpoilerEnd1 && lastChar == "|" {
|
||||||
|
state = SpoilerEnd2
|
||||||
|
}
|
||||||
|
numOfControlChars += 1
|
||||||
} else if v == '`' {
|
} else if v == '`' {
|
||||||
if state == None {
|
if state == None {
|
||||||
state = MonoSpaceBegin
|
state = MonoSpaceBegin
|
||||||
@@ -103,7 +122,7 @@ func ParseMarkdownMessage(message string) (string, []string) {
|
|||||||
}
|
}
|
||||||
lastChar = string(v)
|
lastChar = string(v)
|
||||||
|
|
||||||
if state == ItalicEnd || state == BoldEnd2 || state == MonoSpaceEnd || state == StrikethroughEnd {
|
if state == ItalicEnd || state == BoldEnd2 || state == MonoSpaceEnd || state == StrikethroughEnd || state == SpoilerEnd2 {
|
||||||
signalCliFormatStrings = append(signalCliFormatStrings, strconv.Itoa(textFormatBegin)+":"+strconv.Itoa(textFormatLength + additionalCharacterCount)+":"+textFormat)
|
signalCliFormatStrings = append(signalCliFormatStrings, strconv.Itoa(textFormatBegin)+":"+strconv.Itoa(textFormatLength + additionalCharacterCount)+":"+textFormat)
|
||||||
state = None
|
state = None
|
||||||
textFormatBegin = 0
|
textFormatBegin = 0
|
||||||
|
|||||||
@@ -74,3 +74,15 @@ func TestMultipleMulticharacterEmojiWithBoldText(t *testing.T) {
|
|||||||
expectMessageEqual(t, message, "👋🏾abcdefg")
|
expectMessageEqual(t, message, "👋🏾abcdefg")
|
||||||
expectFormatStringsEqual(t, signalCliFormatStrings, []string{"4:9:BOLD"})
|
expectFormatStringsEqual(t, signalCliFormatStrings, []string{"4:9:BOLD"})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSpoiler(t *testing.T) {
|
||||||
|
message, signalCliFormatStrings := ParseMarkdownMessage("||this is a spoiler||")
|
||||||
|
expectMessageEqual(t, message, "this is a spoiler")
|
||||||
|
expectFormatStringsEqual(t, signalCliFormatStrings, []string{"0:17:SPOILER"})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSpoiler1(t *testing.T) {
|
||||||
|
message, signalCliFormatStrings := ParseMarkdownMessage("||this is a spoiler|| and another ||spoiler||")
|
||||||
|
expectMessageEqual(t, message, "this is a spoiler and another spoiler")
|
||||||
|
expectFormatStringsEqual(t, signalCliFormatStrings, []string{"0:17:SPOILER", "30:7:SPOILER"})
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user