]> git.ipfire.org Git - ipfire.org.git/blobdiff - src/static/js/editor.js
wiki: Add code feature to editor
[ipfire.org.git] / src / static / js / editor.js
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() {