* 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>
103 lines
2 KiB
JavaScript
103 lines
2 KiB
JavaScript
/**
|
|
* @author Titus Wormer
|
|
* @copyright 2015 Titus Wormer
|
|
* @license MIT
|
|
* @module remark:parse:tokenize:html-block
|
|
* @fileoverview Tokenise block HTML.
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
var openCloseTag = require('../util/html').openCloseTag;
|
|
|
|
module.exports = blockHTML;
|
|
|
|
var C_TAB = '\t';
|
|
var C_SPACE = ' ';
|
|
var C_NEWLINE = '\n';
|
|
var C_LT = '<';
|
|
|
|
/* Tokenise block HTML. */
|
|
function blockHTML(eat, value, silent) {
|
|
var self = this;
|
|
var blocks = self.options.blocks;
|
|
var length = value.length;
|
|
var index = 0;
|
|
var next;
|
|
var line;
|
|
var offset;
|
|
var character;
|
|
var count;
|
|
var sequence;
|
|
var subvalue;
|
|
|
|
var sequences = [
|
|
[/^<(script|pre|style)(?=(\s|>|$))/i, /<\/(script|pre|style)>/i, true],
|
|
[/^<!--/, /-->/, true],
|
|
[/^<\?/, /\?>/, true],
|
|
[/^<![A-Za-z]/, />/, true],
|
|
[/^<!\[CDATA\[/, /\]\]>/, true],
|
|
[new RegExp('^</?(' + blocks.join('|') + ')(?=(\\s|/?>|$))', 'i'), /^$/, true],
|
|
[new RegExp(openCloseTag.source + '\\s*$'), /^$/, false]
|
|
];
|
|
|
|
/* Eat initial spacing. */
|
|
while (index < length) {
|
|
character = value.charAt(index);
|
|
|
|
if (character !== C_TAB && character !== C_SPACE) {
|
|
break;
|
|
}
|
|
|
|
index++;
|
|
}
|
|
|
|
if (value.charAt(index) !== C_LT) {
|
|
return;
|
|
}
|
|
|
|
next = value.indexOf(C_NEWLINE, index + 1);
|
|
next = next === -1 ? length : next;
|
|
line = value.slice(index, next);
|
|
offset = -1;
|
|
count = sequences.length;
|
|
|
|
while (++offset < count) {
|
|
if (sequences[offset][0].test(line)) {
|
|
sequence = sequences[offset];
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!sequence) {
|
|
return;
|
|
}
|
|
|
|
if (silent) {
|
|
return sequence[2];
|
|
}
|
|
|
|
index = next;
|
|
|
|
if (!sequence[1].test(line)) {
|
|
while (index < length) {
|
|
next = value.indexOf(C_NEWLINE, index + 1);
|
|
next = next === -1 ? length : next;
|
|
line = value.slice(index + 1, next);
|
|
|
|
if (sequence[1].test(line)) {
|
|
if (line) {
|
|
index = next;
|
|
}
|
|
|
|
break;
|
|
}
|
|
|
|
index = next;
|
|
}
|
|
}
|
|
|
|
subvalue = value.slice(0, index);
|
|
|
|
return eat(subvalue)({type: 'html', value: subvalue});
|
|
}
|