diff --git a/shared/naturalcrit/markdown.js b/shared/naturalcrit/markdown.js index 3a341f379..438f68b37 100644 --- a/shared/naturalcrit/markdown.js +++ b/shared/naturalcrit/markdown.js @@ -284,16 +284,18 @@ const spanTable = { } } + let prevRow; + // Get any remaining header rows l = item.header.length; for (i = 1; i < l; i++) { - item.header[i] = splitCells(item.header[i], colCount); + item.header[i] = splitCells(item.header[i], colCount, item.header[i-1]); } // Get main table cells l = item.rows.length; for (i = 0; i < l; i++) { - item.rows[i] = splitCells(item.rows[i], colCount); + item.rows[i] = splitCells(item.rows[i], colCount, item.rows[i-1]); } // header child tokens @@ -330,7 +332,7 @@ const spanTable = { for (j = 0; j < row.length; j++) { cell = row[j]; text = this.parseInline(cell.tokens); - output += getTableCell(text, cell.colspan, 'th', token.align[col]); + output += getTableCell(text, cell.colspan, cell.rowspan, 'th', token.align[col]); col += cell.colspan; } output += ``; @@ -345,7 +347,7 @@ const spanTable = { for (j = 0; j < row.length; j++) { cell = row[j]; text = this.parseInline(cell.tokens); - output += getTableCell(text, cell.colspan, 'td', token.align[col]); + output += getTableCell(text, cell.colspan, cell.rowspan, 'td', token.align[col]); col += cell.colspan; } output += ``; @@ -357,14 +359,18 @@ const spanTable = { } }; -const getTableCell = (text, colspan, type, align)=>{ +const getTableCell = (text, colspan, rowspan, type, align)=>{ + if(!rowspan) { + return ''; + } const tag = `<${type}` + `${colspan > 1 ? ` colspan=${colspan}` : ''}` + + `${rowspan > 1 ? ` rowspan=${rowspan}` : ''}` + `${align ? ` align=${align}` : ''}>`; return `${tag + text}\n`; }; -const splitCells = (tableRow, count)=>{ +const splitCells = (tableRow, count, prevRow = [])=>{ // ensure that every cell-delimiting pipe has a space // before it to distinguish it from an escaped pipe const row = tableRow.replace(/(\|+)/g, (match, p1, offset, str)=>{ @@ -391,12 +397,34 @@ const splitCells = (tableRow, count)=>{ let numCols = 0; for (; i < cells.length; i++) { - const trimmedCell = cells[i].split(/(? numCols) + break; + } + } + numCols += cells[i].colspan; }