]> git.ipfire.org Git - ipfire.org.git/commitdiff
wiki: Add code feature to editor
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 27 Aug 2019 13:43:35 +0000 (14:43 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 27 Aug 2019 14:22:54 +0000 (15:22 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/static/js/editor.js
src/templates/wiki/edit.html

index 6311f8706ab5065b32f173d2c757e22aac0466ef..2e3c57a4acaa83e1ad8239210c34d33d9baf0be0 100644 (file)
@@ -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() {
index 16382515e5c7918f67680e97525e47af4b92d1e7..c231a4197639d042f932ae5cda587663f78f0402 100644 (file)
                                                                        id="italic" title="{{ _("Italic") }} [{{ _("Ctrl") }}-I]">
                                                                <i class="fas fa-italic"></i>
                                                        </button>
+                                                       <button type="button" class="btn btn-secondary"
+                                                                       id="code" title="{{ _("Code") }} [{{ _("Ctrl") }}-C]">
+                                                               <i class="fas fa-code"></i>
+                                                       </button>
                                                </div>
 
                                                <div class="btn-group btn-group-sm mr-2" role="group">