Skip to content

Commit

Permalink
fix issue with tables that have missing values
Browse files Browse the repository at this point in the history
and add test
  • Loading branch information
notslang committed Mar 23, 2015
1 parent 25c1aa8 commit 614f97e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions test/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 614f97e

Please sign in to comment.