From 4f6c87c14e4e8d4e73ac2eeb5b4e3104d7cf88a2 Mon Sep 17 00:00:00 2001 From: Peter Stuifzand Date: Wed, 1 Jul 2020 17:36:36 +0200 Subject: [PATCH] Link meta key value --- backref.go | 9 +++++++++ editor/src/index.js | 2 +- main.go | 6 ++++++ markdown.go | 1 + templates/layout.html | 3 ++- 5 files changed, 19 insertions(+), 2 deletions(-) diff --git a/backref.go b/backref.go index 0f18daa..3a13e1c 100644 --- a/backref.go +++ b/backref.go @@ -4,8 +4,10 @@ import ( "encoding/json" "fmt" "html/template" + "log" "os" "path/filepath" + "regexp" "strings" ) @@ -111,6 +113,13 @@ func getBackrefs(fp *FilePages, p string) (map[string][]Backref, error) { if line[0] == '*' && line[1] == ' ' { line = line[2:] } + + metaKV, err := regexp.Compile(`(\w+)::\s+(.*)`) + if err != nil { + log.Fatal(err) + } + line = metaKV.ReplaceAllString(line, "**[[$1]]**: $2") + links := renderLinks(line) pageText := renderMarkdown2(links) diff --git a/editor/src/index.js b/editor/src/index.js index 0c081d1..b66dc8e 100644 --- a/editor/src/index.js +++ b/editor/src/index.js @@ -211,7 +211,7 @@ if (holder) { converted = MD.render(converted) } else { if (text.match(/^(\w+):: (.+)$/)) { - converted = converted.replace(/^(\w+):: (.*)$/, '**$1**: $2') + converted = converted.replace(/^(\w+):: (.*)$/, '**[[$1]]**: $2') } else if (text.match(/#\[\[TODO]]/)) { converted = converted.replace('#[[TODO]]', '') } else if (text.match(/#\[\[DONE]]/)) { diff --git a/main.go b/main.go index 93f1382..706a5a3 100644 --- a/main.go +++ b/main.go @@ -683,6 +683,12 @@ func (h *indexHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } if format == "html" { + metaKV, err := regexp.Compile(`(\w+)::\s+(.*)`) + if err != nil { + log.Fatal(err) + } + pageText = metaKV.ReplaceAllString(pageText, "**[[$1]]**: $2") + pageText = renderLinks(pageText) pageText = renderMarkdown2(pageText) diff --git a/markdown.go b/markdown.go index 6b326f0..5e681fd 100644 --- a/markdown.go +++ b/markdown.go @@ -27,6 +27,7 @@ func renderMarkdown2(pageText string) string { html.WithUnsafe(), ), ) + var buf bytes.Buffer if err := md.Convert([]byte(pageText), &buf); err != nil { panic(err) diff --git a/templates/layout.html b/templates/layout.html index 8ea5446..8b10291 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -17,7 +17,8 @@ } #autocomplete { z-index: 1; - width: 217px; + right: 0; + width: 400px; overflow-x: hidden; overflow-y: auto; height: 300px;