diff options
author | Bjørn Erik Pedersen <[email protected]> | 2021-05-13 13:10:32 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2021-05-17 17:15:32 +0200 |
commit | ef0f1a726901d6c614040cfc2d7e8f9a2ca97816 (patch) | |
tree | ae56b2ac4b307d421bfbebc3efaa83abb16e0f59 /common | |
parent | abbc99d4c60b102e2779e4362ceb433095719384 (diff) | |
download | hugo-ef0f1a726901d6c614040cfc2d7e8f9a2ca97816.tar.gz hugo-ef0f1a726901d6c614040cfc2d7e8f9a2ca97816.zip |
publisher: Make the HTML element collector more robust
Fixes #8530
Diffstat (limited to 'common')
-rw-r--r-- | common/text/transform.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/common/text/transform.go b/common/text/transform.go index f59577803..2d51f6c33 100644 --- a/common/text/transform.go +++ b/common/text/transform.go @@ -45,3 +45,25 @@ func RemoveAccentsString(s string) string { accentTransformerPool.Put(t) return s } + +// Chunk splits s into strings of size. +func Chunk(s string, size int) []string { + if size >= len(s) { + return []string{s} + } + var chunks []string + chunk := make([]rune, size) + l := 0 + for _, r := range s { + chunk[l] = r + l++ + if l == size { + chunks = append(chunks, string(chunk)) + l = 0 + } + } + if l > 0 { + chunks = append(chunks, string(chunk[:l])) + } + return chunks +} |