Skip to content

Commit 2105930

Browse files
committed
fix #746 issue with newline characters in text in IE
1 parent 61ade94 commit 2105930

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

src/lib/svg_text_utils.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ var UNICODE_TO_ENTITY = Object.keys(stringMappings.unicodeToEntity).map(function
250250
};
251251
});
252252

253+
var NEWLINES = /(\r\n?|\n)/g;
254+
253255
exports.plainText = function(_str) {
254256
// strip out our pseudo-html so we have a readable
255257
// version to put into text fields
@@ -278,6 +280,13 @@ function encodeForHTML(_str) {
278280
function convertToSVG(_str) {
279281
_str = convertEntities(_str);
280282

283+
// normalize behavior between IE and others wrt newlines and whitespace:pre
284+
// this combination makes IE barf https://github.com/plotly/plotly.js/issues/746
285+
// Chrome and FF display \n, \r, or \r\n as a space in this mode.
286+
// I feel like at some point we turned these into <br> but currently we don't so
287+
// I'm just going to cement what we do now in Chrome and FF
288+
_str = _str.replace(NEWLINES, ' ');
289+
281290
var result = _str
282291
.split(/(<[^<>]*>)/).map(function(d) {
283292
var match = d.match(/<(\/?)([^ >]*)\s*(.*)>/i),

test/image/mocks/annotations.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
{"text":"left<br>justified","showarrow":false,"align":"left","x":1,"y":4},
2222
{"text":"center<br>justified","showarrow":false,"x":2,"y":4},
2323
{"text":"right<br>justified","showarrow":false,"align":"right","x":3,"y":4},
24-
{"text":"no arrow<br>page auto TR","showarrow":false,"xref":"paper","yref":"paper","x":0.75,"y":0.75},
24+
{"text":"no\narrow<br>page\rauto\r\nTR","showarrow":false,"xref":"paper","yref":"paper","x":0.75,"y":0.75},
2525
{"text":"no arrow<br>page auto ML","showarrow":false,"xref":"paper","yref":"paper","x":0.25,"y":0.5},
2626
{"text":"no arrow<br>page auto BC","showarrow":false,"xref":"paper","yref":"paper","x":0.5,"y":0.25},
2727
{"text":"default"},

test/image/mocks/axes_enumerated_ticks.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
"width": 400,
3333
"xaxis": {
3434
"ticktext": [
35-
"<span style=\"fill:green\">green</span> eggs",
36-
"&amp; ham",
35+
"<span style=\"fill:green\">green</span>\neggs",
36+
"&amp;\r\nham",
3737
"H<sub>2</sub>O",
3838
"Gorgonzola"
3939
],

test/image/mocks/text_chart_arrays.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
1
1313
],
1414
"mode": "lines+markers+text",
15-
"name": "Lines, Markers and Text",
15+
"name": "Lines,\nMarkers\rand\r\nText",
1616
"text": [
17-
"Text A",
18-
"Text B",
19-
"Text C"
17+
"Text\nA",
18+
"Text\rB",
19+
"Text\r\nC"
2020
],
2121
"textfont": {
2222
"family": [

0 commit comments

Comments
 (0)