From 2a95bbf88dc38c98f9933ae9224bdcc16a364854 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Wed, 14 Feb 2018 10:01:16 +0100 Subject: [PATCH] prop maths: espace multiline strings --- resources/docs/extras/property-maths.md | 1 + src/browser/js/app/widgets/common/widget.js | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/resources/docs/extras/property-maths.md b/resources/docs/extras/property-maths.md index e4cecae2..c47561d6 100644 --- a/resources/docs/extras/property-maths.md +++ b/resources/docs/extras/property-maths.md @@ -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: diff --git a/src/browser/js/app/widgets/common/widget.js b/src/browser/js/app/widgets/common/widget.js index bf4c5e4f..aaffc897 100644 --- a/src/browser/js/app/widgets/common/widget.js +++ b/src/browser/js/app/widgets/common/widget.js @@ -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)