Markdown parser, done right. 100% CommonMark support, extensions, syntax plugins & high speed https://markdown-it.github.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

72 lines
1.9 KiB

// HTML block
'use strict';
var block_names = require('../common/html_blocks');
var HTML_TAG_OPEN_RE = /^<([a-zA-Z]{1,15})[\s\/>]/;
var HTML_TAG_CLOSE_RE = /^<\/([a-zA-Z]{1,15})[\s>]/;
function isLetter(ch) {
/*eslint no-bitwise:0*/
var lc = ch | 0x20; // to lower case
return (lc >= 0x61/* a */) && (lc <= 0x7a/* z */);
}
module.exports = function html_block(state, startLine, endLine, silent) {
var ch, match, nextLine, token,
pos = state.bMarks[startLine],
max = state.eMarks[startLine],
shift = state.tShift[startLine];
pos += shift;
if (!state.md.options.html) { return false; }
if (shift > 3 || pos + 2 >= max) { return false; }
if (state.src.charCodeAt(pos) !== 0x3C/* < */) { return false; }
ch = state.src.charCodeAt(pos + 1);
if (ch === 0x21/* ! */ || ch === 0x3F/* ? */) {
// Directive start / comment start / processing instruction start
if (silent) { return true; }
} else if (ch === 0x2F/* / */ || isLetter(ch)) {
// Probably start or end of tag
if (ch === 0x2F/* \ */) {
// closing tag
match = state.src.slice(pos, max).match(HTML_TAG_CLOSE_RE);
if (!match) { return false; }
} else {
// opening tag
match = state.src.slice(pos, max).match(HTML_TAG_OPEN_RE);
if (!match) { return false; }
}
// Make sure tag name is valid
if (block_names[match[1].toLowerCase()] !== true) { return false; }
if (silent) { return true; }
} else {
return false;
}
// If we are here - we detected HTML block.
// Let's roll down till empty line (block end).
nextLine = startLine + 1;
while (nextLine < state.lineMax && !state.isEmpty(nextLine)) {
nextLine++;
}
state.line = nextLine;
token = state.push('html_block', '', 0);
token.map = [ startLine, state.line ];
token.content = state.getLines(startLine, nextLine, 0, true);
return true;
};