summaryrefslogtreecommitdiff
path: root/internal/platforms/linkedin/escapes.go
blob: 5e431c757a50875fbec469f6c58fd6bc7bcd4fb4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package linkedin

import (
	"strings"
)

// https://learn.microsoft.com/en-us/linkedin/marketing/community-management/shares/little-text-format?view=li-lms-2024-01#language-grammar
func escapeLinkedInText(input string) string {
	var builder strings.Builder

	reservedChars := map[rune]string{
		'|': "\\|",
		'{': "\\{",
		'}': "\\}",
		// '@': "\\@",
		'[': "\\[",
		']': "\\]",
		'(': "\\(",
		')': "\\)",
		'<': "\\<",
		'>': "\\>",
		//'#':  "\\#",
		'\\': "\\\\",
		'*':  "\\*",
		'_':  "\\_",
		'~':  "\\~",
	}

	for _, char := range input {
		if escapeSeq, ok := reservedChars[char]; ok {
			builder.WriteString(escapeSeq)
		} else {
			builder.WriteRune(char)
		}
	}

	return builder.String()
}