Action
Markdown Link
Last update
over 7 years ago
- Unlisted
Insert Markdown link “”. If there is a text selection, use it as the link text, if a URL is in the clipboard, place it as the link.
Steps
-
script
/* ### Create Markdown link #### if text in clipboard is NOT a URL: - If no text is selected, insert []() in cursor position, leaving cursor ready to type link text. - If text is selected, insert [selectedText]() leaving cursor in parens to type URL. #### If URL in Clipboard: - If no text is selected, insert [](urlFromClipboard) in cursor position, leaving cursor ready to type link text - If text is selected, insert [selectedText](urlFromClipboard) leaving cursor after close parens. */ // helper to test for URL function isUrl(s) { var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/ return regexp.test(s); } // get clipboard and test if it's a URL var clip = app.getClipboard(); var link = ""; if (isUrl(clip)) { link = clip; } var sel = editor.getSelectedText(); var selRange = editor.getSelectedRange(); if (!sel || sel.length == 0) { editor.setSelectedText("[](" + link + ")"); editor.setSelectedRange(selRange[0]+1,0); } else { editor.setSelectedText("["+sel+"](" + link + ")"); editor.setSelectedRange(selRange[0]+selRange[1]+link.length+4,0); }
Options
-
After Success Nothing Notification Error Log Level Error
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.