Example #1
0
func (p *Page) initPlain() {
	p.plainInit.Do(func() {
		p.plain = helpers.StripHTML(string(p.Content))
		p.plainWords = strings.Fields(p.plain)
		return
	})
}
// plainify strips any HTML and returns the plain text version.
func plainify(in interface{}) (string, error) {
	s, err := cast.ToStringE(in)

	if err != nil {
		return "", err
	}

	return helpers.StripHTML(s), nil
}
// countRunes returns the approximate rune count of the given content.
func countRunes(content interface{}) (int, error) {
	conv, err := cast.ToStringE(content)

	if err != nil {
		return 0, fmt.Errorf("Failed to convert content to string: %s", err.Error())
	}

	counter := 0
	for _, r := range helpers.StripHTML(conv) {
		if !helpers.IsWhitespace(r) {
			counter++
		}
	}

	return counter, nil
}
// countWords returns the approximate word count of the given content.
func countWords(content interface{}) (int, error) {
	conv, err := cast.ToStringE(content)

	if err != nil {
		return 0, fmt.Errorf("Failed to convert content to string: %s", err.Error())
	}

	counter := 0
	for _, word := range strings.Fields(helpers.StripHTML(conv)) {
		runeCount := utf8.RuneCountInString(word)
		if len(word) == runeCount {
			counter++
		} else {
			counter += runeCount
		}
	}

	return counter, nil
}
Example #5
0
func normalizeExpected(ext, str string) string {
	str = normalizeContent(str)
	switch ext {
	default:
		return str
	case "html":
		return strings.Trim(helpers.StripHTML(str), " ")
	case "ad":
		paragraphs := strings.Split(str, "</p>")
		expected := ""
		for _, para := range paragraphs {
			if para == "" {
				continue
			}
			expected += fmt.Sprintf("<div class=\"paragraph\">\n%s</p></div>\n", para)
		}
		return expected
	case "rst":
		return fmt.Sprintf("<div class=\"document\">\n\n\n%s</div>", str)
	}
}
Example #6
0
File: page.go Project: GuoJing/hugo
func (p *Page) Plain() string {
	if len(p.plain) == 0 {
		p.plain = helpers.StripHTML(StripShortcodes(string(p.renderBytes(p.rawContent))))
	}
	return p.plain
}
Example #7
0
func (p *Page) Plain() string {
	if len(p.plain) == 0 {
		p.plain = helpers.StripHTML(string(p.Content))
	}
	return p.plain
}
Example #8
0
func (p *Page) initPlain() {
	p.plainInit.Do(func() {
		p.plain = helpers.StripHTML(string(p.Content))
		return
	})
}