Skip to content

Commit

Permalink
Remove rule option to not add an alignment row
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jan 23, 2020
1 parent cdc535a commit b021b7a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 46 deletions.
40 changes: 19 additions & 21 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,33 +174,31 @@ function markdownTable(table, options) {
rows[rowIndex] = cells.join(delimiter)
}

if (settings.rule !== false) {
index = -1
rule = []

while (++index < cellCount) {
// When `pad` is false, make the rule the same size as the first row.
if (settings.alignDelimiters === false) {
value = table[0][index]
spacing = calculateStringLength(stringify(value))
spacing = spacing > minCellSize ? spacing : minCellSize
} else {
spacing = sizes[index]
}
index = -1
rule = []

align = alignment[index]
while (++index < cellCount) {
// When `pad` is false, make the rule the same size as the first row.
if (settings.alignDelimiters === false) {
value = table[0][index]
spacing = calculateStringLength(stringify(value))
spacing = spacing > minCellSize ? spacing : minCellSize
} else {
spacing = sizes[index]
}

// When `align` is left, don't add colons.
value = align === lowercaseR || align === '' ? dash : colon
value += pad(spacing - 2, dash)
value += align !== lowercaseL && align !== '' ? colon : dash
align = alignment[index]

rule[index] = value
}
// When `align` is left, don't add colons.
value = align === lowercaseR || align === '' ? dash : colon
value += pad(spacing - 2, dash)
value += align !== lowercaseL && align !== '' ? colon : dash

rows.splice(1, 0, rule.join(delimiter))
rule[index] = value
}

rows.splice(1, 0, rule.join(delimiter))

return start + rows.join(end + lineFeed + start) + end
}

Expand Down
10 changes: 2 additions & 8 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ Turns a given matrix of strings (an array of arrays of strings) into a table.
One style for all columns, or styles for their respective columns (`string` or
`Array.<string>`).
Each style is either `'l'` (left), `'r'` (right), or `'c'` (center).
Other values are treated as `''`, which doesn’t place the colon but does align
left.
Other values are treated as `''`, which doesn’t place the colon in the alignment
row but does align left.
*Only the lowercased first character is used, so `Right` is fine.*

###### `options.delimiter`
Expand All @@ -94,12 +94,6 @@ Value to insert at the beginning of every row (`string`, default: `'| '`).

Value to insert at the end of every row (`string`, default: `' |'`).

###### `options.rule`

Whether to display a rule between the header and the body of the table
(`boolean`, default: `true`).
*Careful, setting this to `false` will break Markdown*.

###### `options.stringLength`

Method to detect the length of a cell (`Function`, default: `s => s.length`).
Expand Down
17 changes: 0 additions & 17 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,23 +229,6 @@ test('table()', function(t) {
'should create a table without ending border'
)

t.test(
table(
[
['Branch', 'Commit'],
['master', '0123456789abcdef'],
['staging', 'fedcba9876543210']
],
{rule: false}
),
[
'| Branch | Commit |',
'| master | 0123456789abcdef |',
'| staging | fedcba9876543210 |'
].join('\n'),
'should create a table without rule'
)

t.test(
strip(
table(
Expand Down

0 comments on commit b021b7a

Please sign in to comment.