|
|
@ -55,7 +55,7 @@ function escapedSplit(str) { |
|
|
|
|
|
|
|
module.exports = function table(state, startLine, endLine, silent) { |
|
|
|
var ch, lineText, pos, i, nextLine, columns, columnCount, token, |
|
|
|
aligns, t, tableLines, tbodyLines; |
|
|
|
aligns, t, tableLines, tbodyLines, columnVIndex; |
|
|
|
|
|
|
|
// should have at least three lines
|
|
|
|
if (startLine + 2 > endLine) { return false; } |
|
|
@ -110,18 +110,30 @@ module.exports = function table(state, startLine, endLine, silent) { |
|
|
|
|
|
|
|
if (silent) { return true; } |
|
|
|
|
|
|
|
token = state.push('table_open', 'table', 1); |
|
|
|
token.map = tableLines = [ startLine, 0 ]; |
|
|
|
token = state.push('table_open', 'table', 1); |
|
|
|
token.map = tableLines = [ startLine, 0 ]; |
|
|
|
token.size = 0; |
|
|
|
token.position = state.bMarks[startLine]; |
|
|
|
|
|
|
|
token = state.push('thead_open', 'thead', 1); |
|
|
|
token.map = [ startLine, startLine + 1 ]; |
|
|
|
|
|
|
|
token = state.push('tr_open', 'tr', 1); |
|
|
|
token.map = [ startLine, startLine + 1 ]; |
|
|
|
token = state.push('thead_open', 'thead', 1); |
|
|
|
token.map = [ startLine, startLine + 1 ]; |
|
|
|
token.size = 0; |
|
|
|
token.position = state.bMarks[startLine]; |
|
|
|
|
|
|
|
token = state.push('tr_open', 'tr', 1); |
|
|
|
token.map = [ startLine, startLine + 1 ]; |
|
|
|
token.size = 0; |
|
|
|
token.position = state.bMarks[startLine]; |
|
|
|
|
|
|
|
columnVIndex = state.bMarks[startLine] + state.tShift[startLine]; |
|
|
|
for (i = 0; i < columns.length; i++) { |
|
|
|
token = state.push('th_open', 'th', 1); |
|
|
|
token.map = [ startLine, startLine + 1 ]; |
|
|
|
token.size = 1; |
|
|
|
token.position = columnVIndex; |
|
|
|
columnVIndex = columnVIndex + 1; |
|
|
|
|
|
|
|
if (aligns[i]) { |
|
|
|
token.attrs = [ [ 'style', 'text-align:' + aligns[i] ] ]; |
|
|
|
} |
|
|
@ -130,15 +142,33 @@ module.exports = function table(state, startLine, endLine, silent) { |
|
|
|
token.content = columns[i].trim(); |
|
|
|
token.map = [ startLine, startLine + 1 ]; |
|
|
|
token.children = []; |
|
|
|
token.position = columnVIndex; |
|
|
|
token.size = columns[i].length; |
|
|
|
columnVIndex = columnVIndex + columns[i].length; |
|
|
|
|
|
|
|
token = state.push('th_close', 'th', -1); |
|
|
|
token.position = columnVIndex; |
|
|
|
|
|
|
|
// Last column?
|
|
|
|
if (i === (columns.length - 1)) { |
|
|
|
token.size = 1; |
|
|
|
columnVIndex = columnVIndex + 1; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
token = state.push('tr_close', 'tr', -1); |
|
|
|
token = state.push('thead_close', 'thead', -1); |
|
|
|
token = state.push('tr_close', 'tr', -1); |
|
|
|
token.size = 0; |
|
|
|
token.position = state.eMarks[startLine]; |
|
|
|
|
|
|
|
token = state.push('thead_close', 'thead', -1); |
|
|
|
token.size = state.eMarks[startLine + 1] - state.bMarks[startLine + 1]; |
|
|
|
token.position = state.bMarks[startLine + 1]; |
|
|
|
|
|
|
|
token = state.push('tbody_open', 'tbody', 1); |
|
|
|
token.map = tbodyLines = [ startLine + 2, 0 ]; |
|
|
|
token.size = 0; |
|
|
|
token.position = state.bMarks[startLine + 2]; |
|
|
|
|
|
|
|
for (nextLine = startLine + 2; nextLine < endLine; nextLine++) { |
|
|
|
if (state.sCount[nextLine] < state.blkIndent) { break; } |
|
|
@ -148,8 +178,16 @@ module.exports = function table(state, startLine, endLine, silent) { |
|
|
|
columns = escapedSplit(lineText.replace(/^\||\|$/g, '')); |
|
|
|
|
|
|
|
token = state.push('tr_open', 'tr', 1); |
|
|
|
token.size = 0; |
|
|
|
token.position = state.bMarks[nextLine]; |
|
|
|
|
|
|
|
columnVIndex = state.bMarks[nextLine] + state.tShift[nextLine]; |
|
|
|
for (i = 0; i < columnCount; i++) { |
|
|
|
token = state.push('td_open', 'td', 1); |
|
|
|
token.size = 1; |
|
|
|
token.position = columnVIndex; |
|
|
|
columnVIndex++; |
|
|
|
|
|
|
|
if (aligns[i]) { |
|
|
|
token.attrs = [ [ 'style', 'text-align:' + aligns[i] ] ]; |
|
|
|
} |
|
|
@ -157,13 +195,30 @@ module.exports = function table(state, startLine, endLine, silent) { |
|
|
|
token = state.push('inline', '', 0); |
|
|
|
token.content = columns[i] ? columns[i].trim() : ''; |
|
|
|
token.children = []; |
|
|
|
token.size = (columns[i] || '').length; |
|
|
|
token.position = columnVIndex; |
|
|
|
columnVIndex += token.size; |
|
|
|
|
|
|
|
token = state.push('td_close', 'td', -1); |
|
|
|
token.position = columnVIndex; |
|
|
|
|
|
|
|
// Last column?
|
|
|
|
if (i === (columns.length - 1)) { |
|
|
|
token.size = 1; |
|
|
|
} |
|
|
|
} |
|
|
|
token = state.push('tr_close', 'tr', -1); |
|
|
|
token.size = 0; |
|
|
|
token.position = state.eMarks[nextLine]; |
|
|
|
} |
|
|
|
|
|
|
|
token = state.push('tbody_close', 'tbody', -1); |
|
|
|
token.size = 0; |
|
|
|
token.position = state.eMarks[nextLine]; |
|
|
|
|
|
|
|
token = state.push('table_close', 'table', -1); |
|
|
|
token.size = 0; |
|
|
|
token.position = state.eMarks[nextLine]; |
|
|
|
|
|
|
|
tableLines[1] = tbodyLines[1] = nextLine; |
|
|
|
state.line = nextLine; |
|
|
|