1
0
Fork 0
mirror of https://github.com/marty-oehme/scripts.git synced 2024-12-21 15:38:09 +00:00

added selected-markdown-to-slack script

This commit is contained in:
Patrizio Bekerle 2017-09-26 10:22:55 +02:00
parent 3871fe3255
commit 432c6e60e1
No known key found for this signature in database
GPG key ID: 2E9FFD770DABE838
2 changed files with 50 additions and 0 deletions

View file

@ -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 <a href='https://slack.com'>Slack</a> in the clipboard."
}

View file

@ -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);
}
}