|
|
@ -3,11 +3,13 @@ |
|
|
|
'use strict'; |
|
|
|
|
|
|
|
|
|
|
|
var skipEmptyLines = require('../helpers').skipEmptyLines; |
|
|
|
var skipEmptyLines = require('../helpers').skipEmptyLines; |
|
|
|
var skipSpaces = require('../helpers').skipSpaces; |
|
|
|
var skipChars = require('../helpers').skipChars; |
|
|
|
|
|
|
|
|
|
|
|
module.exports =function fences(state, startLine, endLine, silent) { |
|
|
|
var marker, len, params, nextLine, |
|
|
|
var marker, len, params, nextLine, mem, |
|
|
|
pos = state.bMarks[startLine] + state.tShift[startLine], |
|
|
|
max = state.eMarks[startLine]; |
|
|
|
|
|
|
@ -20,43 +22,41 @@ module.exports =function fences(state, startLine, endLine, silent) { |
|
|
|
} |
|
|
|
|
|
|
|
// scan marker length
|
|
|
|
len = 1; |
|
|
|
while (state.src.charCodeAt(++pos) === marker) { |
|
|
|
len++; |
|
|
|
} |
|
|
|
mem = pos; |
|
|
|
pos = skipChars(state, pos, marker); |
|
|
|
|
|
|
|
len = pos - mem; |
|
|
|
|
|
|
|
if (len < 3) { return false; } |
|
|
|
|
|
|
|
params = state.src.slice(pos, max).trim(); |
|
|
|
|
|
|
|
if (!/\S/.test(params)) { return false; } |
|
|
|
|
|
|
|
// search end of block
|
|
|
|
nextLine = startLine; |
|
|
|
|
|
|
|
do { |
|
|
|
nextLine++; |
|
|
|
|
|
|
|
if (nextLine > endLine) { return false; } |
|
|
|
if (nextLine >= endLine) { |
|
|
|
// unclosed block should be autoclosed by end of document.
|
|
|
|
if (state.blkLevel === 0) { |
|
|
|
break; |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
pos = state.bMarks[nextLine] + state.tShift[nextLine]; |
|
|
|
pos = mem = state.bMarks[nextLine] + state.tShift[nextLine]; |
|
|
|
max = state.eMarks[nextLine]; |
|
|
|
|
|
|
|
if (pos + 3 > max) { continue; } |
|
|
|
if (state.src.charCodeAt(pos) !== marker) { continue; } |
|
|
|
|
|
|
|
// check markers
|
|
|
|
if (state.src.charCodeAt(pos) !== marker && |
|
|
|
state.src.charCodeAt(pos + 1) !== marker && |
|
|
|
state.src.charCodeAt(pos + 2) !== marker) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
pos = skipChars(state, pos, marker); |
|
|
|
|
|
|
|
pos += 3; |
|
|
|
// closing code fence must be at least as long as the opening one
|
|
|
|
if (pos - mem < len) { continue; } |
|
|
|
|
|
|
|
// make sure tail has spaces only
|
|
|
|
//pos = pos < max ? skipSpaces(state, pos) : pos;
|
|
|
|
|
|
|
|
// stmd allow any combonation of markers and spaces in tail
|
|
|
|
pos = skipSpaces(state, pos); |
|
|
|
|
|
|
|
if (pos < max) { continue; } |
|
|
|
|
|
|
@ -69,7 +69,7 @@ module.exports =function fences(state, startLine, endLine, silent) { |
|
|
|
|
|
|
|
state.tokens.push({ |
|
|
|
type: 'fence', |
|
|
|
params: params.split(/\s+/g), |
|
|
|
params: params ? params.split(/\s+/g) : [], |
|
|
|
startLine: startLine + 1, |
|
|
|
endLine: nextLine |
|
|
|
}); |
|
|
|