Browse Source

Problem: tags are not parsed in the backend

Solution: replace tag with markdown links
master
Peter Stuifzand 4 months ago
parent
commit
569bef3226
  1. 2
      editor/src/markdown-tag.js
  2. 14
      main.go

2
editor/src/markdown-tag.js

@ -24,7 +24,7 @@ Plugin.prototype.init = function (md) { @@ -24,7 +24,7 @@ Plugin.prototype.init = function (md) {
export function tagParser(id, state, silent) {
let input = state.src.slice(state.pos);
const match = /^#[^ ]+/.exec(input)
const match = /^#\S+/.exec(input)
if (!match) {
return false
}

14
main.go

@ -922,11 +922,7 @@ func (h *indexHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { @@ -922,11 +922,7 @@ func (h *indexHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
func renderLinks(pageText string, edit bool) string {
hrefRE, err := regexp.Compile(`#?\[\[\s*([^\]]+)\s*\]\]`)
if err != nil {
log.Fatal(err)
}
hrefRE := regexp.MustCompile(`#?\[\[\s*([^\]]+)\s*\]\]`)
pageText = hrefRE.ReplaceAllStringFunc(pageText, func(s string) string {
tag := false
if s[0] == '#' {
@ -955,6 +951,14 @@ func renderLinks(pageText string, edit bool) string { @@ -955,6 +951,14 @@ func renderLinks(pageText string, edit bool) string {
return fmt.Sprintf("[%s](/%s%s)", s, editPart, cleanNameURL(s))
})
tagRE := regexp.MustCompile(`#(\S+)`)
pageText = tagRE.ReplaceAllStringFunc(pageText, func(s string) string {
s = strings.TrimPrefix(s, "#")
s = strings.TrimSpace(s)
return fmt.Sprintf(`<a href="/%s" class="tag">%s</a>`, url.PathEscape(cleanNameURL(s)), s)
})
return pageText
}

Loading…
Cancel
Save