From 614f97e0729e794b825488f67d3ced917a63f768 Mon Sep 17 00:00:00 2001 From: Sean Lang Date: Mon, 23 Mar 2015 15:46:01 -0400 Subject: [PATCH] fix issue with tables that have missing values and add test --- lib/index.coffee | 10 +++++++--- test/index.coffee | 13 +++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/index.coffee b/lib/index.coffee index 6f1b782..173e1ea 100644 --- a/lib/index.coffee +++ b/lib/index.coffee @@ -218,9 +218,13 @@ formatTable = (token) -> for i in [0...token.header.length] col = [token.header[i]] for j in [0...token.cells.length] - # https://github.com/chjj/marked/issues/473 - token.cells[j][i] = token.cells[j][i].trim() - + token.cells[j][i] = ( + if token.cells[j][i]? + # https://github.com/chjj/marked/issues/473 + token.cells[j][i].trim() + else + '' + ) col.push token.cells[j][i] colWidth = longestStringInArray(col) diff --git a/test/index.coffee b/test/index.coffee index c37f8af..9a7d7c2 100644 --- a/test/index.coffee +++ b/test/index.coffee @@ -255,6 +255,19 @@ describe 'tables', -> ''') + it 'should handle tables with missing values', -> + tidyMd(''' + Name | Type | Description | Choices + -----| ------| -------------| ------- + creator_license_id | unknown | License which... + + ''').should.equal(''' + Name | Type | Description | Choices + ------------------ | ------- | ---------------- | ------- + creator_license_id | unknown | License which... | + + ''') + it 'should support single column tables & not make trailing whitespace', -> tidyMd(''' | Group