mirror of
https://github.com/marty-oehme/scripts.git
synced 2024-12-22 16:08:09 +00:00
Feature: pass additional params to plantuml jar. Feature: Hide plantuml markup in preview. BugFix: removed dev specifc default path
This commit is contained in:
parent
adc513dd7d
commit
d0c23ca5d1
2 changed files with 35 additions and 18 deletions
|
@ -3,7 +3,7 @@
|
||||||
"identifier": "render-plantuml",
|
"identifier": "render-plantuml",
|
||||||
"script": "render-plantuml.qml",
|
"script": "render-plantuml.qml",
|
||||||
"authors": ["@nikhilw"],
|
"authors": ["@nikhilw"],
|
||||||
"version": "0.0.1",
|
"version": "0.0.2",
|
||||||
"minAppVersion": "17.05.7",
|
"minAppVersion": "17.05.7",
|
||||||
"description" : "This script renders any plantuml text embedded in a note with the language hint, into a uml diagram. It needs node.js (<a href=\"https://nodejs.org/en/download/\">https://nodejs.org/en/download/</a>), java (<a href=\"https://java.com/en/download/\">https://java.com/en/download/</a>) and plantuml (<a href=\"http://plantuml.com/download\">http://plantuml.com/download</a>) to be installed. Install node and java. download the plantuml jar and provide the full path in script settings."
|
"description" : "This script renders any plantuml text embedded in a note with the language hint, into a uml diagram. It needs node.js (<a href=\"https://nodejs.org/en/download/\">https://nodejs.org/en/download/</a>), java (<a href=\"https://java.com/en/download/\">https://java.com/en/download/</a>) and plantuml (<a href=\"http://plantuml.com/download\">http://plantuml.com/download</a>) to be installed. Install node and java. download the plantuml jar and provide the full path in script settings."
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,8 @@ QtObject {
|
||||||
property string javaExePath;
|
property string javaExePath;
|
||||||
property string plantumlJarPath;
|
property string plantumlJarPath;
|
||||||
property string workDir;
|
property string workDir;
|
||||||
|
property string hideMarkup;
|
||||||
|
property string additionalParams;
|
||||||
|
|
||||||
// register your settings variables so the user can set them in the script settings
|
// register your settings variables so the user can set them in the script settings
|
||||||
property variant settingsVariables: [
|
property variant settingsVariables: [
|
||||||
|
@ -30,7 +32,7 @@ QtObject {
|
||||||
"name": "Path to plantuml jar",
|
"name": "Path to plantuml jar",
|
||||||
"description": "Please enter absolute path to plantuml jar file:",
|
"description": "Please enter absolute path to plantuml jar file:",
|
||||||
"type": "file",
|
"type": "file",
|
||||||
"default": "/home/nikhil/softs/plantuml/plantuml.jar"
|
"default": "/opt/softs/plantuml/plantuml.jar"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"identifier": "workDir",
|
"identifier": "workDir",
|
||||||
|
@ -38,6 +40,20 @@ QtObject {
|
||||||
"description": "Please enter a path to be used as working directory i.e. temporary directory for file creation:",
|
"description": "Please enter a path to be used as working directory i.e. temporary directory for file creation:",
|
||||||
"type": "file",
|
"type": "file",
|
||||||
"default": "/tmp"
|
"default": "/tmp"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"identifier": "hideMarkup",
|
||||||
|
"name": "Hide plantuml markup",
|
||||||
|
"description": "Enable if you wish to hide plantuml markup in preview.",
|
||||||
|
"type": "boolean",
|
||||||
|
"default": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"identifier": "additionalParams",
|
||||||
|
"name": "Additional Params (Advanced)",
|
||||||
|
"description": "Enter any additional parameters you wish to pass to plantuml. This can potentially cause unexpected behaviour:",
|
||||||
|
"type": "string",
|
||||||
|
"default": ""
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -52,22 +68,27 @@ QtObject {
|
||||||
* @return {string} the modfied html or an empty string if nothing should be modified
|
* @return {string} the modfied html or an empty string if nothing should be modified
|
||||||
*/
|
*/
|
||||||
function noteToMarkdownHtmlHook(note, html) {
|
function noteToMarkdownHtmlHook(note, html) {
|
||||||
var matches = html.match(/language-plantuml\"\>([\s\S]*?)<\/pre/gmi);
|
//var matches = html.match(/language-plantuml\"\>([\s\S]*?)<\/pre/gmi);
|
||||||
|
|
||||||
var index = 0;
|
var index = 0;
|
||||||
html = html.replace(/<pre><code class=\"language-plantuml\"\>([\s\S]*?)<\/pre>/gmi, function(matchedStr, g1) {
|
html = html.replace(/<pre><code class=\"language-plantuml\"\>([\s\S]*?)<\/pre>/gmi, function(matchedStr, g1) {
|
||||||
var matchedUml = g1.replace(/\n/gi, "\\n");
|
var matchedUml = g1.replace(/\n/gi, "\\n");
|
||||||
var filePath = workDir + "/" + note.id + "_" + (++index);
|
var filePath = workDir + "/" + note.id + "_" + (++index);
|
||||||
var plantumlFilePath = filePath + ".plantuml";
|
var plantumlFilePath = filePath + ".plantuml";
|
||||||
|
|
||||||
var params = ["-e", "require('fs').writeFileSync('" + plantumlFilePath + "', \"" + matchedUml + "\", 'utf8');"];
|
var params = ["-e", "require('fs').writeFileSync('" + plantumlFilePath + "', \"" + matchedUml + "\", 'utf8');"];
|
||||||
var result = script.startSynchronousProcess("node", params, html);
|
var result = script.startSynchronousProcess("node", params, html);
|
||||||
|
|
||||||
// script.log(additionalPumlParams);
|
params = ["-jar", plantumlJarPath, "-o", workDir, additionalParams, plantumlFilePath];
|
||||||
params = ["-jar", plantumlJarPath, "-o", workDir, " ", plantumlFilePath];
|
result = script.startSynchronousProcess(javaExePath, params, html);
|
||||||
result = script.startSynchronousProcess(javaExePath, params, html); //["-jar", plantumlJarPath, "-o", workDir, filePath]
|
|
||||||
|
|
||||||
return "<div><img src=\"file://" + filePath + ".png\" alt=\"Wait for it..\"/></div>" + matchedStr;
|
var imgElement = "<div><img src=\"file://" + filePath + ".png?t=" + +(new Date()) + "\" alt=\"Wait for it..\"/></div>";
|
||||||
|
|
||||||
|
if (hideMarkup == "true") {
|
||||||
|
return imgElement;
|
||||||
|
} else {
|
||||||
|
return imgElement + matchedStr;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return html;
|
return html;
|
||||||
|
@ -75,8 +96,4 @@ QtObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Future plans:
|
// Future plans:
|
||||||
// TODO: Allow for passingin addtional parameters to plantuml.
|
|
||||||
// TODO: Allow for replacing the markup in the rendered preview with image instead of keeping both.
|
|
||||||
// TODO: Optimize image creation by combining img generation in a single java command instead of in a loop.
|
// TODO: Optimize image creation by combining img generation in a single java command instead of in a loop.
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue