prop maths: espace multiline strings

This commit is contained in:
jean-emmanuel 2018-02-14 10:01:16 +01:00
parent ff95da7ba6
commit 2a95bbf88d
2 changed files with 8 additions and 0 deletions

View file

@ -13,6 +13,7 @@ Where FORMULA is a valid [MathJS](http://mathjs.org/docs/expressions/syntax.html
- [available constants](http://mathjs.org/docs/reference/constants.html)
- property inheritance calls (`@{...}`) are always resolved before formulas
- arrays / matrices indexes are **zero-based** (ie `['a','b'][0]` returns `'a'`)
- strings can be multiline when enclosed in backticks instead of double quotes (``` ` ` ```)
Additionnal functions:

View file

@ -289,8 +289,15 @@ class Widget extends EventEmitter {
try {
propValue = propValue.replace(/#\{(?:[^\}\\]|\\.)+\}/g, (m)=>{
// unescape brackets
m = m.replace(/\\(\{|\})/g, '$1')
// espace multiline strings
m = m.replace(/`([^`]*)`/g, (m)=>{
return m.replace(/"/g,'\\"').replace(/\n/g,'\\n').replace(/`/g,'"')
})
if (!this.parsers[m]) this.parsers[m] = math.compile(m.substr(2, m.length - 3).trim())
let r = this.parsers[m].eval(variables)