.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / remark-parse / lib / tokenize / blockquote.js
1 'use strict';
2
3 var trim = require('trim');
4 var interrupt = require('../util/interrupt');
5
6 module.exports = blockquote;
7
8 var C_NEWLINE = '\n';
9 var C_TAB = '\t';
10 var C_SPACE = ' ';
11 var C_GT = '>';
12
13 /* Tokenise a blockquote. */
14 function blockquote(eat, value, silent) {
15   var self = this;
16   var offsets = self.offset;
17   var tokenizers = self.blockTokenizers;
18   var interruptors = self.interruptBlockquote;
19   var now = eat.now();
20   var currentLine = now.line;
21   var length = value.length;
22   var values = [];
23   var contents = [];
24   var indents = [];
25   var add;
26   var index = 0;
27   var character;
28   var rest;
29   var nextIndex;
30   var content;
31   var line;
32   var startIndex;
33   var prefixed;
34   var exit;
35
36   while (index < length) {
37     character = value.charAt(index);
38
39     if (character !== C_SPACE && character !== C_TAB) {
40       break;
41     }
42
43     index++;
44   }
45
46   if (value.charAt(index) !== C_GT) {
47     return;
48   }
49
50   if (silent) {
51     return true;
52   }
53
54   index = 0;
55
56   while (index < length) {
57     nextIndex = value.indexOf(C_NEWLINE, index);
58     startIndex = index;
59     prefixed = false;
60
61     if (nextIndex === -1) {
62       nextIndex = length;
63     }
64
65     while (index < length) {
66       character = value.charAt(index);
67
68       if (character !== C_SPACE && character !== C_TAB) {
69         break;
70       }
71
72       index++;
73     }
74
75     if (value.charAt(index) === C_GT) {
76       index++;
77       prefixed = true;
78
79       if (value.charAt(index) === C_SPACE) {
80         index++;
81       }
82     } else {
83       index = startIndex;
84     }
85
86     content = value.slice(index, nextIndex);
87
88     if (!prefixed && !trim(content)) {
89       index = startIndex;
90       break;
91     }
92
93     if (!prefixed) {
94       rest = value.slice(index);
95
96       /* Check if the following code contains a possible
97        * block. */
98       if (interrupt(interruptors, tokenizers, self, [eat, rest, true])) {
99         break;
100       }
101     }
102
103     line = startIndex === index ? content : value.slice(startIndex, nextIndex);
104
105     indents.push(index - startIndex);
106     values.push(line);
107     contents.push(content);
108
109     index = nextIndex + 1;
110   }
111
112   index = -1;
113   length = indents.length;
114   add = eat(values.join(C_NEWLINE));
115
116   while (++index < length) {
117     offsets[currentLine] = (offsets[currentLine] || 0) + indents[index];
118     currentLine++;
119   }
120
121   exit = self.enterBlock();
122   contents = self.tokenizeBlock(contents.join(C_NEWLINE), now);
123   exit();
124
125   return add({
126     type: 'blockquote',
127     children: contents
128   });
129 }