1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | exports.parseCodeText = function (code) {
|
12 | var m = code.trim().match(/^@([^\n]+)/);
|
13 |
|
14 | if (m) return { tag: m[1], code: code.substr(m[1].length+2) };
|
15 | return { tag: null, code: code };
|
16 | };
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | exports.parseTags = function (str) {
|
23 | if (typeof str !== 'string') return {};
|
24 |
|
25 | var m;
|
26 | var obj = {};
|
27 | str = str.trim();
|
28 |
|
29 | while (true) {
|
30 | if (m = str.match(/^\.([a-z\-]+)\s*/)) {
|
31 | if (!obj["class"]) obj["class"] = [];
|
32 | obj["class"].push(m[1]);
|
33 | } else if (m = str.match(/^([a-z\-]+)="([^"]+)"\s*/)) {
|
34 | obj[m[1]] = m[2];
|
35 | } else if (m = str.match(/^([a-z\-]+)='([^']+)'\s*/)) {
|
36 | obj[m[1]] = m[2];
|
37 | } else if (m = str.match(/^([a-z\-]+)=([^\s]+)\s*/)) {
|
38 | obj[m[1]] = m[2];
|
39 | } else if (m = str.match(/^([a-z\-]+)\s*/)) {
|
40 | obj[m[1]] = true;
|
41 | } else {
|
42 | if (obj["class"]) obj["class"] = obj["class"].join(' ');
|
43 | return obj;
|
44 | }
|
45 |
|
46 |
|
47 | str = str.substr(m[0].length);
|
48 | }
|
49 | };
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 | exports.prefixClass = function (klass, prefix) {
|
59 | return klass.split(' ').map(function (n) {
|
60 | return n.length > 0 ? (prefix + '-' + n) : n;
|
61 | }).join(' ');
|
62 | };
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 | exports.htmlize = function (src) {
|
69 |
|
70 | if (src.constructor === Array) src = src[0];
|
71 |
|
72 | if (src.substr(0, 1) === '<') {
|
73 | return src;
|
74 | } else {
|
75 | var Jade = require('jade');
|
76 | return Jade.render(src);
|
77 | }
|
78 | };
|