|
|
@ -13,7 +13,7 @@ function lineMatch(state, line, reg) { |
|
|
|
|
|
|
|
module.exports = function table(state, startLine, endLine, silent) { |
|
|
|
var ch, firstLineMatch, secondLineMatch, pos, i, nextLine, m, rows, |
|
|
|
aligns, t; |
|
|
|
aligns, t, tableLines, tbodyLines; |
|
|
|
|
|
|
|
// should have at least three lines
|
|
|
|
if (startLine + 2 > endLine) { return false; } |
|
|
@ -54,15 +54,33 @@ module.exports = function table(state, startLine, endLine, silent) { |
|
|
|
if (aligns.length !== rows.length) { return false; } |
|
|
|
if (silent) { return true; } |
|
|
|
|
|
|
|
state.tokens.push({ type: 'table_open', level: state.level++ }); |
|
|
|
state.tokens.push({ type: 'thead_open', level: state.level++ }); |
|
|
|
state.tokens.push({ |
|
|
|
type: 'table_open', |
|
|
|
lines: tableLines = [ startLine, 0 ], |
|
|
|
level: state.level++ |
|
|
|
}); |
|
|
|
state.tokens.push({ |
|
|
|
type: 'thead_open', |
|
|
|
lines: [ startLine, startLine + 1 ], |
|
|
|
level: state.level++ |
|
|
|
}); |
|
|
|
|
|
|
|
state.tokens.push({ type: 'tr_open', level: state.level++ }); |
|
|
|
state.tokens.push({ |
|
|
|
type: 'tr_open', |
|
|
|
lines: [ startLine, startLine + 1 ], |
|
|
|
level: state.level++ |
|
|
|
}); |
|
|
|
for (i = 0; i < rows.length; i++) { |
|
|
|
state.tokens.push({ type: 'th_open', align: aligns[i], level: state.level++ }); |
|
|
|
state.tokens.push({ |
|
|
|
type: 'th_open', |
|
|
|
align: aligns[i], |
|
|
|
lines: [ startLine, startLine + 1 ], |
|
|
|
level: state.level++ |
|
|
|
}); |
|
|
|
state.tokens.push({ |
|
|
|
type: 'inline', |
|
|
|
content: rows[i].trim(), |
|
|
|
lines: [ startLine, startLine + 1 ], |
|
|
|
level: state.level, |
|
|
|
children: [] |
|
|
|
}); |
|
|
@ -70,7 +88,12 @@ module.exports = function table(state, startLine, endLine, silent) { |
|
|
|
} |
|
|
|
state.tokens.push({ type: 'tr_close', level: --state.level }); |
|
|
|
state.tokens.push({ type: 'thead_close', level: --state.level }); |
|
|
|
state.tokens.push({ type: 'tbody_open', level: state.level++ }); |
|
|
|
|
|
|
|
state.tokens.push({ |
|
|
|
type: 'tbody_open', |
|
|
|
lines: tbodyLines = [ startLine + 2, 0 ], |
|
|
|
level: state.level++ |
|
|
|
}); |
|
|
|
|
|
|
|
for (nextLine = startLine + 2; nextLine < endLine; nextLine++) { |
|
|
|
if (state.tShift[nextLine] < state.blkIndent) { break; } |
|
|
@ -95,6 +118,7 @@ module.exports = function table(state, startLine, endLine, silent) { |
|
|
|
state.tokens.push({ type: 'tbody_close', level: --state.level }); |
|
|
|
state.tokens.push({ type: 'table_close', level: --state.level }); |
|
|
|
|
|
|
|
tableLines[1] = tbodyLines[1] = nextLine; |
|
|
|
state.line = nextLine; |
|
|
|
return true; |
|
|
|
}; |
|
|
|