1
0
Fork 0
mirror of https://github.com/marty-oehme/scripts.git synced 2024-12-22 16:08:09 +00:00
qownnotes-scripts/selected-markdown-to-slack/selected-markdown-to-slack.qml
2017-09-26 10:22:55 +02:00

41 lines
1.2 KiB
QML

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