mirror of
https://github.com/heyman/heynote.git
synced 2024-11-25 01:13:17 +01:00
Add support for specifying a custom format function within a math block (#99)
This commit is contained in:
parent
b0f3bdd19e
commit
0b6a1a49e8
@ -67,10 +67,19 @@ function mathDeco(view) {
|
|||||||
|
|
||||||
// if we got a result from math.js, add the result decoration
|
// if we got a result from math.js, add the result decoration
|
||||||
if (result !== undefined) {
|
if (result !== undefined) {
|
||||||
|
let format = parser.get("format")
|
||||||
|
|
||||||
let resultWidget
|
let resultWidget
|
||||||
if (typeof(result) === "string") {
|
if (typeof(result) === "string") {
|
||||||
resultWidget = new MathResult(result, result)
|
resultWidget = new MathResult(result, result)
|
||||||
} else {
|
} else if (format !== undefined && typeof(format) === "function") {
|
||||||
|
try {
|
||||||
|
resultWidget = new MathResult(format(result), format(result))
|
||||||
|
} catch (e) {
|
||||||
|
// suppress any errors
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (resultWidget === undefined) {
|
||||||
resultWidget = new MathResult(
|
resultWidget = new MathResult(
|
||||||
math.format(result, {
|
math.format(result, {
|
||||||
precision: 8,
|
precision: 8,
|
||||||
|
@ -24,3 +24,13 @@ format(1/3, 3)
|
|||||||
`)
|
`)
|
||||||
await expect(page.locator("css=.heynote-math-result")).toHaveText("0.333")
|
await expect(page.locator("css=.heynote-math-result")).toHaveText("0.333")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test("custom format function", async ({ page }) => {
|
||||||
|
await heynotePage.setContent(`
|
||||||
|
∞∞∞math
|
||||||
|
_format = format
|
||||||
|
format(x) = _format(x, {notation:"exponential"})
|
||||||
|
42
|
||||||
|
`)
|
||||||
|
await expect(page.locator("css=.heynote-math-result").last()).toHaveText("4.2e+1")
|
||||||
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user