-
-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removes duplicate PlantUML/Mermaid encoders, adds support for Mermaid…
… compression, makes SVG the default formats.
- Loading branch information
1 parent
3d22317
commit f103a7a
Showing
13 changed files
with
92 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 0 additions & 18 deletions
18
structurizr-export/src/main/java/com/structurizr/export/mermaid/MermaidEncoder.java
This file was deleted.
Oops, something went wrong.
73 changes: 0 additions & 73 deletions
73
structurizr-export/src/main/java/com/structurizr/export/plantuml/PlantUMLEncoder.java
This file was deleted.
Oops, something went wrong.
32 changes: 31 additions & 1 deletion
32
...turizr-import/src/main/java/com/structurizr/importer/diagrams/mermaid/MermaidEncoder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,45 @@ | ||
package com.structurizr.importer.diagrams.mermaid; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Base64; | ||
import java.util.zip.Deflater; | ||
import java.util.zip.DeflaterOutputStream; | ||
|
||
/** | ||
* Encodes a Mermaid diagram definition to base64 format, for use with image URLs, etc. | ||
*/ | ||
public class MermaidEncoder { | ||
public final class MermaidEncoder { | ||
|
||
private static final String TEMPLATE = "{ \"code\":\"%s\", \"mermaid\":{\"theme\":\"default\"}}"; | ||
|
||
public String encode(String mermaidDefinition) { | ||
return this.encode(mermaidDefinition, false); | ||
} | ||
|
||
public String encode(String mermaidDefinition, boolean compress) { | ||
if (compress) { | ||
try { | ||
String content = String.format(TEMPLATE, mermaidDefinition.replaceAll("\n", "\\\\n").replaceAll("\"", "\\\\\"")); | ||
byte[] compressedDefinition = compress(content); | ||
return "pako:" + Base64.getUrlEncoder().encodeToString(compressedDefinition); | ||
} catch(Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
return Base64.getUrlEncoder().encodeToString(mermaidDefinition.getBytes(StandardCharsets.UTF_8)); | ||
} | ||
|
||
private byte[] compress(String content) throws Exception { | ||
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||
Deflater deflater = new Deflater(); | ||
|
||
DeflaterOutputStream dos = new DeflaterOutputStream(baos, deflater, true); | ||
dos.write(content.getBytes(StandardCharsets.UTF_8)); | ||
dos.finish(); | ||
|
||
return baos.toByteArray(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.