From b27332057fd0a99b50fd251a0d37bcff939db383 Mon Sep 17 00:00:00 2001 From: Peter Stuifzand Date: Mon, 1 Jun 2020 01:57:23 +0200 Subject: [PATCH] Support code fenced blocks - Improve rendering of code fence html - Add slash command "Code Block" - Use editor version 0.6.6 --- editor/package-lock.json | 6 +++--- editor/package.json | 2 +- editor/src/fuse.js | 1 + editor/src/index.js | 3 +++ main.go | 26 ++++++++++++++++++++++++-- 5 files changed, 32 insertions(+), 6 deletions(-) diff --git a/editor/package-lock.json b/editor/package-lock.json index 293984b..b80dff1 100644 --- a/editor/package-lock.json +++ b/editor/package-lock.json @@ -7548,9 +7548,9 @@ } }, "wiki-list-editor": { - "version": "0.6.5", - "resolved": "https://registry.npmjs.org/wiki-list-editor/-/wiki-list-editor-0.6.5.tgz", - "integrity": "sha512-1/XQ7JSJoet/TCq5RiF0JAHFZYveI3fEW8drc6gPnAfwz4e2t7vHBZV5sDhFO+z4fD+uISfsBveW4oJzVNteNA==", + "version": "0.6.6", + "resolved": "https://registry.npmjs.org/wiki-list-editor/-/wiki-list-editor-0.6.6.tgz", + "integrity": "sha512-9Kcpr/hKzMXlnb/gI9nMoE1OwXiWT4VpYvel0vjz++du8Z9wU+2qXIl3sWuFZl77stZpyrtKqV5BRhx63KN0RA==", "requires": { "dragula": "^3.7.2", "jquery": "^3.5.1", diff --git a/editor/package.json b/editor/package.json index 5d9183e..b459942 100644 --- a/editor/package.json +++ b/editor/package.json @@ -20,7 +20,7 @@ "node-sass": "^4.14.1", "sass-loader": "^7.3.1", "style-loader": "^1.0.0", - "wiki-list-editor": "^0.6.5" + "wiki-list-editor": "^0.6.6" }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1", diff --git a/editor/src/fuse.js b/editor/src/fuse.js index 9baffda..effd939 100644 --- a/editor/src/fuse.js +++ b/editor/src/fuse.js @@ -15,6 +15,7 @@ function createTitleSearch() { {title: 'Yesterday', name: 'yesterday'}, {title: 'TODO', name: 'todo'}, {title: 'Page Reference', name: 'page_reference'}, + {title: 'Code Block', name: 'code_block'}, ]; const fuseIndex = Fuse.createIndex(options.keys, documents) diff --git a/editor/src/index.js b/editor/src/index.js index 7967e5c..a0bd87b 100644 --- a/editor/src/index.js +++ b/editor/src/index.js @@ -184,6 +184,9 @@ if (holder) { } else if (linkName === "Page Reference") { commandResult = "[[]]" adjustment = -2 + } else if (linkName === "Code Block") { + commandResult = "```\n\n```" + adjustment = -5 } let startAndLink = prefix diff --git a/main.go b/main.go index 86b2497..3a082f0 100644 --- a/main.go +++ b/main.go @@ -473,10 +473,32 @@ func (h *indexHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } - pageText = "" + builder := strings.Builder{} for _, item := range listItems { - pageText += strings.Repeat(" ", item.Indented) + "* " + item.Text + "\n" + lines := strings.Split(item.Text, "\n") + if len(lines) > 1 { + first := true + for _, line := range lines { + if first { + builder.WriteString(strings.Repeat(" ", item.Indented)) + builder.WriteString("* ") + builder.WriteString(line) + builder.WriteByte('\n') + first = false + } else { + builder.WriteString(strings.Repeat(" ", item.Indented+1)) + builder.WriteString(line) + builder.WriteByte('\n') + } + } + } else { + builder.WriteString(strings.Repeat(" ", item.Indented)) + builder.WriteString("* ") + builder.WriteString(item.Text) + builder.WriteByte('\n') + } } + pageText = builder.String() } pageText = renderLinks(pageText)