1 | var colors = require('colors');
|
2 | var less = require('less');
|
3 |
|
4 | /**
|
5 | * 解析 less
|
6 | *
|
7 | * @param {string} content 文本内容
|
8 | * @param {Object} attrs 属性
|
9 | * @param {string} attrs.data 数据项
|
10 | * @param {Object} scope 作用域
|
11 | * @param {Function} scope.getDirname 获取当前目录
|
12 | */
|
13 | module.exports = function processor(content, attrs, scope) {
|
14 | if (!content) {
|
15 | return content;
|
16 | }
|
17 | less.render(content, {
|
18 | paths: [scope.getDirname()],
|
19 | syncImport: true,
|
20 | relativeUrls: true
|
21 | }, function (error, output) {
|
22 | if (error) {
|
23 | console.error(colors.red(error));
|
24 | return content;
|
25 | }
|
26 | else {
|
27 | content = output.css;
|
28 | }
|
29 | });
|
30 | return content;
|
31 | }; |
\ | No newline at end of file |