// highlight returns an HTML string with syntax highlighting applied.
func highlight(in interface{}, lang, opts string) (template.HTML, error) {
	str, err := cast.ToStringE(in)

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

	return template.HTML(helpers.Highlight(html.UnescapeString(str), lang, opts)), nil
}
Exemple #2
0
func Highlight(in interface{}, lang, opts string) template.HTML {
	var str string
	av := reflect.ValueOf(in)
	switch av.Kind() {
	case reflect.String:
		str = av.String()
	}

	return template.HTML(helpers.Highlight(html.UnescapeString(str), lang, opts))
}
Exemple #3
0
func Highlight(in interface{}, lang string) template.HTML {
	var str string
	av := reflect.ValueOf(in)
	switch av.Kind() {
	case reflect.String:
		str = av.String()
	}

	if strings.HasPrefix(strings.TrimSpace(str), "<pre><code>") {
		str = str[strings.Index(str, "<pre><code>")+11:]
	}
	if strings.HasSuffix(strings.TrimSpace(str), "</code></pre>") {
		str = str[:strings.LastIndex(str, "</code></pre>")]
	}
	return template.HTML(helpers.Highlight(html.UnescapeString(str), lang))
}