Skip to content

Commit edf560a

Browse files
authored
SW-554 add-microsoft-visio-to-the-get-generator-info (mrbeam#1412)
1 parent 4e0a93d commit edf560a

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

octoprint_mrbeam/static/js/helpers/working_area_helper.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,34 @@ class WorkingAreaHelper {
211211
}
212212
}
213213

214+
// detect Microsoft Visio generated svg
215+
// <svg ... xmlns:v="http://schemas.microsoft.com/visio/2003/SVGExtensions/" ...>
216+
if (
217+
root_attrs["xmlns:v"] &&
218+
root_attrs["xmlns:v"].value.search("microsoft.com/visio") > 0
219+
) {
220+
let version = "unknown";
221+
const ns = root_attrs["xmlns:v"].value;
222+
const regex = /microsoft\.com\/visio\/(.+)\/SVGExtensions/gm;
223+
let m;
224+
225+
while ((m = regex.exec(ns)) !== null) {
226+
// This is necessary to avoid infinite loops with zero-width matches
227+
if (m.index === regex.lastIndex) {
228+
regex.lastIndex++;
229+
}
230+
231+
// The result can be accessed through the `m`-variable.
232+
m.forEach((match, groupIndex) => {
233+
console.log(
234+
`Found match, group ${groupIndex}: ${match}`
235+
);
236+
version = match;
237+
});
238+
}
239+
return { generator: "Microsoft Visio", version: version };
240+
}
241+
214242
// detect dxf.js generated svg
215243
// <!-- Created with dxf.js -->
216244
for (var i = 0; i < children.length; i++) {

0 commit comments

Comments
 (0)