diff --git a/main.go b/main.go
index c79889c..3603970 100644
--- a/main.go
+++ b/main.go
@@ -274,7 +274,7 @@ func (h *historyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
err = t.Execute(w, historyPage{
Session: sess,
- Title: "History of " + strings.Replace(page, "_", " ", -1),
+ Title: "History of " + cleanTitle(page),
Name: page,
History: history,
})
@@ -384,7 +384,7 @@ func (h *editHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
data := editPage{
Session: sess,
- Title: strings.Replace(page, "_", " ", -1),
+ Title: cleanTitle(page),
Content: pageText,
Editor: editor,
Name: page,
@@ -456,7 +456,10 @@ func (h *indexHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
}
- hrefRE := regexp.MustCompile(`#?\[\[\s*([\w.\- ]+)\s*\]\]`)
+ hrefRE, err := regexp.Compile(`#?\[\[\s*([^\]]+)\s*\]\]`)
+ if err != nil {
+ log.Fatal(err)
+ }
pageText = hrefRE.ReplaceAllStringFunc(pageText, func(s string) string {
tag := false
@@ -469,9 +472,9 @@ func (h *indexHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
s = strings.TrimSuffix(s, "]]")
s = strings.TrimSpace(s)
if tag {
- return fmt.Sprintf(`%s`, strings.Replace(s, " ", "_", -1), s)
+ return fmt.Sprintf(`%s`, cleanNameURL(s), s)
}
- return fmt.Sprintf("[%s](/%s)", s, strings.Replace(s, " ", "_", -1))
+ return fmt.Sprintf("[%s](/%s)", s, cleanNameURL(s))
})
md := markdown.New(
@@ -482,7 +485,7 @@ func (h *indexHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
data := indexPage{
Session: sess,
- Title: strings.Replace(page, "_", " ", -1),
+ Title: cleanTitle(page),
Content: template.HTML(pageText),
Name: page,
Backrefs: mpPage.Refs,
diff --git a/util.go b/util.go
index 7d92ba1..723c957 100644
--- a/util.go
+++ b/util.go
@@ -29,7 +29,7 @@ func RandStringBytes(n int) string {
}
func ParseLinks(content string) ([]ParsedLink, error) {
- hrefRE := regexp.MustCompile(`#?\[\[\s*([\w.\- ]+)\s*\]\]`)
+ hrefRE := regexp.MustCompile(`#?\[\[\s*([^\]]+)\s*\]\]`)
links := hrefRE.FindAllStringSubmatch(content, -1)
@@ -46,9 +46,17 @@ func ParseLinks(content string) ([]ParsedLink, error) {
link = strings.TrimSuffix(link, "]]")
link = strings.TrimSpace(link)
- l := strings.Replace(link, " ", "_", -1)
+ l := cleanNameURL(link)
result = append(result, ParsedLink{link, l})
}
return result, nil
}
+
+func cleanNameURL(name string) string {
+ return strings.Replace(name, " ", "_", -1)
+}
+
+func cleanTitle(name string) string {
+ return strings.Replace(name, "_", " ", -1)
+}