mirror of
https://github.com/bbernhard/signal-cli-rest-api.git
synced 2026-05-29 15:14:28 +00:00
parent
3d51571385
commit
a70c2994c3
@ -395,7 +395,7 @@ func (a *Api) Send(c *gin.Context) {
|
|||||||
|
|
||||||
// @Summary Send a signal message.
|
// @Summary Send a signal message.
|
||||||
// @Tags Messages
|
// @Tags Messages
|
||||||
// @Description Send a signal message. Set the text_mode to 'styled' in case you want to add formatting to your text message. Styling Options: *italic text*, **bold text**, ~strikethrough text~.
|
// @Description Send a signal message. Set the text_mode to 'styled' in case you want to add formatting to your text message. Styling Options: *italic text*, **bold text**, ~strikethrough text~. If you want to escape a character, prefix it with two backslashes ('\\')
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Success 201 {object} SendMessageResponse
|
// @Success 201 {object} SendMessageResponse
|
||||||
|
|||||||
@ -2014,7 +2014,7 @@ const docTemplate = `{
|
|||||||
},
|
},
|
||||||
"/v2/send": {
|
"/v2/send": {
|
||||||
"post": {
|
"post": {
|
||||||
"description": "Send a signal message. Set the text_mode to 'styled' in case you want to add formatting to your text message. Styling Options: *italic text*, **bold text**, ~strikethrough text~.",
|
"description": "Send a signal message. Set the text_mode to 'styled' in case you want to add formatting to your text message. Styling Options: *italic text*, **bold text**, ~strikethrough text~. If you want to escape a character, prefix it with two backslashes ('\\\\')",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
|
|||||||
@ -2011,7 +2011,7 @@
|
|||||||
},
|
},
|
||||||
"/v2/send": {
|
"/v2/send": {
|
||||||
"post": {
|
"post": {
|
||||||
"description": "Send a signal message. Set the text_mode to 'styled' in case you want to add formatting to your text message. Styling Options: *italic text*, **bold text**, ~strikethrough text~.",
|
"description": "Send a signal message. Set the text_mode to 'styled' in case you want to add formatting to your text message. Styling Options: *italic text*, **bold text**, ~strikethrough text~. If you want to escape a character, prefix it with two backslashes ('\\\\')",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
|
|||||||
@ -1754,7 +1754,8 @@ paths:
|
|||||||
- application/json
|
- application/json
|
||||||
description: 'Send a signal message. Set the text_mode to ''styled'' in case
|
description: 'Send a signal message. Set the text_mode to ''styled'' in case
|
||||||
you want to add formatting to your text message. Styling Options: *italic
|
you want to add formatting to your text message. Styling Options: *italic
|
||||||
text*, **bold text**, ~strikethrough text~.'
|
text*, **bold text**, ~strikethrough text~. If you want to escape a character,
|
||||||
|
prefix it with two backslashes (''\\'')'
|
||||||
parameters:
|
parameters:
|
||||||
- description: Input Data
|
- description: Input Data
|
||||||
in: body
|
in: body
|
||||||
|
|||||||
@ -25,6 +25,8 @@ const (
|
|||||||
SpoilerBegin = 9
|
SpoilerBegin = 9
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const EscapeCharacter rune = '\\'
|
||||||
|
|
||||||
func getUtf16StringLength(s string) int {
|
func getUtf16StringLength(s string) int {
|
||||||
runes := []rune(s) //turn string to slice
|
runes := []rune(s) //turn string to slice
|
||||||
|
|
||||||
@ -74,7 +76,6 @@ type TextstyleParser struct {
|
|||||||
tokens Stack
|
tokens Stack
|
||||||
fullString string
|
fullString string
|
||||||
signalCliFormatStrings []string
|
signalCliFormatStrings []string
|
||||||
//numOfControlTokens int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTextstyleParser(input string) *TextstyleParser {
|
func NewTextstyleParser(input string) *TextstyleParser {
|
||||||
@ -93,9 +94,6 @@ func (l *TextstyleParser) next() (rune rune) {
|
|||||||
l.width = 0
|
l.width = 0
|
||||||
return eof
|
return eof
|
||||||
}
|
}
|
||||||
//r := []rune(l.input[l.pos:])[0]
|
|
||||||
//l.width = utf16.RuneLen(r)
|
|
||||||
//l.pos += l.width
|
|
||||||
rune, l.width = utf8.DecodeRuneInString(l.input[l.pos:])
|
rune, l.width = utf8.DecodeRuneInString(l.input[l.pos:])
|
||||||
l.pos += l.width
|
l.pos += l.width
|
||||||
return rune
|
return rune
|
||||||
@ -129,6 +127,7 @@ func (l *TextstyleParser) handleToken(tokenType int, signalCliStylingType string
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *TextstyleParser) Parse() (string, []string) {
|
func (l *TextstyleParser) Parse() (string, []string) {
|
||||||
|
var prevChar rune
|
||||||
for {
|
for {
|
||||||
c := l.next()
|
c := l.next()
|
||||||
if c == eof {
|
if c == eof {
|
||||||
@ -140,20 +139,45 @@ func (l *TextstyleParser) Parse() (string, []string) {
|
|||||||
if c == '*' {
|
if c == '*' {
|
||||||
if nextRune == '*' { //Bold
|
if nextRune == '*' { //Bold
|
||||||
l.next()
|
l.next()
|
||||||
|
if prevChar == EscapeCharacter {
|
||||||
|
prevChar = c
|
||||||
|
continue
|
||||||
|
}
|
||||||
l.handleToken(BoldBegin, Bold)
|
l.handleToken(BoldBegin, Bold)
|
||||||
} else { //Italic
|
} else { //Italic
|
||||||
|
if prevChar == EscapeCharacter {
|
||||||
|
prevChar = c
|
||||||
|
continue
|
||||||
|
}
|
||||||
l.handleToken(ItalicBegin, Italic)
|
l.handleToken(ItalicBegin, Italic)
|
||||||
}
|
}
|
||||||
} else if (c == '|') && (nextRune == '|') {
|
} else if (c == '|') && (nextRune == '|') {
|
||||||
l.next()
|
l.next()
|
||||||
|
if prevChar == EscapeCharacter {
|
||||||
|
prevChar = c
|
||||||
|
continue
|
||||||
|
}
|
||||||
l.handleToken(SpoilerBegin, Spoiler)
|
l.handleToken(SpoilerBegin, Spoiler)
|
||||||
} else if c == '~' {
|
} else if c == '~' {
|
||||||
|
if prevChar == EscapeCharacter {
|
||||||
|
prevChar = c
|
||||||
|
continue
|
||||||
|
}
|
||||||
l.handleToken(StrikethroughBegin, Strikethrough)
|
l.handleToken(StrikethroughBegin, Strikethrough)
|
||||||
} else if c == '`' {
|
} else if c == '`' {
|
||||||
|
if prevChar == EscapeCharacter {
|
||||||
|
prevChar = c
|
||||||
|
continue
|
||||||
|
}
|
||||||
l.handleToken(MonoSpaceBegin, Monospace)
|
l.handleToken(MonoSpaceBegin, Monospace)
|
||||||
|
} else if ((c == EscapeCharacter) && (nextRune == '*')) || ((c == EscapeCharacter) && (nextRune == '`')) || ((c == EscapeCharacter) && (nextRune == '|')) || ((c == EscapeCharacter) && (nextRune == '~')) {
|
||||||
|
prevChar = c
|
||||||
|
continue
|
||||||
} else {
|
} else {
|
||||||
l.fullString += string(c)
|
l.fullString += string(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prevChar = c
|
||||||
}
|
}
|
||||||
|
|
||||||
return l.fullString, l.signalCliFormatStrings
|
return l.fullString, l.signalCliFormatStrings
|
||||||
|
|||||||
@ -119,3 +119,31 @@ func TestBoldTextInsideSpoiler(t *testing.T) {
|
|||||||
expectMessageEqual(t, message, "this is a bold text inside a spoiler")
|
expectMessageEqual(t, message, "this is a bold text inside a spoiler")
|
||||||
expectFormatStringsEqual(t, signalCliFormatStrings, []string{"0:36:BOLD", "0:36:SPOILER"})
|
expectFormatStringsEqual(t, signalCliFormatStrings, []string{"0:36:BOLD", "0:36:SPOILER"})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestEscapeAsterisks(t *testing.T) {
|
||||||
|
textstyleParser := NewTextstyleParser("\\*escaped text\\*")
|
||||||
|
message, signalCliFormatStrings := textstyleParser.Parse()
|
||||||
|
expectMessageEqual(t, message, "escaped text")
|
||||||
|
expectFormatStringsEqual(t, signalCliFormatStrings, []string{})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEscapeAsterisks1(t *testing.T) {
|
||||||
|
textstyleParser := NewTextstyleParser("\\**escaped text\\**")
|
||||||
|
message, signalCliFormatStrings := textstyleParser.Parse()
|
||||||
|
expectMessageEqual(t, message, "escaped text")
|
||||||
|
expectFormatStringsEqual(t, signalCliFormatStrings, []string{})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEscapeBackticks(t *testing.T) {
|
||||||
|
textstyleParser := NewTextstyleParser("\\`escaped text\\`")
|
||||||
|
message, signalCliFormatStrings := textstyleParser.Parse()
|
||||||
|
expectMessageEqual(t, message, "escaped text")
|
||||||
|
expectFormatStringsEqual(t, signalCliFormatStrings, []string{})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEscapeTilde(t *testing.T) {
|
||||||
|
textstyleParser := NewTextstyleParser("\\~escaped text\\~")
|
||||||
|
message, signalCliFormatStrings := textstyleParser.Parse()
|
||||||
|
expectMessageEqual(t, message, "escaped text")
|
||||||
|
expectFormatStringsEqual(t, signalCliFormatStrings, []string{})
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user