* 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>
74 lines
1.3 KiB
JavaScript
74 lines
1.3 KiB
JavaScript
/**
|
|
* @author Titus Wormer
|
|
* @copyright 2015 Titus Wormer
|
|
* @license MIT
|
|
* @module remark:parse:tokenize:yaml
|
|
* @fileoverview Tokenise YAML.
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
module.exports = yaml;
|
|
yaml.onlyAtStart = true;
|
|
|
|
var FENCE = '---';
|
|
var C_DASH = '-';
|
|
var C_NEWLINE = '\n';
|
|
|
|
/* Tokenise YAML. */
|
|
function yaml(eat, value, silent) {
|
|
var self = this;
|
|
var subvalue;
|
|
var content;
|
|
var index;
|
|
var length;
|
|
var character;
|
|
var queue;
|
|
|
|
if (
|
|
!self.options.yaml ||
|
|
value.charAt(0) !== C_DASH ||
|
|
value.charAt(1) !== C_DASH ||
|
|
value.charAt(2) !== C_DASH ||
|
|
value.charAt(3) !== C_NEWLINE
|
|
) {
|
|
return;
|
|
}
|
|
|
|
subvalue = FENCE + C_NEWLINE;
|
|
content = '';
|
|
queue = '';
|
|
index = 3;
|
|
length = value.length;
|
|
|
|
while (++index < length) {
|
|
character = value.charAt(index);
|
|
|
|
if (
|
|
character === C_DASH &&
|
|
(queue || !content) &&
|
|
value.charAt(index + 1) === C_DASH &&
|
|
value.charAt(index + 2) === C_DASH
|
|
) {
|
|
/* istanbul ignore if - never used (yet) */
|
|
if (silent) {
|
|
return true;
|
|
}
|
|
|
|
subvalue += queue + FENCE;
|
|
|
|
return eat(subvalue)({
|
|
type: 'yaml',
|
|
value: content
|
|
});
|
|
}
|
|
|
|
if (character === C_NEWLINE) {
|
|
queue += character;
|
|
} else {
|
|
subvalue += queue + character;
|
|
content += queue + character;
|
|
queue = '';
|
|
}
|
|
}
|
|
}
|