From 522c4c62834c7b03a103000a3208ce4893364e5d Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Wed, 22 Mar 2017 10:59:48 -0600 Subject: [PATCH] Allow [[link]] for internal links Former-commit-id: aefb0d00cd7f493ec8706d890eec1eb1510b7092 [formerly 400d9b4158b49fdd6b6910f772f02fc4f82fd2f6] [formerly 99230db788cdfac4fe4fa7e1266fbe77a54f60bf [formerly 420f56843f0f6bbecf4ec7a6c755be5333162b7a]] Former-commit-id: d780226ab14e3b022d497021ddc66c7d2e1be423 [formerly 6c38cf48fc1889ddef0dd1f9b7c36f0ed6525907] Former-commit-id: 82e848729b0ea8b8deb5a310847490f5f22ad114 --- page.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/page.go b/page.go index 37f16ce..5a5c60c 100755 --- a/page.go +++ b/page.go @@ -5,10 +5,13 @@ import ( "io/ioutil" "os" "path" + "regexp" + "strings" "github.com/schollz/versionedtext" ) +// Page is the basic struct type Page struct { Name string Text versionedtext.VersionedText @@ -46,6 +49,14 @@ func (p *Page) Render() { p.RenderedPage = "" + p.Text.GetCurrent() + "" 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()) }