Create tags by prefixing links with "#"
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
1d6956f81c
commit
1d24f5cd86
15
main.go
15
main.go
|
@ -412,15 +412,20 @@ func (h *indexHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !jsonPage {
|
if !jsonPage {
|
||||||
hrefRE := regexp.MustCompile(`\[\[\s*([\w.\- ]+)\s*\]\]`)
|
hrefRE := regexp.MustCompile(`#?\[\[\s*([\w.\- ]+)\s*\]\]`)
|
||||||
|
|
||||||
pageText = hrefRE.ReplaceAllStringFunc(pageText, func(s string) string {
|
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.TrimSuffix(s, "]]")
|
||||||
s = strings.TrimSpace(s)
|
s = strings.TrimSpace(s)
|
||||||
if !mp.Exist(s) {
|
if tag {
|
||||||
// return fmt.Sprintf("<a href=%q class=%q>%s</a>", s, "edit", s)
|
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))
|
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("[%s](/%s)", s, strings.Replace(s, " ", "_", -1))
|
return fmt.Sprintf("[%s](/%s)", s, strings.Replace(s, " ", "_", -1))
|
||||||
})
|
})
|
||||||
|
|
|
@ -22,5 +22,8 @@
|
||||||
.edit {
|
.edit {
|
||||||
color: red;
|
color: red;
|
||||||
}
|
}
|
||||||
|
.tag {
|
||||||
|
color: #444;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user