Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle multiline strings #212

Merged
merged 2 commits into from
Nov 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading