From 3a62d54745e2cbfda6772390830042908d725c71 Mon Sep 17 00:00:00 2001
From: Jim McDonald ")
+ closingPTag = []byte(" / tags in the input and enclose the content
+// of the input (whitespace excluded).
+func (c *ContentSpec) TrimShortHTML(input []byte) []byte {
+ first := bytes.Index(input, paragraphIndicator)
+ last := bytes.LastIndex(input, paragraphIndicator)
+ if first == last {
+ input = bytes.TrimSpace(input)
+ input = bytes.TrimPrefix(input, openingPTag)
+ input = bytes.TrimSuffix(input, closingPTag)
+ input = bytes.TrimSpace(input)
+ }
+ return input
+}
+
func isEndOfSentence(r rune) bool {
return r == '.' || r == '?' || r == '!' || r == '"' || r == '\n'
}
diff --git a/helpers/content_test.go b/helpers/content_test.go
index 1dd4a2fb8..709c81142 100644
--- a/helpers/content_test.go
+++ b/helpers/content_test.go
@@ -29,6 +29,28 @@ import (
const tstHTMLContent = " This is some text. Simple paragraph \t Whitespace\nHTML \n\t Multiple paragraphs Multiple paragraphs Nested paragraphs
And some more.
Nested
paragraphs
")}, + } + + c := newTestContentSpec() + for i, test := range tests { + output := c.TrimShortHTML(test.input) + if bytes.Compare(test.output, output) != 0 { + t.Errorf("Test %d failed. Expected %q got %q", i, test.output, output) + } + } +} + func TestStripHTML(t *testing.T) { type test struct { input, expected string -- cgit v1.2.3