mirror of
https://github.com/bbernhard/signal-cli-rest-api.git
synced 2026-05-24 14:24:15 +00:00
fixed bug in textstyleparser
* bold text wasn't correctly parsed see #382
This commit is contained in:
parent
c6d065980f
commit
a5cbb4c725
@ -27,13 +27,14 @@ func ParseMarkdownMessage(message string) (string, []string) {
|
|||||||
state := None
|
state := None
|
||||||
signalCliFormatStrings := []string{}
|
signalCliFormatStrings := []string{}
|
||||||
fullString := ""
|
fullString := ""
|
||||||
|
lastChar := ""
|
||||||
|
|
||||||
runes := []rune(message) //turn string to slice
|
runes := []rune(message) //turn string to slice
|
||||||
|
|
||||||
for i, v := range runes { //iterate through rune
|
for i, v := range runes { //iterate through rune
|
||||||
if v == '*' {
|
if v == '*' {
|
||||||
if state == ItalicBegin {
|
if state == ItalicBegin {
|
||||||
if i-1 == textFormatBegin {
|
if lastChar == "*" {
|
||||||
state = BoldBegin
|
state = BoldBegin
|
||||||
textFormat = Bold
|
textFormat = Bold
|
||||||
textFormatBegin = i - numOfAsterisks
|
textFormatBegin = i - numOfAsterisks
|
||||||
@ -56,6 +57,7 @@ func ParseMarkdownMessage(message string) (string, []string) {
|
|||||||
textFormatLength += 1
|
textFormatLength += 1
|
||||||
fullString += string(v)
|
fullString += string(v)
|
||||||
}
|
}
|
||||||
|
lastChar = string(v)
|
||||||
|
|
||||||
if state == ItalicEnd || state == BoldEnd2 {
|
if state == ItalicEnd || state == BoldEnd2 {
|
||||||
signalCliFormatStrings = append(signalCliFormatStrings, strconv.Itoa(textFormatBegin)+":"+strconv.Itoa(textFormatLength)+":"+textFormat)
|
signalCliFormatStrings = append(signalCliFormatStrings, strconv.Itoa(textFormatBegin)+":"+strconv.Itoa(textFormatLength)+":"+textFormat)
|
||||||
|
|||||||
@ -32,3 +32,9 @@ func TestBoldAndItalicMessage(t *testing.T) {
|
|||||||
expectMessageEqual(t, message, "This is a bold and italic message")
|
expectMessageEqual(t, message, "This is a bold and italic message")
|
||||||
expectFormatStringsEqual(t, signalCliFormatStrings, []string{"10:4:BOLD", "19:6:ITALIC"})
|
expectFormatStringsEqual(t, signalCliFormatStrings, []string{"10:4:BOLD", "19:6:ITALIC"})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTwoBoldFormattedStrings(t *testing.T) {
|
||||||
|
message, signalCliFormatStrings := ParseMarkdownMessage("This is a **bold** and another **bold** message")
|
||||||
|
expectMessageEqual(t, message, "This is a bold and another bold message")
|
||||||
|
expectFormatStringsEqual(t, signalCliFormatStrings, []string{"10:4:BOLD", "27:4:BOLD"})
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user