1 | var trim = require('../utils/trim');
|
2 | var unindent = require('../utils/unindent');
|
3 |
|
4 | function parse(content, source) {
|
5 | source = trim(source);
|
6 |
|
7 | var title = '';
|
8 | var text = '';
|
9 | var type;
|
10 |
|
11 |
|
12 |
|
13 | var parseRegExpFirstLine = /(@\w*)?(?:(?:\s*\{\s*([a-zA-Z0-9\.\/\\\[\]_-]+)\s*\}\s*)?\s*(.*)?)?/;
|
14 | var parseRegExpFollowing = /(^.*\s?)/gm;
|
15 |
|
16 | var matches;
|
17 | if ( (matches = parseRegExpFirstLine.exec(source)) ) {
|
18 | type = matches[2];
|
19 | title = matches[3];
|
20 | }
|
21 |
|
22 | parseRegExpFollowing.exec(content);
|
23 | while ( (matches = parseRegExpFollowing.exec(source)) ) {
|
24 | text += matches[1];
|
25 | }
|
26 |
|
27 | if (text.length === 0)
|
28 | return null;
|
29 |
|
30 | return {
|
31 | title : title,
|
32 | content: unindent(text),
|
33 | type : type || 'json'
|
34 | };
|
35 | }
|
36 |
|
37 |
|
38 |
|
39 |
|
40 | module.exports = {
|
41 | parse : parse,
|
42 | path : 'local.examples',
|
43 | method: 'push'
|
44 | };
|