Remove from non-embedded SVGs
Change-Id: I7e7e6cd866ee86b28d04c3dfcee3d6dca3e1b262
diff --git a/dev/js/spec/matchSpec.js b/dev/js/spec/matchSpec.js
index 9b3ef9e..d10aced 100644
--- a/dev/js/spec/matchSpec.js
+++ b/dev/js/spec/matchSpec.js
@@ -8,6 +8,7 @@
'match/infolayer',
'match/treeitem',
'match/treearc',
+ 'match/treehierarchy',
'buttongroup/menu',
'match/attachement',
'hint/foundries/cnx',
@@ -20,6 +21,7 @@
infoClass,
matchTreeItemClass,
matchRelClass,
+ matchHierClass,
matchTreeMenuClass,
attachementClass) {
@@ -200,8 +202,10 @@
"</span>" +
"<span class=\"context-right\"></span>";
+ var treeSnippetHierarchy =
+ "<span class=\"context-left\"><\/span><span class=\"match\"><span title=\"corenlp\/c:MPN\">Leonard Maltin<\/span> schrieb: „<span title=\"corenlp\/c:S\"><span title=\"corenlp\/c:NP\">Plot <span title=\"corenlp\/c:MPN\">contrivance isn‘<mark>t<\/mark> handled badly<\/span><\/span> <span title=\"corenlp\/c:PP\">in above-average programmer<\/span><\/span>“.<<span title=\"corenlp\/c:S\"><span title=\"corenlp\/c:ROOT\"><span title=\"corenlp\/c:NP\">ref>''<span title=\"corenlp\/c:NP\"><span title=\"corenlp\/c:CNP\">Movie &amp; Video<\/span> Guide<\/span><\/span>'', <span title=\"corenlp\/c:VP\">1996 edition, <span title=\"corenlp\/c:NP\"><span title=\"corenlp\/c:CNP\">S. 210<\/span><\/span><\/span>.<\/span><\/span><\/span><span class=\"context-right\"><\/span>";
- function matchElementFactory () {
+ function matchElementFactory () {
var me = document.createElement('li');
me.setAttribute(
@@ -641,6 +645,17 @@
expect(tree.children[1].tagName).toEqual('DIV');
});
+ it('should make the tree downloadable', function () {
+ var treeClass = matchHierClass.create(treeSnippetHierarchy);
+ var treeElement = treeClass.element();
+ expect(treeElement.tagName).toEqual("svg");
+
+ var base64 = treeClass.toBase64();
+ var str = atob(base64);
+ expect(str).toMatch(new RegExp('<defs><style>path'));
+ expect(str).not.toMatch(new RegExp(' '));
+ expect(str).toMatch(new RegExp('&'));
+ });
});
diff --git a/dev/js/src/match/treehierarchy.js b/dev/js/src/match/treehierarchy.js
index 08ebeef..e9c6122 100644
--- a/dev/js/src/match/treehierarchy.js
+++ b/dev/js/src/match/treehierarchy.js
@@ -214,8 +214,8 @@
'g.leaf > rect ' + '{ display: none }' +
'g > text > tspan ' + '{ text-anchor: middle; font-size: 9pt }' +
'g.leaf > text > tspan ' + '{ font-size: 10pt; overflow: visible; }';
-
- return btoa(unescape(encodeURIComponent(svg.outerHTML)));
+
+ return btoa(unescape(encodeURIComponent(svg.outerHTML)).replace(/ /g, ' '));
},
/**
@@ -279,11 +279,16 @@
'transform',
'translate(' + v.width/2 + ',' + ((v.height / 2) + 5) + ')'
);
+
+ var vLabel = v.label.replace(/ /g, " ")
+ .replace(/&/g, '&')
+ .replace(/</g, '<')
+ .replace(/>/g, '>');
if (v.class === "leaf") {
- text.setAttribute('title', v.label);
+ text.setAttribute('title', vLabel);
- var labelPart = v.label.split(" ");
+ var labelPart = vLabel.split(" ");
var n = 0;
for (var i = 0; i < labelPart.length; i++) {
if (labelPart[i].length === 0)
@@ -308,7 +313,7 @@
}
else {
var tspan = that._c('tspan');
- tspan.appendChild(d.createTextNode(v.label));
+ tspan.appendChild(d.createTextNode(vLabel));
tspan.setAttribute('x', v.x - v.width / 2);
text.appendChild(tspan);
};