From f41a5dd9439ea26b0b6d04576c2b99ae56e10885 Mon Sep 17 00:00:00 2001 From: Azareal Date: Sun, 3 Mar 2019 16:39:08 +1000 Subject: [PATCH] Fix the issue with Grammarly spewing out random HTML. --- common/parser.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/common/parser.go b/common/parser.go index ac0469e5..de8e8124 100644 --- a/common/parser.go +++ b/common/parser.go @@ -219,6 +219,7 @@ func PreparseMessage(msg string) string { 'u': []string{""}, 'b': []string{""}, 'i': []string{""}, + 'g': []string{""}, // Quick and dirty fix for Grammarly } var buildLitMatch = func(tag string) func(*TagToAction, bool, int, []rune) (int, string) { return func(action *TagToAction, open bool, _ int, _ []rune) (int, string) { @@ -262,6 +263,26 @@ func PreparseMessage(msg string) string { 'u': []*TagToAction{&TagToAction{"", buildLitMatch("u"), 0, false}}, 'b': []*TagToAction{&TagToAction{"", buildLitMatch("strong"), 0, false}}, 'i': []*TagToAction{&TagToAction{"", buildLitMatch("em"), 0, false}}, + 'g': []*TagToAction{ + &TagToAction{"", func(act *TagToAction, open bool, i int, runes []rune) (int, string) { + if open { + act.Depth++ + //fmt.Println("skipping attributes") + for ; i < len(runes); i++ { + if runes[i] == '&' && peekMatch(i, "gt;", runes) { + //fmt.Println("found tag exit") + return i + 3, " " + } + } + return -1, " " + } + if act.Depth <= 0 { + return -1, " " + } + act.Depth-- + return -1, " " + }, 0, true}, + }, } // TODO: Implement a less literal parser for i := 0; i < len(runes); i++ {