prop maths: espace multiline strings
This commit is contained in:
parent
4cfa779d5d
commit
d5dad476f6
2 changed files with 8 additions and 0 deletions
|
|
@ -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:
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue