mirror of
https://github.com/marty-oehme/scripts.git
synced 2024-12-21 23:48:08 +00:00
added selected-markdown-to-slack script
This commit is contained in:
parent
3871fe3255
commit
432c6e60e1
2 changed files with 50 additions and 0 deletions
9
selected-markdown-to-slack/info.json
Normal file
9
selected-markdown-to-slack/info.json
Normal 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."
|
||||||
|
}
|
41
selected-markdown-to-slack/selected-markdown-to-slack.qml
Normal file
41
selected-markdown-to-slack/selected-markdown-to-slack.qml
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue