Skip to content

Commit ac2c2d9

Browse files
committed
Bugfix: Newlines in node labels and description are now rendered correctly.
1 parent 4e33780 commit ac2c2d9

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/model/Node.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ export class Node {
3838
public toJsString(): string {
3939
const jsStringProperties: string[] = [];
4040
if (this.id !== undefined) { jsStringProperties.push(`id: "${this.id}"`); }
41-
if (this.label !== undefined) { jsStringProperties.push(`label: "${this.label}"`); }
42-
if (this.description !== undefined) { jsStringProperties.push(`title: "${this.description}"`); }
41+
const label = this.convertNewlines(this.label);
42+
if (this.label !== undefined) { jsStringProperties.push(`label: "${label}"`); }
43+
const description = this.convertNewlines(this.description);
44+
if (this.description !== undefined) { jsStringProperties.push(`title: "${description}"`); }
4345
if (this.strokeThickness !== undefined) { jsStringProperties.push(`borderWidth: "${this.strokeThickness}"`); }
4446
const jsStringColorProperties: string[] = [];
4547
if (this.stroke !== undefined) { jsStringColorProperties.push(`border: "${this.stroke}"`); }
@@ -49,4 +51,14 @@ export class Node {
4951
if (jsStringColorProperties.length > 0) { jsStringProperties.push(`color: { ${jsStringColorProperties.join(', ')} }`); }
5052
return `{${jsStringProperties.join(', ')}}`;
5153
}
54+
55+
private convertNewlines(text: string | undefined): string {
56+
if(text === undefined) {
57+
return '';
58+
}
59+
text = text.replace('
', '\\n');
60+
text = text.replace('
', '\\n');
61+
text = text.replace('
', '\\n');
62+
return text;
63+
}
5264
}

0 commit comments

Comments
 (0)