.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / remark-parse / lib / tokenize / delete.js
1 'use strict';
2
3 var whitespace = require('is-whitespace-character');
4 var locate = require('../locate/delete');
5
6 module.exports = strikethrough;
7 strikethrough.locator = locate;
8
9 var C_TILDE = '~';
10 var DOUBLE = '~~';
11
12 function strikethrough(eat, value, silent) {
13   var self = this;
14   var character = '';
15   var previous = '';
16   var preceding = '';
17   var subvalue = '';
18   var index;
19   var length;
20   var now;
21
22   if (
23     !self.options.gfm ||
24     value.charAt(0) !== C_TILDE ||
25     value.charAt(1) !== C_TILDE ||
26     whitespace(value.charAt(2))
27   ) {
28     return;
29   }
30
31   index = 1;
32   length = value.length;
33   now = eat.now();
34   now.column += 2;
35   now.offset += 2;
36
37   while (++index < length) {
38     character = value.charAt(index);
39
40     if (
41       character === C_TILDE &&
42       previous === C_TILDE &&
43       (!preceding || !whitespace(preceding))
44     ) {
45       /* istanbul ignore if - never used (yet) */
46       if (silent) {
47         return true;
48       }
49
50       return eat(DOUBLE + subvalue + DOUBLE)({
51         type: 'delete',
52         children: self.tokenizeInline(subvalue, now)
53       });
54     }
55
56     subvalue += previous;
57     preceding = previous;
58     previous = character;
59   }
60 }