MCPcopy Index your code
hub / github.com/witheve/Eve / parseListMarker

Function parseListMarker

src/commonmark.js:128–190  ·  view source on GitHub ↗
(parser, container)

Source from the content-addressed store, hash-verified

126// Parse a list marker and return data on the marker (type,
127// start, delimiter, bullet character, padding) or null.
128var parseListMarker = function(parser, container) {
129 var rest = parser.currentLine.slice(parser.nextNonspace);
130 var match;
131 var nextc;
132 var spacesStartCol;
133 var spacesStartOffset;
134 var data = { type: null,
135 tight: true, // lists are tight by default
136 bulletChar: null,
137 start: null,
138 delimiter: null,
139 padding: null,
140 markerOffset: parser.indent };
141 if ((match = rest.match(reBulletListMarker))) {
142 data.type = 'bullet';
143 data.bulletChar = match[0][0];
144
145 } else if ((match = rest.match(reOrderedListMarker)) &&
146 (container.type !== 'paragraph' ||
147 match[1] === '1')) {
148 data.type = 'ordered';
149 data.start = parseInt(match[1]);
150 data.delimiter = match[2];
151 } else {
152 return null;
153 }
154 // make sure we have spaces after
155 nextc = peek(parser.currentLine, parser.nextNonspace + match[0].length);
156 if (!(nextc === -1 || nextc === C_TAB || nextc === C_SPACE)) {
157 return null;
158 }
159
160 // if it interrupts paragraph, make sure first line isn't blank
161 if (container.type === 'paragraph' && !parser.currentLine.slice(parser.nextNonspace + match[0].length).match(reNonSpace)) {
162 return null;
163 }
164
165 // we've got a match! advance offset and calculate padding
166 parser.advanceNextNonspace(); // to start of marker
167 parser.advanceOffset(match[0].length, true); // to end of marker
168 spacesStartCol = parser.column;
169 spacesStartOffset = parser.offset;
170 do {
171 parser.advanceOffset(1, true);
172 nextc = peek(parser.currentLine, parser.offset);
173 } while (parser.column - spacesStartCol < 5 &&
174 isSpaceOrTab(nextc));
175 var blank_item = peek(parser.currentLine, parser.offset) === -1;
176 var spaces_after_marker = parser.column - spacesStartCol;
177 if (spaces_after_marker >= 5 ||
178 spaces_after_marker < 1 ||
179 blank_item) {
180 data.padding = match[0].length + 1;
181 parser.column = spacesStartCol;
182 parser.offset = spacesStartOffset;
183 if (isSpaceOrTab(peek(parser.currentLine, parser.offset))) {
184 parser.advanceOffset(1, true);
185 }

Callers 1

commonmark.jsFile · 0.85

Calls 3

peekFunction · 0.85
isSpaceOrTabFunction · 0.85
matchMethod · 0.80

Tested by

no test coverage detected