From 7b7e69819e0095fe1ea0daae08688dded5bfa634 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Tue, 27 Aug 2019 14:50:46 +0100 Subject: [PATCH] wiki: Support links in editor Signed-off-by: Michael Tremer --- src/static/js/editor.js | 18 ++++++++++++++++++ src/templates/wiki/edit.html | 5 +++++ 2 files changed, 23 insertions(+) diff --git a/src/static/js/editor.js b/src/static/js/editor.js index 2e3c57a4..148eb69a 100644 --- a/src/static/js/editor.js +++ b/src/static/js/editor.js @@ -61,6 +61,11 @@ class Editor { case 72: editor.headline(); break; + + // L - Link + case 76: + editor.link(); + break; } }); } @@ -75,6 +80,9 @@ class Editor { this.parent.find("#headline").click(this.headline.bind(this)); this.parent.find("#headline-down").click(this.headline_down.bind(this)); this.parent.find("#headline-up").click(this.headline_up.bind(this)); + + // Links + this.parent.find("#link").click(this.link.bind(this)); } // Functions to modify the text @@ -112,6 +120,16 @@ class Editor { } } + link() { + // Handle URLs + if (this.selection.text.startsWith("https://") || this.selection.text.startsWith("http://")) { + this.replaceSelection("[" + this.selection.text + "](" + this.selection.text + ")"); + // Handle selected text + } else { + this.replaceSelection("[" + this.selection.text + "]()") + } + } + // Headlines findLevel() { diff --git a/src/templates/wiki/edit.html b/src/templates/wiki/edit.html index c231a419..8977e0e4 100644 --- a/src/templates/wiki/edit.html +++ b/src/templates/wiki/edit.html @@ -52,6 +52,11 @@ + + -- 2.47.2