1
0
Fork 0
mirror of https://github.com/marty-oehme/scripts.git synced 2024-11-18 15:58:07 +00:00
qownnotes-scripts/selected-markdown-to-jira/selected-markdown-to-jira.qml

67 lines
2.3 KiB
QML
Raw Normal View History

2017-05-19 14:27:59 +00:00
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*");
2018-04-26 05:59:21 +00:00
// some character escaping
text = text.replace(/\{/gm, "\\{").replace(/\}/gm, "\\}");
2017-05-19 14:27:59 +00:00
// 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
2018-01-31 15:49:04 +00:00
result = String(result).replace(/\@Georg/ig, "[~g.franz]").replace(/\@Jacob/ig, "[~j.ester]").replace(/\@Gandalf/ig, "[~g.sievers]").replace(/\@Dominik/ig, "[~d.jansen]").replace(/\@Adrian/ig, "[~a.lawley]").replace(/\@Bastian/ig, "[~b.widensky]");
2017-05-19 14:27:59 +00:00
// put the result into the clipboard
script.setClipboardText(result);
}
}