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