|
|
@ -1,9 +1,7 @@ |
|
|
|
// Parse backticks
|
|
|
|
|
|
|
|
var END_RE = /`+/g; |
|
|
|
|
|
|
|
module.exports = function backticks(state) { |
|
|
|
var start, code, max, marker, match, |
|
|
|
var start, max, marker, matchStart, matchEnd, |
|
|
|
pos = state.pos, |
|
|
|
ch = state.src.charCodeAt(pos); |
|
|
|
|
|
|
@ -17,22 +15,23 @@ module.exports = function backticks(state) { |
|
|
|
|
|
|
|
marker = state.src.slice(start, pos); |
|
|
|
|
|
|
|
END_RE = /`+/g; |
|
|
|
END_RE.lastIndex = pos; |
|
|
|
matchStart = matchEnd = pos; |
|
|
|
|
|
|
|
while ((matchStart = state.src.indexOf('`', matchEnd)) !== -1) { |
|
|
|
matchEnd = matchStart + 1; |
|
|
|
|
|
|
|
while ((match = END_RE.exec(state.src)) !== null) { |
|
|
|
if (match[0].length === marker.length) { |
|
|
|
code = state.src.slice(pos, END_RE.lastIndex - marker.length); |
|
|
|
while (matchEnd < max && state.src.charCodeAt(matchEnd) === 0x60/* ` */) { matchEnd++; } |
|
|
|
|
|
|
|
if (matchEnd - matchStart === marker.length) { |
|
|
|
state.push({ |
|
|
|
type: 'code', |
|
|
|
content: code |
|
|
|
.replace(/[ \n]+/g,' ') |
|
|
|
.trim(), |
|
|
|
content: state.src.slice(pos, matchStart) |
|
|
|
.replace(/[ \n]+/g,' ') |
|
|
|
.trim(), |
|
|
|
block: false, |
|
|
|
level: state.level |
|
|
|
}); |
|
|
|
|
|
|
|
state.pos += marker.length * 2 + code.length; |
|
|
|
state.pos = matchEnd; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|