-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprops.js
More file actions
45 lines (37 loc) · 964 Bytes
/
props.js
File metadata and controls
45 lines (37 loc) · 964 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
var JSML = require('jsml');
var YAML = require('js-yaml');
module.exports = function(str, div) {
div = div || /\n\n\n|\r\n\r\n\r\n/;
// `str` must be a string
if (typeof str != 'string')
str = str.toString();
// trim string
str = str.trim();
var split;
var result = {};
var content;
// If a match was found
if ((split = str.split(div)).length > 0)
try {
// JSON
if (split[0].charAt(0) == '{')
result = JSON.parse(split[0]);
// JSML
else if (split[0].charAt(0) == '"')
result = JSML.parse(split[0]);
// YAML
else
result = YAML.load(split[0]);
} catch (e) {
return { __content: str };
}
else
return { __content: str };
delete split[0];
// Join remaining
str = split.join('\n\n\n');
str += '\n'; // append a line seperator after content, since some tools (like
// pandoc) need it
result.__content = str;
return result;
};