|
|
@ -10,6 +10,34 @@ function getLine(state, line) { |
|
|
|
return state.src.substr(pos, max - pos); |
|
|
|
} |
|
|
|
|
|
|
|
function escapedSplit(str) { |
|
|
|
var result = [], |
|
|
|
pos = 0, |
|
|
|
max = str.length, |
|
|
|
ch, |
|
|
|
escapes = 0, |
|
|
|
lastPos = 0; |
|
|
|
|
|
|
|
ch = str.charCodeAt(pos); |
|
|
|
|
|
|
|
while (pos < max) { |
|
|
|
if (ch === 0x7c/* | */ && (escapes % 2 === 0)) { |
|
|
|
result.push(str.substring(lastPos, pos)); |
|
|
|
lastPos = pos + 1; |
|
|
|
} else if (ch === 0x5c/* \ */) { |
|
|
|
escapes++; |
|
|
|
} else { |
|
|
|
escapes = 0; |
|
|
|
} |
|
|
|
|
|
|
|
ch = str.charCodeAt(++pos); |
|
|
|
} |
|
|
|
|
|
|
|
result.push(str.substring(lastPos)); |
|
|
|
|
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
module.exports = function table(state, startLine, endLine, silent) { |
|
|
|
var ch, lineText, pos, i, nextLine, rows, |
|
|
@ -60,7 +88,7 @@ module.exports = function table(state, startLine, endLine, silent) { |
|
|
|
|
|
|
|
lineText = getLine(state, startLine).trim(); |
|
|
|
if (lineText.indexOf('|') === -1) { return false; } |
|
|
|
rows = lineText.replace(/^\||\|$/g, '').split('|'); |
|
|
|
rows = escapedSplit(lineText.replace(/^\||\|$/g, '')); |
|
|
|
if (aligns.length !== rows.length) { return false; } |
|
|
|
if (silent) { return true; } |
|
|
|
|
|
|
@ -110,14 +138,14 @@ module.exports = function table(state, startLine, endLine, silent) { |
|
|
|
|
|
|
|
lineText = getLine(state, nextLine).trim(); |
|
|
|
if (lineText.indexOf('|') === -1) { break; } |
|
|
|
rows = lineText.replace(/^\||\|$/g, '').split('|'); |
|
|
|
rows = escapedSplit(lineText.replace(/^\||\|$/g, '')); |
|
|
|
|
|
|
|
state.tokens.push({ type: 'tr_open', level: state.level++ }); |
|
|
|
for (i = 0; i < rows.length; i++) { |
|
|
|
state.tokens.push({ type: 'td_open', align: aligns[i], level: state.level++ }); |
|
|
|
state.tokens.push({ |
|
|
|
type: 'inline', |
|
|
|
content: rows[i].replace(/^\|? *| *\|?$/g, ''), |
|
|
|
content: rows[i].trim(), |
|
|
|
level: state.level, |
|
|
|
children: [] |
|
|
|
}); |
|
|
|