mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-12 20:13:59 +02:00
Wrap comments helpers package to fit 80-column width
Add an initial space after `//` where appropriate. Minor copyediting.
This commit is contained in:
@@ -11,8 +11,10 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//Package helpers implements general utility functions that work with and on content. The helper functions defined here
|
||||
//lay down the foundation of how Hugo works with files, filepaths and does string operations on content.
|
||||
// Package helpers implements general utility functions that work with
|
||||
// and on content. The helper functions defined here lay down the
|
||||
// foundation of how Hugo works with files and filepaths, and perform
|
||||
// string operations on content.
|
||||
package helpers
|
||||
|
||||
import (
|
||||
@@ -34,7 +36,7 @@ var SummaryLength = 70
|
||||
// Custom divider <!--more--> let's user define where summarization ends.
|
||||
var SummaryDivider = []byte("<!--more-->")
|
||||
|
||||
//StripHTML accepts a string, strips out all HTML tags and returns it.
|
||||
// StripHTML accepts a string, strips out all HTML tags and returns it.
|
||||
func StripHTML(s string) string {
|
||||
output := ""
|
||||
|
||||
@@ -72,7 +74,7 @@ func StripEmptyNav(in []byte) []byte {
|
||||
return bytes.Replace(in, []byte("<nav>\n</nav>\n\n"), []byte(``), -1)
|
||||
}
|
||||
|
||||
//BytesToHTML converts bytes to type template.HTML.
|
||||
// BytesToHTML converts bytes to type template.HTML.
|
||||
func BytesToHTML(b []byte) template.HTML {
|
||||
return template.HTML(string(b))
|
||||
}
|
||||
@@ -127,7 +129,7 @@ func MarkdownRenderWithTOC(ctx RenderingContext) []byte {
|
||||
GetMarkdownExtensions())
|
||||
}
|
||||
|
||||
//ExtractTOC extracts Table of Contents from content.
|
||||
// ExtractTOC extracts Table of Contents from content.
|
||||
func ExtractTOC(content []byte) (newcontent []byte, toc []byte) {
|
||||
origContent := make([]byte, len(content))
|
||||
copy(origContent, content)
|
||||
@@ -197,7 +199,7 @@ func TotalWords(s string) int {
|
||||
return len(strings.Fields(s))
|
||||
}
|
||||
|
||||
//WordCount takes content and returns a map of words and count of each word.
|
||||
// WordCount takes content and returns a map of words and count of each word.
|
||||
func WordCount(s string) map[string]int {
|
||||
m := make(map[string]int)
|
||||
for _, f := range strings.Fields(s) {
|
||||
@@ -207,12 +209,13 @@ func WordCount(s string) map[string]int {
|
||||
return m
|
||||
}
|
||||
|
||||
//RemoveSummaryDivider removes summary-divider <!--more--> from content.
|
||||
// RemoveSummaryDivider removes summary-divider <!--more--> from content.
|
||||
func RemoveSummaryDivider(content []byte) []byte {
|
||||
return bytes.Replace(content, SummaryDivider, []byte(""), -1)
|
||||
}
|
||||
|
||||
//TruncateWords takes content and na int and shortens down the number of words in the content down to the number of int.
|
||||
// TruncateWords takes content and an int and shortens down the number
|
||||
// of words in the content down to the number of int.
|
||||
func TruncateWords(s string, max int) string {
|
||||
words := strings.Fields(s)
|
||||
if max > len(words) {
|
||||
@@ -222,7 +225,8 @@ func TruncateWords(s string, max int) string {
|
||||
return strings.Join(words[:max], " ")
|
||||
}
|
||||
|
||||
//TruncateWordsToWholeSentence takes content and an int and returns entire sentences from content, delimited by the int.
|
||||
// TruncateWordsToWholeSentence takes content and an int
|
||||
// and returns entire sentences from content, delimited by the int.
|
||||
func TruncateWordsToWholeSentence(s string, max int) string {
|
||||
words := strings.Fields(s)
|
||||
if max > len(words) {
|
||||
@@ -241,6 +245,8 @@ func TruncateWordsToWholeSentence(s string, max int) string {
|
||||
return strings.Join(words[:max], " ")
|
||||
}
|
||||
|
||||
// GetRstContent calls the Python script rst2html as an external helper
|
||||
// to convert reStructuredText content to HTML.
|
||||
func GetRstContent(content []byte) string {
|
||||
cleanContent := bytes.Replace(content, SummaryDivider, []byte(""), 1)
|
||||
|
||||
|
Reference in New Issue
Block a user