Skip to content

Commit

Permalink
Merge pull request #199 from cristianofromagio/fix-plantuml-plugin
Browse files Browse the repository at this point in the history
Fix render-plantuml settings variable usage
  • Loading branch information
pbek authored Aug 2, 2023
2 parents 6aaabb4 + 8dc6330 commit 82ea53c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
Binary file modified render-plantuml/Params.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions render-plantuml/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "Support for PlantUML in notes",
"identifier": "render-plantuml",
"script": "render-plantuml.qml",
"authors": ["@nikhilw", "@Beurt"],
"version": "0.1.4",
"authors": ["@nikhilw", "@Beurt", "@cristianofromagio"],
"version": "0.1.5",
"minAppVersion": "20.6.0",
"description" : "This script renders text based diagram descriptions into image files using the program PlantUML.\n\n<b>Features</b>\n\n- Backround diagram rendering\n- Offline rendering\n- Cache system that renders only new or modified diagram descriptions\n- Diagram rendering in PNG or SVG\n- Context menu to add header/footer of most PlantUML diagram types\n\n<b>Dependencies</b>\n\nIt needs 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.\n\n<b>Installation</b>\n\n1. Download PlantUML with GraphViz support.\n2. Verify or install JAVA or OpenJDK.\n3. In QOwnNotes, go to \"Scripting→Find scripts in script repository\" menu. And install \"Support for PlantUML in notes\".\n4. In the script parameters below configure JAVA and plantuml.jar full paths.\n5. Enjoy!"
}
22 changes: 11 additions & 11 deletions render-plantuml/render-plantuml.qml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ QtObject {
"identifier": "workDir",
"name": "Working directory",
"description": "Please enter a path to be used as working directory i.e. temporary directory for file creation:",
"type": "file",
"type": "directory",
"default": ""
},
{
Expand All @@ -58,10 +58,11 @@ QtObject {
},
{
"identifier": "svgOrPng",
"name": "SVG output format (default: PNG)",
"description": "Enable if you want to use SVG as output format instead of the default PNG format",
"type": "boolean",
"default": false
"name": "Image output format (default: PNG)",
"description": "Please select a format:",
"type": "selection",
"default": "png",
"items": {"png": "png", "svg": "svg"},
},
{
"identifier": "additionalParams",
Expand All @@ -71,7 +72,7 @@ QtObject {
"default": ""
}
];

function init() {
script.registerCustomAction("insertPumlDiagram", "PUML: insert Diagram", "", "",1);
script.registerCustomAction("insertPumlGraphviz", "PUML: insert Graphviz Diagram", "", "",1);
Expand Down Expand Up @@ -142,7 +143,7 @@ QtObject {
break;
}
}

function extractPlantUmlText(html, plantumlSectionRegex, note) {
var plantumlFiles = [];
var diagramsToGenerate = [];
Expand Down Expand Up @@ -199,7 +200,7 @@ QtObject {
var params = [
"-jar", plantumlJarPath,
"-o", script.toNativeDirSeparators(script.getPersistentVariable("renderPlantUML/workDir")),
"-t" + script.getPersistentVariable("renderPlantUML/svgOrPng"),
"-t" + svgOrPng,
additionalParams
].concat(plantumlFiles);
var result = script.startDetachedProcess(
Expand All @@ -215,7 +216,7 @@ QtObject {
function injectDiagrams(html, plantumlSectionRegex, plantumlFiles) {
var index = 0;
var updatedHtml = html.replace(plantumlSectionRegex, function(matchedStr, g1) {
var imgElement = "<div><img src=\"file:///" + plantumlFiles[index++] + "." + script.getPersistentVariable("renderPlantUML/svgOrPng") + "?t=" + +(new Date()) + "\" alt=\"Generated Diagram\"/></div>";
var imgElement = "<div><img src=\"file:///" + plantumlFiles[index++] + "." + svgOrPng + "?t=" + +(new Date()) + "\" alt=\"Generated Diagram\"/></div>";

if (hideMarkup == "true") {
return imgElement;
Expand All @@ -231,7 +232,7 @@ QtObject {
// and verify if it is the same
function isCached(filePath,newContent) {
var cached = "notCached";
if(script.fileExists(filePath) && script.fileExists(filePath + "." + script.getPersistentVariable("renderPlantUML/svgOrPng"))){
if(script.fileExists(filePath) && script.fileExists(filePath + "." + svgOrPng)){
var oldContent = script.readFromFile(filePath);
if (Qt.md5(oldContent) == Qt.md5(newContent))
cached = "cached";
Expand Down Expand Up @@ -276,7 +277,6 @@ QtObject {

var plantumlSectionRegex = /<pre><code class=\"language-plantuml\"\>([\s\S]*?)(<\/code>)?<\/pre>/gmi;
script.setPersistentVariable("renderPlantUML/workDir", workDir ? workDir: script.cacheDir("render-plantuml"));
script.setPersistentVariable("renderPlantUML/svgOrPng", svgOrPng ? "svg":"png");
script.setPersistentVariable("renderPlantUML/noteId", note.id);

var plantumlFiles = extractPlantUmlText(html, plantumlSectionRegex, note);
Expand Down

0 comments on commit 82ea53c

Please sign in to comment.