1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | 'use strict';
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | var yaml = require('remark-yaml');
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | function noop() {}
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 | function factory(method) {
|
31 | var callback = method || noop;
|
32 |
|
33 | return function (node, instance) {
|
34 | var config = node.yaml && node.yaml.remark;
|
35 |
|
36 | if (config) {
|
37 | try {
|
38 | instance.setOptions(config);
|
39 | } catch (exception) {
|
40 | instance.file.fail(exception.message, node);
|
41 | }
|
42 | }
|
43 |
|
44 | callback.apply(this, arguments);
|
45 | };
|
46 | }
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 | function attacher(remark, options) {
|
55 | var settings = options || {};
|
56 |
|
57 | settings.onparse = factory(settings.onparse);
|
58 | settings.onstringify = factory(settings.onstringify);
|
59 |
|
60 | remark.use(yaml, settings);
|
61 | }
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 | module.exports = attacher;
|