Skip to content

Commit

Permalink
Handle multiline strings (#212)
Browse files Browse the repository at this point in the history
* fixing how multiline strings are handled

* just justify multiline strings
  • Loading branch information
mmatera authored Nov 6, 2024
1 parent b3cefa3 commit 52c77ee
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions mathics_django/web/media/js/mathics.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function isEmpty(textarea) {
}

function prepareText(text) {
return text || String.fromCharCode(160); // non breaking space, like  
return text.replaceAll(" ", " ");
}

function getDimensions(math, callback) {
Expand Down Expand Up @@ -97,7 +97,6 @@ function translateDOMElement(element, svg) {
if (element.nodeType === 3) {
return document.createTextNode(element.nodeValue);
}

const nodeName = element.nodeName;

let dom = null;
Expand Down Expand Up @@ -261,7 +260,6 @@ function translateDOMElement(element, svg) {
function createLine(value) {
const container = document.createElement('div');
container.innerHTML = value;

if (container?.firstElementChild?.tagName === 'math') {
return translateDOMElement(container.firstChild);
} else if (container?.firstElementChild?.tagName === 'GRAPHICS3D') {
Expand All @@ -287,18 +285,20 @@ function createLine(value) {
return container;
} else {
const lines = container.innerText.split('\n');

const p = document.createElement('p');
p.className = 'string';
if(lines.length>1){
p.style.textAlign = 'justify';
}

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

if (i < lines.length - 1) {
p.appendChild(document.createElement('br'));
}
}

return p;
}
}
Expand Down Expand Up @@ -477,7 +477,7 @@ function setResult(list, results) {
li.innerText += out.prefix + ': ';
}

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

resultList.appendChild(li);
});
Expand Down

0 comments on commit 52c77ee

Please sign in to comment.