Compare commits
2 Commits
0936963aaf
...
6c6cec6298
Author | SHA1 | Date |
---|---|---|
Přemysl Eric Janouch | 6c6cec6298 | |
Přemysl Eric Janouch | cbf8678681 |
|
@ -23,7 +23,7 @@
|
|||
{{ if .Container }}
|
||||
<section>
|
||||
<header>
|
||||
<h2>{{ .Container.Id }}
|
||||
<h2><a href="container?id={{ .Container.Id }}">{{ .Container.Id }}</a>
|
||||
{{- range .Container.Path }}
|
||||
<small>« <a href="container?id={{ . }}">{{ . }}</a></small>
|
||||
{{- end }}
|
||||
|
|
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"html"
|
||||
"html/template"
|
||||
"io"
|
||||
"log"
|
||||
|
@ -11,6 +12,7 @@ import (
|
|||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
@ -355,6 +357,19 @@ var funcMap = template.FuncMap{
|
|||
"lines": func(s string) int {
|
||||
return strings.Count(s, "\n") + 1
|
||||
},
|
||||
"highlight": func(highlight, s string) template.HTML {
|
||||
b, last := strings.Builder{}, 0
|
||||
for _, m := range regexp.MustCompile(
|
||||
`(?i:`+regexp.QuoteMeta(highlight)+`)`).FindAllStringIndex(s, -1) {
|
||||
b.WriteString(html.EscapeString(s[last:m[0]]))
|
||||
b.WriteString(`<mark>`)
|
||||
b.WriteString(html.EscapeString(s[m[0]:m[1]]))
|
||||
b.WriteString(`</mark>`)
|
||||
last = m[1]
|
||||
}
|
||||
b.WriteString(html.EscapeString(s[last:]))
|
||||
return template.HTML(b.String())
|
||||
},
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
<section>
|
||||
<header>
|
||||
<h3><a href="series?prefix={{ .Prefix }}">{{ .Prefix }}</a></h3>
|
||||
<p>{{ .Description }}
|
||||
<p>{{ .Description | highlight $.Query }}
|
||||
</header>
|
||||
</section>
|
||||
{{ else }}
|
||||
|
@ -28,7 +28,7 @@
|
|||
</h3>
|
||||
</header>
|
||||
{{- if .Description }}
|
||||
<p>{{ .Description }}
|
||||
<p>{{ .Description | highlight $.Query }}
|
||||
{{- end }}
|
||||
</section>
|
||||
{{ else }}
|
||||
|
|
Loading…
Reference in New Issue