newline battles continue

This commit is contained in:
bel
2020-01-19 20:41:30 +00:00
parent 98adb53caf
commit 573696774e
1456 changed files with 501133 additions and 6 deletions

View File

@@ -95,7 +95,11 @@ func (i *Item) Load(key, ns1 string, ns ...string) error {
if err != nil {
return err
}
return config.Decode(b, i)
err = config.Decode(b, i)
if err == nil {
i.Content = clearBlankLines(i.Content)
}
return err
}
func (is Items) Len() int {
@@ -113,8 +117,10 @@ func (is Items) Swap(i, j int) {
}
func clearBlankLines(s string) string {
r := regexp.MustCompile(`(?m)^\s*<br>\s*$`)
s = r.ReplaceAllLiteralString(s, "")
r := regexp.MustCompile(`<br/>`)
s = r.ReplaceAllLiteralString(s, "<br>")
r = regexp.MustCompile(`(?m)<br>\s*(<br>\s*)*`)
s = r.ReplaceAllLiteralString(s, "<br>")
r = regexp.MustCompile(`(?m)\s\s*`)
return r.ReplaceAllLiteralString(s, "\n")
}