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

150 lines
2.6 KiB
JavaScript

/**
* @author Titus Wormer
* @copyright 2015 Titus Wormer
* @license MIT
* @module remark:parse:tokenize:heading-atx
* @fileoverview Tokenise an ATX-style heading.
*/
'use strict';
module.exports = atxHeading;
var C_NEWLINE = '\n';
var C_TAB = '\t';
var C_SPACE = ' ';
var C_HASH = '#';
var MAX_ATX_COUNT = 6;
/* Tokenise an ATX-style heading. */
function atxHeading(eat, value, silent) {
var self = this;
var settings = self.options;
var length = value.length + 1;
var index = -1;
var now = eat.now();
var subvalue = '';
var content = '';
var character;
var queue;
var depth;
/* Eat initial spacing. */
while (++index < length) {
character = value.charAt(index);
if (character !== C_SPACE && character !== C_TAB) {
index--;
break;
}
subvalue += character;
}
/* Eat hashes. */
depth = 0;
while (++index <= length) {
character = value.charAt(index);
if (character !== C_HASH) {
index--;
break;
}
subvalue += character;
depth++;
}
if (depth > MAX_ATX_COUNT) {
return;
}
if (
!depth ||
(!settings.pedantic && value.charAt(index + 1) === C_HASH)
) {
return;
}
length = value.length + 1;
/* Eat intermediate white-space. */
queue = '';
while (++index < length) {
character = value.charAt(index);
if (character !== C_SPACE && character !== C_TAB) {
index--;
break;
}
queue += character;
}
/* Exit when not in pedantic mode without spacing. */
if (
!settings.pedantic &&
queue.length === 0 &&
character &&
character !== C_NEWLINE
) {
return;
}
if (silent) {
return true;
}
/* Eat content. */
subvalue += queue;
queue = '';
content = '';
while (++index < length) {
character = value.charAt(index);
if (!character || character === C_NEWLINE) {
break;
}
if (
character !== C_SPACE &&
character !== C_TAB &&
character !== C_HASH
) {
content += queue + character;
queue = '';
continue;
}
while (character === C_SPACE || character === C_TAB) {
queue += character;
character = value.charAt(++index);
}
while (character === C_HASH) {
queue += character;
character = value.charAt(++index);
}
while (character === C_SPACE || character === C_TAB) {
queue += character;
character = value.charAt(++index);
}
index--;
}
now.column += subvalue.length;
now.offset += subvalue.length;
subvalue += content + queue;
return eat(subvalue)({
type: 'heading',
depth: depth,
children: self.tokenizeInline(content, now)
});
}