-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathmeta.js
46 lines (40 loc) · 866 Bytes
/
meta.js
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
46
'use strict'
const YAML = require('js-yaml')
module.exports = function (md) {
return meta.bind(null, md)
}
function get(state, line) {
const pos = state.bMarks[line]
const max = state.eMarks[line]
return state.src.substr(pos, max - pos)
}
function meta(md, state, start, end, silent) {
if (start !== 0 || state.blkIndent !== 0) {
return false
}
if (state.tShift[start] < 0) {
return false
}
if (!get(state, start).match(/^---$/)) {
return false
}
const data = []
let line = start
while (line < end) {
line++
const str = get(state, line)
if (str.match(/^---$/)) {
break
}
if (state.tShift[line] < 0) {
break
}
data.push(str)
}
// if (line >= end) {
// return false
// }
md.meta = YAML.safeLoad(data.join('\n'), {json: true}) || {}
state.line = line + 1
return true
}