mirror of
https://github.com/schollz/cowyo.git
synced 2023-08-10 21:13:00 +03:00
Allow [[link]] for internal links
This commit is contained in:
parent
cf0a8a7f30
commit
420f56843f
11
page.go
11
page.go
@ -5,10 +5,13 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/schollz/versionedtext"
|
"github.com/schollz/versionedtext"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Page is the basic struct
|
||||||
type Page struct {
|
type Page struct {
|
||||||
Name string
|
Name string
|
||||||
Text versionedtext.VersionedText
|
Text versionedtext.VersionedText
|
||||||
@ -46,6 +49,14 @@ func (p *Page) Render() {
|
|||||||
p.RenderedPage = "<code>" + p.Text.GetCurrent() + "</code>"
|
p.RenderedPage = "<code>" + p.Text.GetCurrent() + "</code>"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Convert [[page]] to [page](/page/view)
|
||||||
|
r, _ := regexp.Compile("\\[\\[(.*?)\\]\\]")
|
||||||
|
currentText := p.Text.GetCurrent()
|
||||||
|
for _, s := range r.FindAllString(currentText, -1) {
|
||||||
|
currentText = strings.Replace(currentText, s, "["+s[2:len(s)-2]+"](/"+s[2:len(s)-2]+"/view)", 1)
|
||||||
|
}
|
||||||
|
p.Text.Update(currentText)
|
||||||
p.RenderedPage = MarkdownToHtml(p.Text.GetCurrent())
|
p.RenderedPage = MarkdownToHtml(p.Text.GetCurrent())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user