diff options
author | SatowTakeshi <[email protected]> | 2020-03-28 01:36:50 +0900 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2020-03-28 11:10:25 +0100 |
commit | 9c9987535f98714c8a4ec98903f54233735ef0e4 (patch) | |
tree | 3dc4880579c814e439cc64d11627538033f97e25 /helpers/content.go | |
parent | 4a39564efe7b02a685598ae9dbae95e2326c0230 (diff) | |
download | hugo-9c9987535f98714c8a4ec98903f54233735ef0e4.tar.gz hugo-9c9987535f98714c8a4ec98903f54233735ef0e4.zip |
helpers: Fix TrimShortHTML
Where some tags are siblings of p tag.
Fixes #7081
Diffstat (limited to 'helpers/content.go')
-rw-r--r-- | helpers/content.go | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/helpers/content.go b/helpers/content.go index e61888357..5eeca88b6 100644 --- a/helpers/content.go +++ b/helpers/content.go @@ -44,6 +44,7 @@ var ( openingPTag = []byte("<p>") closingPTag = []byte("</p>") paragraphIndicator = []byte("<p") + closingIndicator = []byte("</") ) // ContentSpec provides functionality to render markdown content. @@ -315,9 +316,13 @@ func (c *ContentSpec) TruncateWordsToWholeSentence(s string) (string, bool) { // where said tags are the only <p> 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 { + firstOpeningP := bytes.Index(input, paragraphIndicator) + lastOpeningP := bytes.LastIndex(input, paragraphIndicator) + + lastClosingP := bytes.LastIndex(input, closingPTag) + lastClosing := bytes.LastIndex(input, closingIndicator) + + if firstOpeningP == lastOpeningP && lastClosingP == lastClosing { input = bytes.TrimSpace(input) input = bytes.TrimPrefix(input, openingPTag) input = bytes.TrimSuffix(input, closingPTag) |