mirror of
https://github.com/marty-oehme/scripts.git
synced 2024-12-22 16:08:09 +00:00
added selected-markdown-to-jira script
This commit is contained in:
parent
6a9232c2d9
commit
00e22d90f8
2 changed files with 72 additions and 0 deletions
9
selected-markdown-to-jira/info.json
Normal file
9
selected-markdown-to-jira/info.json
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"name": "Selected Markdown to Jira",
|
||||||
|
"identifier": "selected-markdown-to-jira",
|
||||||
|
"script": "selected-markdown-to-jira.qml",
|
||||||
|
"authors": ["@pbek"],
|
||||||
|
"version": "0.0.1",
|
||||||
|
"minAppVersion": "17.05.7",
|
||||||
|
"description" : "With this script you can right click the selected text and convert it to Jira Code.\n\n<b>Dependencies</b>\n\n<a href=\"https://nodejs.org/en/download/\">Node.js</a>\n<a href=\"https://github.com/kylefarris/J2M\">jira2md</a>\n\n<b>Installation</b>\nAfter you have installed <i>Node.js</i> you can install <i>jira2md</i> by typing:\n<code>npm install jira2md</code>"
|
||||||
|
}
|
63
selected-markdown-to-jira/selected-markdown-to-jira.qml
Normal file
63
selected-markdown-to-jira/selected-markdown-to-jira.qml
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
import QtQml 2.0
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This script creates a menu item and a button that converts the selected Markdown
|
||||||
|
* text to Jira code in the clipboard
|
||||||
|
*
|
||||||
|
* Dependencies:
|
||||||
|
* Node.js: https://nodejs.org/en/download/
|
||||||
|
* https://github.com/kylefarris/J2M
|
||||||
|
*
|
||||||
|
* first you have to install jira2md:
|
||||||
|
* npm install jira2md
|
||||||
|
*/
|
||||||
|
QtObject {
|
||||||
|
property string nodejsExecutablePath;
|
||||||
|
|
||||||
|
// register your settings variables so the user can set them in the script settings
|
||||||
|
property variant settingsVariables: [
|
||||||
|
{
|
||||||
|
"identifier": "nodejsExecutablePath",
|
||||||
|
"name": "Node.js path",
|
||||||
|
"description": "Please select the path to your Node.js executable:",
|
||||||
|
"type": "file",
|
||||||
|
"default": "nodejs",
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the custom action
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
script.registerCustomAction("markdownToJira", "Markdown to Jira", "Jira", "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 != "markdownToJira") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the selected text from the note text edit
|
||||||
|
var text = script.noteTextEditSelectedText();
|
||||||
|
|
||||||
|
// fix unordered lists
|
||||||
|
text = text.replace(/^-/gm, "*");
|
||||||
|
text = text.replace(/\t-/gm, "\t*");
|
||||||
|
|
||||||
|
// you need NodeJs and jira2md (https://github.com/kylefarris/J2M) to convert Markdown to Jira
|
||||||
|
var params = ["-e", "console.log(require('jira2md').to_jira(require('fs').readFileSync('/dev/stdin').toString()))"];
|
||||||
|
var result = script.startSynchronousProcess(nodejsExecutablePath, params, text);
|
||||||
|
|
||||||
|
// replace some names
|
||||||
|
result = String(result).replace(/\@Georg/ig, "[~g.franz]");
|
||||||
|
|
||||||
|
// put the result into the clipboard
|
||||||
|
script.setClipboardText(result);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue