Create tags by prefixing links with "#"
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Peter Stuifzand 2020-05-07 14:26:36 +02:00
parent 1d6956f81c
commit 1d24f5cd86
2 changed files with 13 additions and 5 deletions

15
main.go
View File

@ -412,15 +412,20 @@ func (h *indexHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
if !jsonPage {
hrefRE := regexp.MustCompile(`\[\[\s*([\w.\- ]+)\s*\]\]`)
hrefRE := regexp.MustCompile(`#?\[\[\s*([\w.\- ]+)\s*\]\]`)
pageText = hrefRE.ReplaceAllStringFunc(pageText, func(s string) string {
s = strings.TrimPrefix(s, "[[")
tag := false
if s[0] == '#' {
s = strings.TrimPrefix(s, "#[[")
tag = true
} else {
s = strings.TrimPrefix(s, "[[")
}
s = strings.TrimSuffix(s, "]]")
s = strings.TrimSpace(s)
if !mp.Exist(s) {
// return fmt.Sprintf("<a href=%q class=%q>%s</a>", s, "edit", s)
return fmt.Sprintf("%s[?](/%s)", s, strings.Replace(s, " ", "_", -1))
if tag {
return fmt.Sprintf(`<a href=%q class="tag">%s</a>`, strings.Replace(s, " ", "_", -1), s)
}
return fmt.Sprintf("[%s](/%s)", s, strings.Replace(s, " ", "_", -1))
})

View File

@ -22,5 +22,8 @@
.edit {
color: red;
}
.tag {
color: #444;
}
</style>
{{ end }}