diff --git a/editor/src/markdown-tag.js b/editor/src/markdown-tag.js index b3a3862..a930069 100644 --- a/editor/src/markdown-tag.js +++ b/editor/src/markdown-tag.js @@ -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 } diff --git a/main.go b/main.go index e812b95..3a1fe3a 100644 --- a/main.go +++ b/main.go @@ -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 { 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(`%s`, url.PathEscape(cleanNameURL(s)), s) + }) + return pageText }