node/tools/eslint/node_modules/remark-parse/lib/tokenize/code-inline.js
Vse Mozhet Byt 3bc72ab274 tools: update: eslint-plugin-markdown@1.0.0-beta.7
* Remove pinning of eslint-plugin-markdown

  An issue affecting Node.js source has been fixed in
  eslint-plugin-markdown so we don't need to pin it to beta-4 anymore.

  Refs: https://github.com/eslint/eslint-plugin-markdown/issues/69

* Update eslint-plugin-markdown up to 1.0.0-beta.7

* Fix docs for eslint-plugin-markdown@1.0.0-beta.7

PR-URL: https://github.com/nodejs/node/pull/14047
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2017-07-19 15:02:09 -04:00

120 lines
2 KiB
JavaScript

/**
* @author Titus Wormer
* @copyright 2015 Titus Wormer
* @license MIT
* @module remark:parse:tokenize:code-inline
* @fileoverview Tokenise inline code.
*/
'use strict';
var whitespace = require('is-whitespace-character');
var locate = require('../locate/code-inline');
module.exports = inlineCode;
inlineCode.locator = locate;
var C_TICK = '`';
/* Tokenise inline code. */
function inlineCode(eat, value, silent) {
var length = value.length;
var index = 0;
var queue = '';
var tickQueue = '';
var contentQueue;
var subqueue;
var count;
var openingCount;
var subvalue;
var character;
var found;
var next;
while (index < length) {
if (value.charAt(index) !== C_TICK) {
break;
}
queue += C_TICK;
index++;
}
if (!queue) {
return;
}
subvalue = queue;
openingCount = index;
queue = '';
next = value.charAt(index);
count = 0;
while (index < length) {
character = next;
next = value.charAt(index + 1);
if (character === C_TICK) {
count++;
tickQueue += character;
} else {
count = 0;
queue += character;
}
if (count && next !== C_TICK) {
if (count === openingCount) {
subvalue += queue + tickQueue;
found = true;
break;
}
queue += tickQueue;
tickQueue = '';
}
index++;
}
if (!found) {
if (openingCount % 2 !== 0) {
return;
}
queue = '';
}
/* istanbul ignore if - never used (yet) */
if (silent) {
return true;
}
contentQueue = '';
subqueue = '';
length = queue.length;
index = -1;
while (++index < length) {
character = queue.charAt(index);
if (whitespace(character)) {
subqueue += character;
continue;
}
if (subqueue) {
if (contentQueue) {
contentQueue += subqueue;
}
subqueue = '';
}
contentQueue += character;
}
return eat(subvalue)({
type: 'inlineCode',
value: contentQueue
});
}