Re-enable math
This commit is contained in:
parent
3f922fffd2
commit
2a5d3f2498
|
@ -21,13 +21,13 @@ import moment from 'moment'
|
||||||
// import 'prismjs/components/prism-jq'
|
// import 'prismjs/components/prism-jq'
|
||||||
import MD from './markdown'
|
import MD from './markdown'
|
||||||
import he from 'he'
|
import he from 'he'
|
||||||
// import {all, create} from 'mathjs'
|
import {all, create} from 'mathjs'
|
||||||
// import formulaFunctions from './formula'
|
import formulaFunctions from './formula'
|
||||||
|
|
||||||
moment.locale('nl')
|
moment.locale('nl')
|
||||||
|
|
||||||
// const math = create(all)
|
const math = create(all)
|
||||||
// math.import(formulaFunctions)
|
math.import(formulaFunctions)
|
||||||
|
|
||||||
function isMultiline(input) {
|
function isMultiline(input) {
|
||||||
return input.value.startsWith("```", 0)
|
return input.value.startsWith("```", 0)
|
||||||
|
@ -90,7 +90,7 @@ function addIndicator(editor, indicator) {
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
.catch(reason => {
|
.catch(reason => {
|
||||||
console.warn('error while saving: '+ reason)
|
console.warn('error while saving: ' + reason)
|
||||||
indicator.addError('error!')
|
indicator.addError('error!')
|
||||||
indicator.done();
|
indicator.done();
|
||||||
})
|
})
|
||||||
|
@ -181,13 +181,14 @@ function Editor(holder, input) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function transformTable(editor, id, element) {
|
function transformTable(editor, id, element) {
|
||||||
|
Promise.any()
|
||||||
|
|
||||||
editor.treeForId(id).then(tree => {
|
editor.treeForId(id).then(tree => {
|
||||||
let header = _.find(tree[0].children, c => c.text === 'headers') || []
|
let header = _.find(tree[0].children, c => c.text === 'headers') || []
|
||||||
let rows = _.find(tree[0].children, c => c.text === 'rows') || []
|
let rows = _.find(tree[0].children, c => c.text === 'rows') || []
|
||||||
|
|
||||||
let rowData = _.map(rows.children, row => {
|
let rowData = _.map(rows.children, row => {
|
||||||
// FIXME: Use real parse link function
|
// FIXME: Use a real parse link function
|
||||||
let page = row.text.substring(2).substring(0, row.text.length - 4)
|
let page = row.text.substring(2).substring(0, row.text.length - 4)
|
||||||
return fetch('/' + page + '?format=metakv')
|
return fetch('/' + page + '?format=metakv')
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
|
@ -230,6 +231,23 @@ function Editor(holder, input) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function transformMathExpression(converted, scope) {
|
||||||
|
try {
|
||||||
|
let expr = converted.substring(1);
|
||||||
|
let parsedExpr = math.parse(expr)
|
||||||
|
let compiled = parsedExpr.compile()
|
||||||
|
let evaluated = compiled.evaluate(scope);
|
||||||
|
if (parsedExpr.isAssignmentNode) {
|
||||||
|
converted = parsedExpr.object.name + " = <i>" + evaluated.toString() + "</i>"
|
||||||
|
} else {
|
||||||
|
converted = expr + " = <i>" + evaluated.toString() + "</i>"
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
converted = converted + ' <span style="background: red; color: white;">' + e.message + '</span>';
|
||||||
|
}
|
||||||
|
return converted;
|
||||||
|
}
|
||||||
|
|
||||||
function transform(text, element, id, editor, scope) {
|
function transform(text, element, id, editor, scope) {
|
||||||
if (text === undefined) {
|
if (text === undefined) {
|
||||||
return;
|
return;
|
||||||
|
@ -248,11 +266,7 @@ function Editor(holder, input) {
|
||||||
} else if (converted.startsWith("```", 0) || converted.startsWith("$$", 0)) {
|
} else if (converted.startsWith("```", 0) || converted.startsWith("$$", 0)) {
|
||||||
converted = MD.render(converted)
|
converted = MD.render(converted)
|
||||||
} else if (converted.startsWith("=", 0)) {
|
} else if (converted.startsWith("=", 0)) {
|
||||||
// try {
|
converted = transformMathExpression(converted, scope);
|
||||||
// converted = math.evaluate(converted.substring(1), scope).toString()
|
|
||||||
// } catch (e) {
|
|
||||||
// converted = converted + ' <span style="background: red; color: white;">' + e.message + '</span>';
|
|
||||||
// }
|
|
||||||
} else {
|
} else {
|
||||||
let re = /^([A-Z0-9 ]+)::\s*(.+)$/i;
|
let re = /^([A-Z0-9 ]+)::\s*(.+)$/i;
|
||||||
let res = text.match(re)
|
let res = text.match(re)
|
||||||
|
@ -274,6 +288,7 @@ function Editor(holder, input) {
|
||||||
element.toggleClass('todo--done', todo === false)
|
element.toggleClass('todo--done', todo === false)
|
||||||
element.toggleClass('todo--todo', todo === true)
|
element.toggleClass('todo--todo', todo === true)
|
||||||
}
|
}
|
||||||
|
|
||||||
element.html(converted)
|
element.html(converted)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -535,9 +550,10 @@ function Editor(holder, input) {
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
editor.replaceChildren(id, results)
|
editor.replaceChildren(id, results)
|
||||||
}).then(function () {
|
})
|
||||||
editor.render()
|
.then(function () {
|
||||||
})
|
editor.render()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user