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