From d0c23ca5d156f1e2b4d5e1edaeca5813a14227a8 Mon Sep 17 00:00:00 2001 From: NikhilWanpal Date: Tue, 13 Feb 2018 15:16:01 +0530 Subject: [PATCH] Feature: pass additional params to plantuml jar. Feature: Hide plantuml markup in preview. BugFix: removed dev specifc default path --- render-plantuml/info.json | 2 +- render-plantuml/render-plantuml.qml | 51 +++++++++++++++++++---------- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/render-plantuml/info.json b/render-plantuml/info.json index ec9531a..3f12728 100644 --- a/render-plantuml/info.json +++ b/render-plantuml/info.json @@ -3,7 +3,7 @@ "identifier": "render-plantuml", "script": "render-plantuml.qml", "authors": ["@nikhilw"], - "version": "0.0.1", + "version": "0.0.2", "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 (https://nodejs.org/en/download/), java (https://java.com/en/download/) and plantuml (http://plantuml.com/download) to be installed. Install node and java. download the plantuml jar and provide the full path in script settings." } diff --git a/render-plantuml/render-plantuml.qml b/render-plantuml/render-plantuml.qml index 5ba50d6..54dbcb3 100644 --- a/render-plantuml/render-plantuml.qml +++ b/render-plantuml/render-plantuml.qml @@ -15,6 +15,8 @@ QtObject { property string javaExePath; property string plantumlJarPath; property string workDir; + property string hideMarkup; + property string additionalParams; // register your settings variables so the user can set them in the script settings property variant settingsVariables: [ @@ -30,7 +32,7 @@ QtObject { "name": "Path to plantuml jar", "description": "Please enter absolute path to plantuml jar file:", "type": "file", - "default": "/home/nikhil/softs/plantuml/plantuml.jar" + "default": "/opt/softs/plantuml/plantuml.jar" }, { "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:", "type": "file", "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 */ 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; html = html.replace(/
([\s\S]*?)<\/pre>/gmi, function(matchedStr, g1) {
-        	var matchedUml = g1.replace(/\n/gi, "\\n");
-			var filePath = workDir + "/" + note.id + "_" + (++index);
-			var plantumlFilePath = filePath + ".plantuml";
+            var matchedUml = g1.replace(/\n/gi, "\\n");
+            var filePath = workDir + "/" + note.id + "_" + (++index);
+            var plantumlFilePath = filePath + ".plantuml";
 
-			var params = ["-e", "require('fs').writeFileSync('" + plantumlFilePath + "', \"" + matchedUml + "\", 'utf8');"];
-        	var result = script.startSynchronousProcess("node", params, html);
-        	
-//			script.log(additionalPumlParams);
-        	params = ["-jar", plantumlJarPath, "-o", workDir, " ", plantumlFilePath];
-        	result = script.startSynchronousProcess(javaExePath, params, html); //["-jar", plantumlJarPath, "-o", workDir, filePath]
-        	
-        	return "
\"Wait
" + matchedStr; + var params = ["-e", "require('fs').writeFileSync('" + plantumlFilePath + "', \"" + matchedUml + "\", 'utf8');"]; + var result = script.startSynchronousProcess("node", params, html); + + params = ["-jar", plantumlJarPath, "-o", workDir, additionalParams, plantumlFilePath]; + result = script.startSynchronousProcess(javaExePath, params, html); + + var imgElement = "
\"Wait
"; + + if (hideMarkup == "true") { + return imgElement; + } else { + return imgElement + matchedStr; + } }); return html; @@ -75,8 +96,4 @@ QtObject { } // 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. - -