Skip to content

Commit 52c77ee

Browse files
authored
Handle multiline strings (#212)
* fixing how multiline strings are handled * just justify multiline strings
1 parent b3cefa3 commit 52c77ee

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

mathics_django/web/media/js/mathics.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function isEmpty(textarea) {
5656
}
5757

5858
function prepareText(text) {
59-
return text || String.fromCharCode(160); // non breaking space, like  
59+
return text.replaceAll(" ", " ");
6060
}
6161

6262
function getDimensions(math, callback) {
@@ -97,7 +97,6 @@ function translateDOMElement(element, svg) {
9797
if (element.nodeType === 3) {
9898
return document.createTextNode(element.nodeValue);
9999
}
100-
101100
const nodeName = element.nodeName;
102101

103102
let dom = null;
@@ -261,7 +260,6 @@ function translateDOMElement(element, svg) {
261260
function createLine(value) {
262261
const container = document.createElement('div');
263262
container.innerHTML = value;
264-
265263
if (container?.firstElementChild?.tagName === 'math') {
266264
return translateDOMElement(container.firstChild);
267265
} else if (container?.firstElementChild?.tagName === 'GRAPHICS3D') {
@@ -287,18 +285,20 @@ function createLine(value) {
287285
return container;
288286
} else {
289287
const lines = container.innerText.split('\n');
290-
291288
const p = document.createElement('p');
292289
p.className = 'string';
290+
if(lines.length>1){
291+
p.style.textAlign = 'justify';
292+
}
293293

294294
for (let i = 0; i < lines.length; i++) {
295-
p.innerText += prepareText(lines[i]);
295+
newline = prepareText(lines[i]);
296+
p.innerHTML += newline;
296297

297298
if (i < lines.length - 1) {
298299
p.appendChild(document.createElement('br'));
299300
}
300301
}
301-
302302
return p;
303303
}
304304
}
@@ -477,7 +477,7 @@ function setResult(list, results) {
477477
li.innerText += out.prefix + ': ';
478478
}
479479

480-
li.appendChild(createLine(out.text));
480+
li.appendChild(createLine(out.text.slice(1,-1)));
481481

482482
resultList.appendChild(li);
483483
});

0 commit comments

Comments
 (0)