Add more options to highlight

Fixes #1021
This commit is contained in:
bep
2015-04-15 20:31:05 +02:00
parent be540f5b8f
commit be24457acf
5 changed files with 149 additions and 27 deletions

View File

@@ -21,7 +21,13 @@ type Tmpl struct {
func (t *GoHTMLTemplate) EmbedShortcodes() {
t.AddInternalShortcode("ref.html", `{{ .Get 0 | ref .Page }}`)
t.AddInternalShortcode("relref.html", `{{ .Get 0 | relref .Page }}`)
t.AddInternalShortcode("highlight.html", `{{ .Get 0 | highlight .Inner }}`)
t.AddInternalShortcode("highlight.html", `
{{ if len .Params | eq 2 }}
{{ highlight .Inner (.Get 0) (.Get 1) }}
{{ else }}
{{ highlight .Inner (.Get 0) "" }}
{{ end }}
`)
t.AddInternalShortcode("test.html", `This is a simple Test`)
t.AddInternalShortcode("figure.html", `<!-- image -->
<figure {{ with .Get "class" }}class="{{.}}"{{ end }}>

View File

@@ -875,7 +875,7 @@ func ReturnWhenSet(a, k interface{}) interface{} {
return ""
}
func Highlight(in interface{}, lang string) template.HTML {
func Highlight(in interface{}, lang, opts string) template.HTML {
var str string
av := reflect.ValueOf(in)
switch av.Kind() {
@@ -883,7 +883,7 @@ func Highlight(in interface{}, lang string) template.HTML {
str = av.String()
}
return template.HTML(helpers.Highlight(html.UnescapeString(str), lang))
return template.HTML(helpers.Highlight(html.UnescapeString(str), lang, opts))
}
var markdownTrimPrefix = []byte("<p>")