diff --git a/app/plugins/digest.go b/app/plugins/digest.go index a4ad493..d511b8c 100644 --- a/app/plugins/digest.go +++ b/app/plugins/digest.go @@ -61,56 +61,60 @@ func InitDigestCache() { if len(c.DigestTagOccupyNum) <= 1 { return c } - c.specialSolve = map[string]digest.SpecialSolveConf{} - for _, item := range c.DigestTagOccupyNum { - tags := strings.Split(strings.ReplaceAll(item.Tag, " ", ""), "<") - for _, tag := range tags { - if tag == "" { - continue - } - tag = str.Join("<", tag) - var ec map[rune]digest.SpecialSolve - var specialTags map[string]digest.SpecialSolve - if len(item.EscapeCharacter) > 0 { - ec = make(map[rune]digest.SpecialSolve) - for _, esc := range item.EscapeCharacter { - for _, i := range esc.Character { - s := []rune(i) - if len(s) == 1 { - ec[s[0]] = digest.SpecialSolve{ - Num: esc.Num, - ChuckOvered: esc.ChuckOvered, - } - } - } - if esc.Tags == "" { - continue - } - tagss := strings.Split(strings.ReplaceAll(esc.Tags, " ", ""), "<") - specialTags = make(map[string]digest.SpecialSolve) - for _, t := range tagss { - if t == "" { - continue - } - t = str.Join("<", t) - specialTags[t] = digest.SpecialSolve{ + c.specialSolve = ParseDigestConf(c) + return c + }, "digestConfig") +} + +func ParseDigestConf(c DigestConfig) map[string]digest.SpecialSolveConf { + specialSolve := map[string]digest.SpecialSolveConf{} + for _, item := range c.DigestTagOccupyNum { + tags := strings.Split(strings.ReplaceAll(item.Tag, " ", ""), "<") + for _, tag := range tags { + if tag == "" { + continue + } + tag = str.Join("<", tag) + var ec map[rune]digest.SpecialSolve + var specialTags map[string]digest.SpecialSolve + if len(item.EscapeCharacter) > 0 { + ec = make(map[rune]digest.SpecialSolve) + for _, esc := range item.EscapeCharacter { + for _, i := range esc.Character { + s := []rune(i) + if len(s) == 1 { + ec[s[0]] = digest.SpecialSolve{ Num: esc.Num, ChuckOvered: esc.ChuckOvered, } } } - - } - c.specialSolve[tag] = digest.SpecialSolveConf{ - Num: item.Num, - ChuckOvered: item.ChuckOvered, - EscapeCharacter: ec, - Tags: specialTags, + if esc.Tags == "" { + continue + } + tagss := strings.Split(strings.ReplaceAll(esc.Tags, " ", ""), "<") + specialTags = make(map[string]digest.SpecialSolve) + for _, t := range tagss { + if t == "" { + continue + } + t = str.Join("<", t) + specialTags[t] = digest.SpecialSolve{ + Num: esc.Num, + ChuckOvered: esc.ChuckOvered, + } + } } } + specialSolve[tag] = digest.SpecialSolveConf{ + Num: item.Num, + ChuckOvered: item.ChuckOvered, + EscapeCharacter: ec, + Tags: specialTags, + } } - return c - }, "digestConfig") + } + return specialSolve } func RemoveWpBlock(s string) string { diff --git a/plugin/digest/digest.go b/plugin/digest/digest.go index 832f598..19d2387 100644 --- a/plugin/digest/digest.go +++ b/plugin/digest/digest.go @@ -26,8 +26,6 @@ type SpecialSolve struct { ChuckOvered bool } -var selfCloseTags = html.GetSelfCloseTags() - func StripTags(content, allowTag string) string { content = strings.Trim(content, " \t\n\r\000\x0B") content = strings.Replace(content, "]]>", "]]>", -1) @@ -78,7 +76,7 @@ func Html(content string, limit int) (string, string) { tagIn = false continue } - if tagIn == false && ru[i] != '\n' { + if tagIn == false { end++ } } @@ -111,6 +109,7 @@ func CustomizeHtml(content string, limit int, m map[string]SpecialSolveConf) (st runeTotal := len(runeContent) l, r := '<', '>' i := -1 + selfCloseTags := html.GetSelfCloseTags() var currentTag, parentTag string var allTags = []string{""} var tag []rune