Skip to content

Commit 7ecde98

Browse files
committed
Use [\s\S] instead of the dot to match any character.
This allows to override the replacement function to preserve whitespace.
1 parent 7592dd2 commit 7ecde98

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ The template contents are matched and replaced using the regular expression **tm
227227
To use different tags for the template syntax, override **tmpl.regexp** with a modified regular expression, by exchanging all occurrences of "**\\{%**" and "**%\\}**", e.g. with "**\\[%**" and "**%\\]**":
228228

229229
```js
230-
tmpl.regexp = /(\s+)|('|\\)(?![^%]*%\])|(?:\[%(=|#)(.+?)%\])|(\[%)|(%\])/g;
230+
tmpl.regexp = /(\s+)|('|\\)(?![^%]*%\])|(?:\[%(=|#)([\s\S]+?)%\])|(\[%)|(%\])/g;
231231
```
232232

233233
## Templates syntax

tmpl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
tmpl.load = function (id) {
3535
return document.getElementById(id).innerHTML;
3636
};
37-
tmpl.regexp = /(\s+)|('|\\)(?![^%]*%\})|(?:\{%(=|#)(.+?)%\})|(\{%)|(%\})/g;
37+
tmpl.regexp = /(\s+)|('|\\)(?![^%]*%\})|(?:\{%(=|#)([\s\S]+?)%\})|(\{%)|(%\})/g;
3838
tmpl.func = function (s, p1, p2, p3, p4, p5, p6, o, str) {
3939
if (p1) { // whitespace
4040
return o && o + s.length !== str.length ? " " : "";

tmpl.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)