3 var whitespace = require('is-whitespace-character');
4 var normalize = require('../util/normalize');
6 module.exports = footnoteDefinition;
7 footnoteDefinition.notInList = true;
8 footnoteDefinition.notInBlock = true;
10 var C_BACKSLASH = '\\';
14 var C_BRACKET_OPEN = '[';
15 var C_BRACKET_CLOSE = ']';
19 var EXPRESSION_INITIAL_TAB = /^( {4}|\t)?/gm;
21 function footnoteDefinition(eat, value, silent) {
23 var offsets = self.offset;
37 if (!self.options.footnotes) {
42 length = value.length;
45 currentLine = now.line;
47 while (index < length) {
48 character = value.charAt(index);
50 if (!whitespace(character)) {
54 subvalue += character;
59 value.charAt(index) !== C_BRACKET_OPEN ||
60 value.charAt(index + 1) !== C_CARET
65 subvalue += C_BRACKET_OPEN + C_CARET;
66 index = subvalue.length;
69 while (index < length) {
70 character = value.charAt(index);
72 if (character === C_BRACKET_CLOSE) {
74 } else if (character === C_BACKSLASH) {
77 character = value.charAt(index);
86 value.charAt(index) !== C_BRACKET_CLOSE ||
87 value.charAt(index + 1) !== C_COLON
96 identifier = normalize(queue);
97 subvalue += queue + C_BRACKET_CLOSE + C_COLON;
98 index = subvalue.length;
100 while (index < length) {
101 character = value.charAt(index);
103 if (character !== C_TAB && character !== C_SPACE) {
107 subvalue += character;
111 now.column += subvalue.length;
112 now.offset += subvalue.length;
117 while (index < length) {
118 character = value.charAt(index);
120 if (character === C_NEWLINE) {
121 subqueue = character;
124 while (index < length) {
125 character = value.charAt(index);
127 if (character !== C_NEWLINE) {
131 subqueue += character;
138 while (index < length) {
139 character = value.charAt(index);
141 if (character !== C_SPACE) {
145 subqueue += character;
149 if (subqueue.length === 0) {
161 content += character;
167 content = content.replace(EXPRESSION_INITIAL_TAB, function (line) {
168 offsets[currentLine] = (offsets[currentLine] || 0) + line.length;
176 exit = self.enterBlock();
177 content = self.tokenizeBlock(content, now);
181 type: 'footnoteDefinition',
182 identifier: identifier,