From a7b6b36839d8a9a16b07fac700d6f8c10ad94b38 Mon Sep 17 00:00:00 2001 From: Felix van Oost Date: Sun, 13 Aug 2023 03:17:07 -0400 Subject: [PATCH] Add PlantUML no-metadata option (#1611) * Add 'no-metadata' argument * Add PlantUML no-metadata option to documentation * Add smoke test for PlantUML 'no-metadata' option fixes #1610 --- ci/tests/smoke.js | 1 + docs/modules/setup/pages/diagram-options.adoc | 6 +++++- .../main/java/io/kroki/server/service/PlantumlCommand.java | 6 +++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/ci/tests/smoke.js b/ci/tests/smoke.js index 6cfc47731..4ff16d41b 100755 --- a/ci/tests/smoke.js +++ b/ci/tests/smoke.js @@ -19,6 +19,7 @@ const tests = [ { engine: 'mermaid', file: 'contribute.mmd', options: {}, outputFormat: ['svg'] }, { engine: 'bpmn', file: 'example.bpmn', options: {}, outputFormat: ['svg'] }, { engine: 'plantuml', file: 'architecture.puml', options: {}, outputFormat: ['svg', 'pdf', 'png', 'txt'] }, + { engine: 'plantuml', file: 'architecture.puml', options: { 'no-metadata': 'true' }, outputFormat: ['svg', 'png'] }, { engine: 'svgbob', file: 'cloud.bob', options: {}, outputFormat: ['svg'] }, { engine: 'nomnoml', file: 'pirate.nomnoml', options: {}, outputFormat: ['svg'] }, { engine: 'packetdiag', file: 'packet.diag', options: {}, outputFormat: ['svg', 'png'] }, diff --git a/docs/modules/setup/pages/diagram-options.adoc b/docs/modules/setup/pages/diagram-options.adoc index 8375bb7b3..4f24b874c 100644 --- a/docs/modules/setup/pages/diagram-options.adoc +++ b/docs/modules/setup/pages/diagram-options.adoc @@ -182,6 +182,10 @@ The complete list of options is available in Mermaid source code at: https://git |Use a specific theme (it will prepend the `!theme` directive in your diagram) +|no-metadata +|_flag_ + +empty string ("") +|Do not save the diagram's source code in the generated SVG/PNG metadata |=== == Structurizr @@ -233,7 +237,7 @@ The complete list of options is available in Mermaid source code at: https://git |stroke-width |_any_ + -*`2`* +*`2`* |Stroke width for all lines |=== diff --git a/server/src/main/java/io/kroki/server/service/PlantumlCommand.java b/server/src/main/java/io/kroki/server/service/PlantumlCommand.java index 416d806a0..b326fb2e1 100644 --- a/server/src/main/java/io/kroki/server/service/PlantumlCommand.java +++ b/server/src/main/java/io/kroki/server/service/PlantumlCommand.java @@ -69,16 +69,20 @@ public byte[] handle(int exitValue, byte[] stdout, byte[] stderr) { public byte[] convert(String source, FileFormat format, JsonObject options) throws IOException, InterruptedException { List commands = new ArrayList<>(); - String theme = options.getString("theme"); commands.add(binPath); commands.add("-pipe"); commands.add("-t" + (format == FileFormat.BASE64 ? FileFormat.PNG.getName() : format.getName())); commands.add("-timeout"); commands.add(String.valueOf(this.convertTimeout.timeUnit().toSeconds(this.convertTimeout.duration()))); + String theme = options.getString("theme"); if (theme != null && !theme.isBlank()) { commands.add("-theme"); commands.add(theme); } + String no_metadata = options.getString("no-metadata"); + if (no_metadata != null) { + commands.add("-nometadata"); + } byte[] result = commander.execute(source.getBytes(), commands.toArray(new String[0])); if (format == FileFormat.BASE64) { final String encodedBytes = "data:image/png;base64," + Base64.getUrlEncoder().encodeToString(result).replaceAll("\\s", "");