This commit is contained in:
parent
7152f154ab
commit
191db91095
15
main.go
15
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(`<a href=%q class="tag">%s</a>`, strings.Replace(s, " ", "_", -1), s)
|
||||
return fmt.Sprintf(`<a href=%q class="tag">%s</a>`, 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,
|
||||
|
|
12
util.go
12
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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user