|
1 |
| -'use strict'; |
| 1 | +'use strict' |
2 | 2 |
|
3 |
| -/* Expose. */ |
4 |
| -module.exports = zone; |
| 3 | +var commentMarker = require('mdast-comment-marker') |
| 4 | +var visit = require('unist-util-visit') |
5 | 5 |
|
6 |
| -/* Dependencies. */ |
7 |
| -var commentMarker = require('mdast-comment-marker'); |
8 |
| -var visit = require('unist-util-visit'); |
| 6 | +module.exports = zone |
9 | 7 |
|
10 |
| -/* Methods. */ |
11 |
| -var splice = [].splice; |
| 8 | +var splice = [].splice |
12 | 9 |
|
13 |
| -/* Run factory. */ |
14 | 10 | function zone(node, name, callback) {
|
15 |
| - var nodes = []; |
16 |
| - var start = null; |
17 |
| - var scope = null; |
18 |
| - var level = 0; |
19 |
| - var position; |
| 11 | + var nodes = [] |
| 12 | + var start = null |
| 13 | + var scope = null |
| 14 | + var level = 0 |
| 15 | + var position |
20 | 16 |
|
21 |
| - visit(node, gather); |
| 17 | + visit(node, gather) |
22 | 18 |
|
23 | 19 | /* Gather one dimensional zones. */
|
24 | 20 | function gather(node, index, parent) {
|
25 |
| - var type = test(node); |
| 21 | + var type = test(node) |
26 | 22 |
|
27 | 23 | if (scope && parent === scope) {
|
28 | 24 | if (type === 'start') {
|
29 |
| - level++; |
| 25 | + level++ |
30 | 26 | }
|
31 | 27 |
|
32 | 28 | if (type === 'end') {
|
33 |
| - level--; |
| 29 | + level-- |
34 | 30 | }
|
35 | 31 |
|
36 | 32 | if (type === 'end' && level === 0) {
|
37 | 33 | nodes = callback(start, nodes, node, {
|
38 | 34 | start: index - nodes.length - 1,
|
39 | 35 | end: index,
|
40 | 36 | parent: scope
|
41 |
| - }); |
| 37 | + }) |
42 | 38 |
|
43 | 39 | if (nodes) {
|
44 |
| - splice.apply(scope.children, [position, index - position + 1].concat(nodes)); |
| 40 | + splice.apply( |
| 41 | + scope.children, |
| 42 | + [position, index - position + 1].concat(nodes) |
| 43 | + ) |
45 | 44 | }
|
46 | 45 |
|
47 |
| - start = null; |
48 |
| - scope = null; |
49 |
| - position = null; |
50 |
| - nodes = []; |
| 46 | + start = null |
| 47 | + scope = null |
| 48 | + position = null |
| 49 | + nodes = [] |
51 | 50 | } else {
|
52 |
| - nodes.push(node); |
| 51 | + nodes.push(node) |
53 | 52 | }
|
54 | 53 | }
|
55 | 54 |
|
56 | 55 | if (!scope && type === 'start') {
|
57 |
| - level = 1; |
58 |
| - position = index; |
59 |
| - start = node; |
60 |
| - scope = parent; |
| 56 | + level = 1 |
| 57 | + position = index |
| 58 | + start = node |
| 59 | + scope = parent |
61 | 60 | }
|
62 | 61 | }
|
63 | 62 |
|
64 | 63 | /* Test if `node` matches the bound settings. */
|
65 | 64 | function test(node) {
|
66 |
| - var marker = commentMarker(node); |
67 |
| - var attributes; |
68 |
| - var head; |
| 65 | + var marker = commentMarker(node) |
| 66 | + var attributes |
| 67 | + var head |
69 | 68 |
|
70 | 69 | if (!marker || marker.name !== name) {
|
71 |
| - return null; |
| 70 | + return null |
72 | 71 | }
|
73 | 72 |
|
74 |
| - attributes = marker.attributes; |
75 |
| - head = attributes.match(/(start|end)\b/); |
| 73 | + attributes = marker.attributes |
| 74 | + head = attributes.match(/(start|end)\b/) |
76 | 75 |
|
77 |
| - return head ? head[0] : null; |
| 76 | + return head ? head[0] : null |
78 | 77 | }
|
79 | 78 | }
|
0 commit comments