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

Function scanDelims

src/commonmark.js:1287–1342  ·  view source on GitHub ↗
(cc)

Source from the content-addressed store, hash-verified

1285// they can open and/or close emphasis or strong emphasis. A utility
1286// function for strong/emph parsing.
1287var scanDelims = function(cc) {
1288 var numdelims = 0;
1289 var char_before, char_after, cc_after;
1290 var startpos = this.pos;
1291 var left_flanking, right_flanking, can_open, can_close;
1292 var after_is_whitespace, after_is_punctuation, before_is_whitespace, before_is_punctuation;
1293
1294 if (cc === C_SINGLEQUOTE || cc === C_DOUBLEQUOTE) {
1295 numdelims++;
1296 this.pos++;
1297 } else {
1298 while (this.peek() === cc) {
1299 numdelims++;
1300 this.pos++;
1301 }
1302 }
1303
1304 if (numdelims === 0) {
1305 return null;
1306 }
1307
1308 char_before = startpos === 0 ? '\n' : this.subject.charAt(startpos - 1);
1309
1310 cc_after = this.peek();
1311 if (cc_after === -1) {
1312 char_after = '\n';
1313 } else {
1314 char_after = fromCodePoint(cc_after);
1315 }
1316
1317 after_is_whitespace = reWhitespaceChar.test(char_after);
1318 after_is_punctuation = rePunctuation.test(char_after);
1319 before_is_whitespace = reWhitespaceChar.test(char_before);
1320 before_is_punctuation = rePunctuation.test(char_before);
1321
1322 left_flanking = !after_is_whitespace &&
1323 !(after_is_punctuation && !before_is_whitespace && !before_is_punctuation);
1324 right_flanking = !before_is_whitespace &&
1325 !(before_is_punctuation && !after_is_whitespace && !after_is_punctuation);
1326 if (cc === C_UNDERSCORE) {
1327 can_open = left_flanking &&
1328 (!right_flanking || before_is_punctuation);
1329 can_close = right_flanking &&
1330 (!left_flanking || after_is_punctuation);
1331 } else if (cc === C_SINGLEQUOTE || cc === C_DOUBLEQUOTE) {
1332 can_open = left_flanking && !right_flanking;
1333 can_close = right_flanking;
1334 } else {
1335 can_open = left_flanking;
1336 can_close = right_flanking;
1337 }
1338 this.pos = startpos;
1339 return { numdelims: numdelims,
1340 can_open: can_open,
1341 can_close: can_close };
1342};
1343
1344// Handle a delimiter marker for emphasis or a quote.

Callers

nothing calls this directly

Calls 3

fromCodePointFunction · 0.85
peekMethod · 0.80
testMethod · 0.45

Tested by

no test coverage detected