Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [FUTURE]

### Added

- Logging for Environment and workspace

### Fixed

- User-defined graphics library [#182](https://github.com/hediet/vscode-drawio/issues/182)

## [1.9.0]

### Fixed
Expand Down
12 changes: 12 additions & 0 deletions examples/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@
"file": "${workspaceFolder}/tooltips-plugin.js"
}
],
"hediet.vscode-drawio.customLibraries": [
{
"file": "${workspaceFolder}/library/scratchpad.xml",
"libName": "xml_lib",
"entryId": "xml_lib"
},
{
"file": "${workspaceFolder}/library/scratchpad.json",
"libName": "json_lib",
"entryId": "json_lib"
}
],
"hediet.vscode-drawio.defaultVertexStyle": {
"fontColor": "#ff0000",
"fontFamily": "Courier New",
Expand Down
14 changes: 14 additions & 0 deletions examples/library/scratchpad.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"xml": "<mxGraphModel><root><mxCell id=\"0\"\/><mxCell id=\"1\" parent=\"0\"\/><mxCell id=\"2\" value=\"JSON lib 1\" style=\"whiteSpace=wrap;html=1;\" vertex=\"1\" parent=\"1\"><mxGeometry width=\"120\" height=\"60\" as=\"geometry\"\/><\/mxCell><\/root><\/mxGraphModel>",
"w": 120,
"h": 60,
"aspect": "fixed"
},
{
"xml": "<mxGraphModel><root><mxCell id=\"0\"\/><mxCell id=\"1\" parent=\"0\"\/><mxCell id=\"2\" value=\"JSON lib 2\" style=\"whiteSpace=wrap;html=1;\" vertex=\"1\" parent=\"1\"><mxGeometry width=\"120\" height=\"60\" as=\"geometry\"\/><\/mxCell><\/root><\/mxGraphModel>",
"w": 120,
"h": 60,
"aspect": "fixed"
}
]
14 changes: 14 additions & 0 deletions examples/library/scratchpad.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<mxlibrary>[
{
"xml": "&lt;mxGraphModel&gt;&lt;root&gt;&lt;mxCell id=\"0\"/&gt;&lt;mxCell id=\"1\" parent=\"0\"/&gt;&lt;mxCell id=\"2\" value=\"Exported Format\" style=\"whiteSpace=wrap;html=1;\" vertex=\"1\" parent=\"1\"&gt;&lt;mxGeometry width=\"120\" height=\"60\" as=\"geometry\"/&gt;&lt;/mxCell&gt;&lt;/root&gt;&lt;/mxGraphModel&gt;",
"w": 120,
"h": 60,
"aspect": "fixed"
},
{
"xml": "jVBLDsIgED0Ne4TEA0htV648AZFJIQEhMNr29mIZbVw0cUHy5n3Im2FShXnIOtlLNOCZPDOpcozYUJgVeM8Ed4bJjgnB62Oi31EPq8qTznDHfwKiBZ7aP6AxKoaUoRQwle9jDhqbp+DiyTNZh3BN+vaep1qeyZPFUNt3hwrpT8gI826vlaJSA8QAmJdqmZxBSw7qzi240VLsSJwubR6/0W3LCmjRz7gddNV+7v0C",
"w": 120,
"h": 60,
"aspect": "fixed"
}
]</mxlibrary>
24 changes: 23 additions & 1 deletion src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,29 @@ export class DiagramConfig {
function parseXml(xml: string): unknown {
const parse = require("xml-parser-xo");
const parsedXml = parse(xml);
return JSON.parse(parsedXml.root.children[0].content);
const unescapeHtml = (str: string): string => {
const htmlEntities: { [key: string]: string } = {
"&amp;": "&",
"&lt;": "<",
"&gt;": ">",
"&quot;": '"',
"&#39;": "'",
};
return str.replace(/&amp;|&lt;|&gt;|&quot;|&#39;/g, (match) => htmlEntities[match]);
};
const parsedJson = JSON.parse(
parsedXml.root.children[0].content
);
for (let index = 0; index < parsedJson.length; index++) {
const element = parsedJson[index];
if (element.xml.startsWith("&lt;")) {
// This is the default export format
let xmlContent = element.xml;
xmlContent = unescapeHtml(xmlContent);
element.xml = xmlContent;
}
}
return parsedJson;
}

let data: DrawioLibraryData["data"];
Expand Down
15 changes: 15 additions & 0 deletions src/DrawioClient/DrawioClientFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class DrawioClientFactory {
webviewPanel: WebviewPanel,
options: DrawioClientOptions
): Promise<CustomizedDrawioClient> {
this.logEnvironment();
const config = this.config.getDiagramConfig(uri);
const plugins = await this.getPlugins(config);

Expand Down Expand Up @@ -292,6 +293,20 @@ export class DrawioClientFactory {
</html>
`;
}

private logEnvironment(): void {
const isWsl =
process.platform === "linux" && process.env.WSL_DISTRO_NAME;
const isWindows = process.platform === "win32";
const wslDistro = process.env.WSL_DISTRO_NAME || "Unknown";
this.log.appendLine(
`[Drawio] Environment: WSL=${isWsl}, Windows=${isWindows}, WSL_DISTRO_NAME=${wslDistro}`
);

const workspaceRootUri = workspace.workspaceFolders?.[0]?.uri;
const workspaceRoot = workspaceRootUri ? workspaceRootUri.fsPath : ".";
this.log.appendLine(`[Drawio] Workspace root: ${workspaceRoot}`);
}
}

export interface DrawioClientOptions {
Expand Down
Loading