diff --git a/selected-markdown-to-slack/info.json b/selected-markdown-to-slack/info.json new file mode 100644 index 0000000..7a785e3 --- /dev/null +++ b/selected-markdown-to-slack/info.json @@ -0,0 +1,9 @@ +{ + "name": "Selected Markdown to Slack", + "identifier": "selected-markdown-to-slack", + "script": "selected-markdown-to-slack.qml", + "authors": ["@pbek"], + "version": "0.0.1", + "minAppVersion": "17.05.7", + "description" : "With this script you can right click the selected Markdown-text and convert it to Markdown-text that is better understood by Slack in the clipboard." +} diff --git a/selected-markdown-to-slack/selected-markdown-to-slack.qml b/selected-markdown-to-slack/selected-markdown-to-slack.qml new file mode 100644 index 0000000..6bc26a2 --- /dev/null +++ b/selected-markdown-to-slack/selected-markdown-to-slack.qml @@ -0,0 +1,41 @@ +import QtQml 2.0 +import QOwnNotesTypes 1.0 + +/** + * This script creates a menu item and a button that converts the selected Markdown-text + * to Markdown-text that is better understood by Slack (https://slack.com) in the clipboard + */ +Script { + /** + * Initializes the custom action + */ + function init() { + script.registerCustomAction("markdownToSlack", "Markdown to Slack", "Slack", "edit-copy", true, true); + } + + /** + * This function is invoked when a custom action is triggered + * in the menu or via button + * + * @param identifier string the identifier defined in registerCustomAction + */ + function customActionInvoked(identifier) { + if (identifier != "markdownToSlack") { + return; + } + + // get the selected text from the note text edit + var text = script.noteTextEditSelectedText(); + + // remove unordered lists +// text = text.replace(/^-/gm, ""); +// text = text.replace(/\t-/gm, ""); + + // change links + text = text.replace(/<(http.+?)>/mg, "\$1"); + text = text.replace(/\[(.+?)\]\((http.+?)\)/mg, "\$1 (\$2)"); + + // put the result into the clipboard + script.setClipboardText(text); + } +}