UNPKG

899 BJavaScriptView Raw
1var jsdev = require('JSDev');
2
3/**
4 * JSDev 编码
5 *
6 * @see https://github.com/douglascrockford/JSDev
7 * @param {string} content 文本内容
8 * @param {Object} attrs 属性
9 * @param {string} attrs.data 数据项
10 * @param {Object} scope 作用域
11 * @param {Function} scope.execImport 导入数据
12 */
13module.exports = function processor(content, attrs, scope) {
14 if (!content) {
15 return content;
16 }
17 var tags;
18 if (attrs.tags) {
19 /*jslint evil: true */
20 tags = scope.execImport(attrs.tags);
21 if (/^\[[^]*\]$/.test(tags)) { // array
22 tags = new Function(
23 'return (' +
24 tags +
25 ');'
26 )();
27 } else {
28 tags = tags.split(/\s*[,\n]\s*/);
29 }
30 } else {
31 tags = [];
32 }
33
34 var comments;
35 if (attrs.comments) {
36 comments = scope.execImport(attrs.comments);
37 } else {
38 comments = null;
39 }
40 return jsdev(content, tags, comments);
41};