You can now escape whitelisted HTML elements with a backslash to make them render as text rather than HTML elements.
Added eight more parser tests. Replaced an empty slice with nil to make it cleaner.
This commit is contained in:
parent
e1dfebf090
commit
4f7bb5320d
@ -219,6 +219,7 @@ func PreparseMessage(msg string) string {
|
||||
'u': []string{""},
|
||||
'b': []string{"", "lockquote"},
|
||||
'i': []string{""},
|
||||
//'p': []string{""},
|
||||
'g': []string{""}, // Quick and dirty fix for Grammarly
|
||||
}
|
||||
var buildLitMatch = func(tag string) func(*TagToAction, bool, int, []rune) (int, string) {
|
||||
@ -266,6 +267,7 @@ func PreparseMessage(msg string) string {
|
||||
&TagToAction{"lockquote", buildLitMatch("blockquote"), 0, false},
|
||||
},
|
||||
'i': []*TagToAction{&TagToAction{"", buildLitMatch("em"), 0, false}},
|
||||
//'p': []*TagToAction{&TagToAction{"", buildLitMatch2("\n\n", ""), 0, false}},
|
||||
'g': []*TagToAction{
|
||||
&TagToAction{"", func(act *TagToAction, open bool, i int, runes []rune) (int, string) {
|
||||
if open {
|
||||
@ -290,7 +292,13 @@ func PreparseMessage(msg string) string {
|
||||
// TODO: Implement a less literal parser
|
||||
for i := 0; i < len(runes); i++ {
|
||||
char := runes[i]
|
||||
if char == '&' && peekMatch(i, "lt;", runes) {
|
||||
// TODO: Make the slashes escapable too in case someone means to use a literaly slash, maybe as an example of how to escape elements?
|
||||
if char == '\\' {
|
||||
if peekMatch(i, "<", runes) {
|
||||
msg += "&"
|
||||
i++
|
||||
}
|
||||
} else if char == '&' && peekMatch(i, "lt;", runes) {
|
||||
var ok bool
|
||||
i, ok = tryStepForward(i, 4, runes)
|
||||
if !ok {
|
||||
|
@ -113,8 +113,7 @@ func installGuilds(plugin *common.Plugin) error {
|
||||
qgen.DBTableColumn{"rank", "int", 0, false, false, "0"}, /* 0: Member. 1: Mod. 2: Admin. */
|
||||
qgen.DBTableColumn{"posts", "int", 0, false, false, "0"}, /* Per-Group post count. Should we do some sort of score system? */
|
||||
qgen.DBTableColumn{"joinedAt", "datetime", 0, false, false, ""},
|
||||
},
|
||||
[]qgen.DBTableKey{},
|
||||
}, nil,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -73,10 +73,18 @@ func TestPreparser(t *testing.T) {
|
||||
msgList.Add("</span>", "")
|
||||
msgList.Add("<span></span>", "")
|
||||
msgList.Add("<span ></span>", "")
|
||||
msgList.Add("<span><span></span></span>", "")
|
||||
msgList.Add("<span><b></b></span>", "<strong></strong>")
|
||||
msgList.Add("<></>", "<></>")
|
||||
msgList.Add("</><>", "</><>")
|
||||
msgList.Add("<>", "<>")
|
||||
msgList.Add("</>", "</>")
|
||||
msgList.Add("<p>hi</p>", "hi")
|
||||
msgList.Add("<p></p>", "")
|
||||
msgList.Add("<blockquote>hi</blockquote>", "<blockquote>hi</blockquote>")
|
||||
msgList.Add("<blockquote><b>hi</b></blockquote>", "<blockquote><strong>hi</strong></blockquote>")
|
||||
msgList.Add("<blockquote><meow>hi</meow></blockquote>", "<blockquote><meow>hi</meow></blockquote>")
|
||||
msgList.Add("\\<blockquote>hi</blockquote>", "<blockquote>hi</blockquote>")
|
||||
msgList.Add("@", "@")
|
||||
msgList.Add("@Admin", "@1")
|
||||
msgList.Add("@Bah", "@Bah")
|
||||
|
Loading…
Reference in New Issue
Block a user