Skip to content

Commit 554667b

Browse files
authoredOct 10, 2022
feat: Add width and valign attributes for cleaner <td> (#344)
1 parent fb8f89f commit 554667b

File tree

3 files changed

+76
-27
lines changed

3 files changed

+76
-27
lines changed
 

‎src/generate/__tests__/__snapshots__/index.js.snap

+51-23
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ These people contributed to the project:
1313
<table>
1414
<tbody>
1515
<tr>
16-
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
17-
<td align=\\"center\\">Divjot Singh is awesome!</td>
18-
<td align=\\"center\\">Jeroen Engels is awesome!</td>
16+
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Kent C. Dodds is awesome!</td>
17+
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Divjot Singh is awesome!</td>
18+
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Jeroen Engels is awesome!</td>
1919
</tr>
2020
</tbody>
2121
</table>
@@ -41,9 +41,9 @@ These people contributed to the project:
4141
<table>
4242
<tbody>
4343
<tr>
44-
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
45-
<td align=\\"center\\">Divjot Singh is awesome!</td>
46-
<td align=\\"center\\">Jeroen Engels is awesome!</td>
44+
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Kent C. Dodds is awesome!</td>
45+
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Divjot Singh is awesome!</td>
46+
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Jeroen Engels is awesome!</td>
4747
</tr>
4848
</tbody>
4949
<tfoot>
@@ -78,9 +78,9 @@ These people contributed to the project:
7878
<table>
7979
<tbody>
8080
<tr>
81-
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
82-
<td align=\\"center\\">Divjot Singh is awesome!</td>
83-
<td align=\\"center\\">Jeroen Engels is awesome!</td>
81+
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Kent C. Dodds is awesome!</td>
82+
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Divjot Singh is awesome!</td>
83+
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Jeroen Engels is awesome!</td>
8484
</tr>
8585
</tbody>
8686
</table>
@@ -106,15 +106,15 @@ These people contributed to the project:
106106
<table>
107107
<tbody>
108108
<tr>
109-
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
110-
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
111-
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
112-
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
113-
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
109+
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Kent C. Dodds is awesome!</td>
110+
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Kent C. Dodds is awesome!</td>
111+
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Kent C. Dodds is awesome!</td>
112+
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Kent C. Dodds is awesome!</td>
113+
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Kent C. Dodds is awesome!</td>
114114
</tr>
115115
<tr>
116-
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
117-
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
116+
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Kent C. Dodds is awesome!</td>
117+
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Kent C. Dodds is awesome!</td>
118118
</tr>
119119
</tbody>
120120
</table>
@@ -140,15 +140,15 @@ These people contributed to the project:
140140
<table>
141141
<tbody>
142142
<tr>
143-
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
144-
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
145-
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
146-
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
147-
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
143+
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Kent C. Dodds is awesome!</td>
144+
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Kent C. Dodds is awesome!</td>
145+
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Kent C. Dodds is awesome!</td>
146+
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Kent C. Dodds is awesome!</td>
147+
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Kent C. Dodds is awesome!</td>
148148
</tr>
149149
<tr>
150-
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
151-
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
150+
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Kent C. Dodds is awesome!</td>
151+
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Kent C. Dodds is awesome!</td>
152152
</tr>
153153
</tbody>
154154
<tfoot>
@@ -169,3 +169,31 @@ These people contributed to the project:
169169
170170
Thanks a lot everyone!"
171171
`;
172+
173+
exports[`validate if cell width attribute is floored correctly 1`] = `
174+
"# project
175+
176+
Description
177+
178+
## Contributors
179+
These people contributed to the project:
180+
<!-- ALL-CONTRIBUTORS-LIST:START -->
181+
<!-- prettier-ignore-start -->
182+
<!-- markdownlint-disable -->
183+
<table>
184+
<tbody>
185+
<tr>
186+
<td align=\\"center\\" valign=\\"top\\" width=\\"14.28%\\">Kent C. Dodds is awesome!</td>
187+
<td align=\\"center\\" valign=\\"top\\" width=\\"14.28%\\">Kent C. Dodds is awesome!</td>
188+
<td align=\\"center\\" valign=\\"top\\" width=\\"14.28%\\">Kent C. Dodds is awesome!</td>
189+
</tr>
190+
</tbody>
191+
</table>
192+
193+
<!-- markdownlint-restore -->
194+
<!-- prettier-ignore-end -->
195+
196+
<!-- ALL-CONTRIBUTORS-LIST:END -->
197+
198+
Thanks a lot everyone!"
199+
`;

‎src/generate/__tests__/index.js

+15
Original file line numberDiff line numberDiff line change
@@ -238,3 +238,18 @@ test('replace all-contributors badge if present', () => {
238238

239239
expect(result).toBe(expected)
240240
})
241+
242+
test('validate if cell width attribute is floored correctly', () => {
243+
const {kentcdodds} = contributors
244+
const {options, content} = fixtures()
245+
const contributorList = [
246+
kentcdodds,
247+
kentcdodds,
248+
kentcdodds,
249+
]
250+
251+
options.contributorsPerLine = 7
252+
const result = generate(options, contributorList, content)
253+
254+
expect(result).toMatchSnapshot()
255+
})

‎src/generate/index.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const _ = require('lodash/fp')
2+
const floor = require('lodash/floor')
23
const formatBadge = require('./format-badge')
34
const formatContributor = require('./format-contributor')
45

@@ -43,9 +44,12 @@ function injectListBetweenTags(newContent) {
4344
}
4445
}
4546

46-
function formatLine(contributors) {
47-
return `<td align="center">${contributors.join(
48-
'</td>\n <td align="center">',
47+
function formatLine(options, contributors) {
48+
const width = floor(_.divide(100)(options.contributorsPerLine), 2)
49+
const attributes = `align="center" valign="top" width="${width}%"`
50+
51+
return `<td ${attributes}>${contributors.join(
52+
`</td>\n <td ${attributes}>`,
4953
)}</td>`
5054
}
5155

@@ -74,7 +78,9 @@ function generateContributorsList(options, contributors) {
7478
return formatContributor(options, contributor)
7579
}),
7680
_.chunk(options.contributorsPerLine),
77-
_.map(formatLine),
81+
_.map((currentLineContributors) => formatLine(
82+
options, currentLineContributors
83+
)),
7884
_.join('\n </tr>\n <tr>\n '),
7985
newContent => {
8086
if (options.linkToUsage) {

0 commit comments

Comments
 (0)
Please sign in to comment.