]> git.ipfire.org Git - ipfire.org.git/commitdiff
wiki: Support links in editor
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 27 Aug 2019 13:50:46 +0000 (14:50 +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 2e3c57a4acaa83e1ad8239210c34d33d9baf0be0..148eb69a0e064efe087bad88be8c6ef57d629dd4 100644 (file)
@@ -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() {
index c231a4197639d042f932ae5cda587663f78f0402..8977e0e43e3a5b435bcebfda170e4dab16470de3 100644 (file)
                                                        </button>
                                                </div>
 
+                                               <button type="button" class="btn btn-sm btn-secondary mr-2"
+                                                               id="link" title="{{ _("Link") }} [{{ _("Ctrl") }}-L]">
+                                                       <i class="fas fa-link"></i>
+                                               </button>
+
                                                <a class="btn btn-sm btn-secondary" href="{{ path }}/_files"
                                                                target="_blank" title="{{ _("Files") }}">
                                                        <i class="fas fa-images"></i>