Skip to content

Commit

Permalink
cherry pick commit from upstream
Browse files Browse the repository at this point in the history
Original commit message:
Fixed issue jaime-olivares/yuml-diagram#18
  • Loading branch information
jaime-olivares authored and aduh95 committed Apr 27, 2019
1 parent 4904294 commit ef3c14d
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/svg-builder.js
Expand Up @@ -45,6 +45,7 @@ module.exports = function(isDark) {
const text = document.createElementNS(NS, "text");
text.textContent = lineText;
text.setAttribute("fill", color || isDark ? WHITE : BLACK);
text.setAttribute("font-family", "Helvetica,sans-Serif");

text.setAttribute("x", x);
text.setAttribute("y", y);
Expand Down
9 changes: 8 additions & 1 deletion src/yuml2dot-utils.js
Expand Up @@ -19,6 +19,13 @@ const escape_label = function(label) {
return newLabel;
};

const unescape_label = label =>
label
.replace(/\\\{/g, "{")
.replace(/\\\}/g, "}")
.replace(/\\</g, "<")
.replace(/\\>/g, ">");

const splitYumlExpr = function*(line, separators, escape = "\\") {
const SEPARATOR_END = {
"[": "]",
Expand Down Expand Up @@ -146,7 +153,7 @@ const serializeDot = function(node) {
text = text.substr(closingTagPosition + 1);
}
htmlTDNode += ">";
for (const char of text) {
for (const char of unescape_label(text)) {
htmlTDNode += ESCAPED_CHARS[char] || char;
}
htmlTDNode += "</TD>";
Expand Down
19 changes: 18 additions & 1 deletion test/index.js
@@ -1 +1,18 @@
// TODO : Unit tests
const yuml2svg = require("..");
const { promises: fs } = require("fs");

const inputFile = require.resolve("./test.yuml");
const outputFile = require.resolve("./test.yuml.svg");

Promise.all([fs.readFile(inputFile).then(yuml2svg), fs.readFile(outputFile)])
.then(([actual, expectedOutput]) => {
const actualOutput = Buffer.from(actual);
if (Buffer.compare(actualOutput, expectedOutput) === 0) {
return Promise.resolve("Success");
} else {
console.warn("Output has been modified");

return fs.writeFile(outputFile, actualOutput);
}
})
.then(console.log, console.error);
5 changes: 5 additions & 0 deletions test/test.yuml
@@ -0,0 +1,5 @@
// {type:class}
// {direction:topDown}
[a]->[<<b>>|c]
[e]->[<<b>>]
[f]->[c]
63 changes: 63 additions & 0 deletions test/test.yuml.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ef3c14d

Please sign in to comment.