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.
 
 
 

42 lines
931 B

// Parse backticks
var END_RE = /`+/g;
module.exports = function backticks(state) {
var start, code, max, marker, match,
pos = state.pos,
ch = state.src.charCodeAt(pos);
if (ch !== 0x60/* ` */) { return false; }
start = pos;
pos++;
max = state.posMax;
while (pos < max && state.src.charCodeAt(pos) === 0x60/* ` */) { pos++; }
marker = state.src.slice(start, pos);
END_RE = /`+/g;
END_RE.lastIndex = pos;
while ((match = END_RE.exec(state.src)) !== null) {
if (match[0].length === marker.length) {
code = state.src.slice(pos, END_RE.lastIndex - marker.length);
state.push({
type: 'code',
content: code
.replace(/[ \n]+/g,' ')
.trim(),
block: false
});
state.pos += marker.length * 2 + code.length;
return true;
}
}
state.pending += marker;
state.pos += marker.length;
return true;
};