From: Michael Tremer Date: Tue, 27 Aug 2019 13:43:35 +0000 (+0100) Subject: wiki: Add code feature to editor X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8dea0e28c37988d5bf15e291f3ce7ca43049bcd2;p=ipfire.org.git wiki: Add code feature to editor Signed-off-by: Michael Tremer --- diff --git a/src/static/js/editor.js b/src/static/js/editor.js index 6311f870..2e3c57a4 100644 --- a/src/static/js/editor.js +++ b/src/static/js/editor.js @@ -52,6 +52,11 @@ class Editor { editor.italic(); break; + // C - Code + case 67: + editor.code(); + break; + // H - Headline case 72: editor.headline(); @@ -64,6 +69,7 @@ class Editor { // Typography this.parent.find("#bold").click(this.bold.bind(this)); this.parent.find("#italic").click(this.italic.bind(this)); + this.parent.find("#code").click(this.code.bind(this)); // Headlines this.parent.find("#headline").click(this.headline.bind(this)); @@ -96,6 +102,16 @@ class Editor { this.replaceSelection("*" + this.selection.text + "*"); } + code() { + var multiline = this.selection.text.indexOf("\n"); + + if (multiline >= 0) { + this.replaceSelection("```\n" + this.selection.text + "\n```\n\n"); + } else { + this.replaceSelection("`" + this.selection.text + "`"); + } + } + // Headlines findLevel() { diff --git a/src/templates/wiki/edit.html b/src/templates/wiki/edit.html index 16382515..c231a419 100644 --- a/src/templates/wiki/edit.html +++ b/src/templates/wiki/edit.html @@ -31,6 +31,10 @@ id="italic" title="{{ _("Italic") }} [{{ _("Ctrl") }}-I]"> +