1
- 'use strict' ;
1
+ 'use strict'
2
2
3
- var xtend = require ( 'xtend' ) ;
4
- var entities = require ( 'parse-entities' ) ;
3
+ var xtend = require ( 'xtend' )
4
+ var entities = require ( 'parse-entities' )
5
5
6
- module . exports = factory ;
6
+ module . exports = factory
7
7
8
- /* Factory to create an entity decoder. */
8
+ // Factory to create an entity decoder.
9
9
function factory ( ctx ) {
10
- decoder . raw = decodeRaw ;
10
+ decoder . raw = decodeRaw
11
11
12
- return decoder ;
12
+ return decoder
13
13
14
- /* Normalize `position` to add an `indent`. */
14
+ // Normalize `position` to add an `indent`.
15
15
function normalize ( position ) {
16
- var offsets = ctx . offset ;
17
- var line = position . line ;
18
- var result = [ ] ;
16
+ var offsets = ctx . offset
17
+ var line = position . line
18
+ var result = [ ]
19
19
20
20
while ( ++ line ) {
21
21
if ( ! ( line in offsets ) ) {
22
- break ;
22
+ break
23
23
}
24
24
25
- result . push ( ( offsets [ line ] || 0 ) + 1 ) ;
25
+ result . push ( ( offsets [ line ] || 0 ) + 1 )
26
26
}
27
27
28
- return {
29
- start : position ,
30
- indent : result
31
- } ;
28
+ return { start : position , indent : result }
32
29
}
33
30
34
- /* Handle a warning.
35
- * See https://github.com/wooorm/parse-entities
36
- * for the warnings. */
37
- function handleWarning ( reason , position , code ) {
38
- if ( code === 3 ) {
39
- return ;
40
- }
41
-
42
- ctx . file . message ( reason , position ) ;
43
- }
44
-
45
- /* Decode `value` (at `position`) into text-nodes. */
31
+ // Decode `value` (at `position`) into text-nodes.
46
32
function decoder ( value , position , handler ) {
47
33
entities ( value , {
48
34
position : normalize ( position ) ,
@@ -51,14 +37,22 @@ function factory(ctx) {
51
37
reference : handler ,
52
38
textContext : ctx ,
53
39
referenceContext : ctx
54
- } ) ;
40
+ } )
55
41
}
56
42
57
- /* Decode `value` (at `position`) into a string. */
43
+ // Decode `value` (at `position`) into a string.
58
44
function decodeRaw ( value , position , options ) {
59
- return entities ( value , xtend ( options , {
60
- position : normalize ( position ) ,
61
- warning : handleWarning
62
- } ) ) ;
45
+ return entities (
46
+ value ,
47
+ xtend ( options , { position : normalize ( position ) , warning : handleWarning } )
48
+ )
49
+ }
50
+
51
+ // Handle a warning.
52
+ // See <https://github.com/wooorm/parse-entities> for the warnings.
53
+ function handleWarning ( reason , position , code ) {
54
+ if ( code !== 3 ) {
55
+ ctx . file . message ( reason , position )
56
+ }
63
57
}
64
58
}
0 commit comments