node/tools/eslint/node_modules/remark-parse/lib/tokenize/thematic-break.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

79 lines
1.5 KiB
JavaScript

/**
* @author Titus Wormer
* @copyright 2015 Titus Wormer
* @license MIT
* @module remark:parse:tokenize:thematic-break
* @fileoverview Tokenise a thematic break.
*/
'use strict';
module.exports = thematicBreak;
var C_NEWLINE = '\n';
var C_TAB = '\t';
var C_SPACE = ' ';
var C_ASTERISK = '*';
var C_UNDERSCORE = '_';
var C_DASH = '-';
var THEMATIC_BREAK_MARKER_COUNT = 3;
/* Tokenise a thematic break. */
function thematicBreak(eat, value, silent) {
var index = -1;
var length = value.length + 1;
var subvalue = '';
var character;
var marker;
var markerCount;
var queue;
while (++index < length) {
character = value.charAt(index);
if (character !== C_TAB && character !== C_SPACE) {
break;
}
subvalue += character;
}
if (
character !== C_ASTERISK &&
character !== C_DASH &&
character !== C_UNDERSCORE
) {
return;
}
marker = character;
subvalue += character;
markerCount = 1;
queue = '';
while (++index < length) {
character = value.charAt(index);
if (character === marker) {
markerCount++;
subvalue += queue + marker;
queue = '';
} else if (character === C_SPACE) {
queue += character;
} else if (
markerCount >= THEMATIC_BREAK_MARKER_COUNT &&
(!character || character === C_NEWLINE)
) {
subvalue += queue;
if (silent) {
return true;
}
return eat(subvalue)({type: 'thematicBreak'});
} else {
return;
}
}
}