diff options
Diffstat (limited to 'tools/node_modules/eslint/node_modules/remark-parse/lib/tokenize/html-block.js')
-rw-r--r-- | tools/node_modules/eslint/node_modules/remark-parse/lib/tokenize/html-block.js | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/tools/node_modules/eslint/node_modules/remark-parse/lib/tokenize/html-block.js b/tools/node_modules/eslint/node_modules/remark-parse/lib/tokenize/html-block.js new file mode 100644 index 0000000000..dc861b53c3 --- /dev/null +++ b/tools/node_modules/eslint/node_modules/remark-parse/lib/tokenize/html-block.js @@ -0,0 +1,103 @@ +/** + * @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}); +} |