3 var trim = require('trim-trailing-lines');
5 module.exports = fencedCode;
13 var MIN_FENCE_COUNT = 3;
14 var CODE_INDENT_COUNT = 4;
16 function fencedCode(eat, value, silent) {
18 var settings = self.options;
19 var length = value.length + 1;
38 /* Eat initial spacing. */
39 while (index < length) {
40 character = value.charAt(index);
42 if (character !== C_SPACE && character !== C_TAB) {
46 subvalue += character;
53 character = value.charAt(index);
55 if (character !== C_TILDE && character !== C_TICK) {
62 subvalue += character;
64 while (index < length) {
65 character = value.charAt(index);
67 if (character !== marker) {
71 subvalue += character;
76 if (fenceCount < MIN_FENCE_COUNT) {
80 /* Eat spacing before flag. */
81 while (index < length) {
82 character = value.charAt(index);
84 if (character !== C_SPACE && character !== C_TAB) {
88 subvalue += character;
96 while (index < length) {
97 character = value.charAt(index);
100 character === C_NEWLINE ||
101 character === C_TILDE ||
107 if (character === C_SPACE || character === C_TAB) {
110 flag += queue + character;
117 character = value.charAt(index);
119 if (character && character !== C_NEWLINE) {
128 now.column += subvalue.length;
129 now.offset += subvalue.length;
132 flag = self.decode.raw(self.unescape(flag), now);
140 exdentedClosing = '';
142 exdentedContent = '';
145 while (index < length) {
146 character = value.charAt(index);
148 exdentedContent += exdentedClosing;
150 exdentedClosing = '';
152 if (character !== C_NEWLINE) {
153 content += character;
154 exdentedClosing += character;
159 /* Add the newline to `subvalue` if its the first
160 * character. Otherwise, add it to the `closing`
163 closing += character;
164 exdentedClosing += character;
166 subvalue += character;
172 while (index < length) {
173 character = value.charAt(index);
175 if (character !== C_SPACE) {
184 exdentedClosing += queue.slice(indent);
186 if (queue.length >= CODE_INDENT_COUNT) {
192 while (index < length) {
193 character = value.charAt(index);
195 if (character !== marker) {
204 exdentedClosing += queue;
206 if (queue.length < fenceCount) {
212 while (index < length) {
213 character = value.charAt(index);
215 if (character !== C_SPACE && character !== C_TAB) {
219 closing += character;
220 exdentedClosing += character;
224 if (!character || character === C_NEWLINE) {
229 subvalue += content + closing;
231 return eat(subvalue)({
234 value: trim(exdentedContent)