* 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>
137 lines
2.6 KiB
JavaScript
137 lines
2.6 KiB
JavaScript
/**
|
|
* @author Titus Wormer
|
|
* @copyright 2015 Titus Wormer
|
|
* @license MIT
|
|
* @module remark:parse:tokenize:blockquote
|
|
* @fileoverview Tokenise blockquote.
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
var trim = require('trim');
|
|
var interrupt = require('../util/interrupt');
|
|
|
|
module.exports = blockquote;
|
|
|
|
var C_NEWLINE = '\n';
|
|
var C_TAB = '\t';
|
|
var C_SPACE = ' ';
|
|
var C_GT = '>';
|
|
|
|
/* Tokenise a blockquote. */
|
|
function blockquote(eat, value, silent) {
|
|
var self = this;
|
|
var offsets = self.offset;
|
|
var tokenizers = self.blockTokenizers;
|
|
var interruptors = self.interruptBlockquote;
|
|
var now = eat.now();
|
|
var currentLine = now.line;
|
|
var length = value.length;
|
|
var values = [];
|
|
var contents = [];
|
|
var indents = [];
|
|
var add;
|
|
var index = 0;
|
|
var character;
|
|
var rest;
|
|
var nextIndex;
|
|
var content;
|
|
var line;
|
|
var startIndex;
|
|
var prefixed;
|
|
var exit;
|
|
|
|
while (index < length) {
|
|
character = value.charAt(index);
|
|
|
|
if (character !== C_SPACE && character !== C_TAB) {
|
|
break;
|
|
}
|
|
|
|
index++;
|
|
}
|
|
|
|
if (value.charAt(index) !== C_GT) {
|
|
return;
|
|
}
|
|
|
|
if (silent) {
|
|
return true;
|
|
}
|
|
|
|
index = 0;
|
|
|
|
while (index < length) {
|
|
nextIndex = value.indexOf(C_NEWLINE, index);
|
|
startIndex = index;
|
|
prefixed = false;
|
|
|
|
if (nextIndex === -1) {
|
|
nextIndex = length;
|
|
}
|
|
|
|
while (index < length) {
|
|
character = value.charAt(index);
|
|
|
|
if (character !== C_SPACE && character !== C_TAB) {
|
|
break;
|
|
}
|
|
|
|
index++;
|
|
}
|
|
|
|
if (value.charAt(index) === C_GT) {
|
|
index++;
|
|
prefixed = true;
|
|
|
|
if (value.charAt(index) === C_SPACE) {
|
|
index++;
|
|
}
|
|
} else {
|
|
index = startIndex;
|
|
}
|
|
|
|
content = value.slice(index, nextIndex);
|
|
|
|
if (!prefixed && !trim(content)) {
|
|
index = startIndex;
|
|
break;
|
|
}
|
|
|
|
if (!prefixed) {
|
|
rest = value.slice(index);
|
|
|
|
/* Check if the following code contains a possible
|
|
* block. */
|
|
if (interrupt(interruptors, tokenizers, self, [eat, rest, true])) {
|
|
break;
|
|
}
|
|
}
|
|
|
|
line = startIndex === index ? content : value.slice(startIndex, nextIndex);
|
|
|
|
indents.push(index - startIndex);
|
|
values.push(line);
|
|
contents.push(content);
|
|
|
|
index = nextIndex + 1;
|
|
}
|
|
|
|
index = -1;
|
|
length = indents.length;
|
|
add = eat(values.join(C_NEWLINE));
|
|
|
|
while (++index < length) {
|
|
offsets[currentLine] = (offsets[currentLine] || 0) + indents[index];
|
|
currentLine++;
|
|
}
|
|
|
|
exit = self.enterBlock();
|
|
contents = self.tokenizeBlock(contents.join(C_NEWLINE), now);
|
|
exit();
|
|
|
|
return add({
|
|
type: 'blockquote',
|
|
children: contents
|
|
});
|
|
}
|