1 | var colors = require('colors');
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | module.exports = function processor(content, attrs, scope) {
|
15 | var pattern = scope.execImport(attrs.pattern);
|
16 | var replacement = scope.execImport(attrs.replacement);
|
17 | var regex;
|
18 | if (/^\s*\/.*\/([img]{0,3})\s*$/.test(pattern) ||
|
19 | /^(['"]).*\1$/.test(pattern)) {
|
20 | try {
|
21 |
|
22 | regex = new Function('return (' + pattern + ')')();
|
23 | }
|
24 | catch (ex) {
|
25 | console.error(colors.red(ex.message));
|
26 | return content;
|
27 | }
|
28 | }
|
29 | else {
|
30 | regex = pattern;
|
31 | }
|
32 | if (!regex) {
|
33 | return content;
|
34 | }
|
35 | return scope.compile(content.replace(regex, replacement || ''));
|
36 | }; |
\ | No newline at end of file |