mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-27 14:10:31 +03:00
helpers: Fix TrimShortHTML used by markdownify and RenderString
Closes #11698
This commit is contained in:
parent
ac7cffa7e2
commit
0bde6931ac
3 changed files with 78 additions and 11 deletions
|
@ -251,18 +251,15 @@ 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 {
|
||||
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)
|
||||
if bytes.Count(input, openingPTag) == 1 {
|
||||
input = bytes.TrimSpace(input)
|
||||
if bytes.HasPrefix(input, openingPTag) && bytes.HasSuffix(input, closingPTag) {
|
||||
input = bytes.TrimPrefix(input, openingPTag)
|
||||
input = bytes.TrimSuffix(input, closingPTag)
|
||||
input = bytes.TrimSpace(input)
|
||||
}
|
||||
}
|
||||
|
||||
return input
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue