diff --git a/src/generate/__tests__/index.js b/src/generate/__tests__/index.js
index 8b247f9a..33a06c87 100644
--- a/src/generate/__tests__/index.js
+++ b/src/generate/__tests__/index.js
@@ -277,3 +277,20 @@ test('validate if cell width attribute is floored correctly', () => {
expect(result).toMatchSnapshot()
})
+
+test('inject the table when the ALL-CONTRIBUTORS-LIST tag starts the file', () => {
+ const {kentcdodds, bogas04} = contributors
+ const {options} = fixtures()
+ const contributorList = [kentcdodds, bogas04]
+ const content = [
+ 'FOO BAR BAZ',
+ '',
+ 'Thanks a lot everyone!',
+ ].join('\n')
+
+ const result = generate(options, contributorList, content)
+
+ expect(result).toContain('
')
+ expect(result).toContain('')
+ expect(result).not.toContain('FOO BAR BAZ')
+})
diff --git a/src/generate/index.js b/src/generate/index.js
index 07ad73f7..7f4e2c73 100644
--- a/src/generate/index.js
+++ b/src/generate/index.js
@@ -36,13 +36,17 @@ function injectListBetweenTags(newContent) {
0,
previousContent.lastIndexOf('\n', startOfOpeningTagIndex),
)
- const nbSpaces =
- startOfOpeningTagIndex - Math.min(startOfOpeningTagIndex, startIndent)
+ const nbSpaces = Math.max(
+ 0,
+ startOfOpeningTagIndex -
+ Math.min(startOfOpeningTagIndex, startIndent) -
+ 1,
+ )
return [
previousContent.slice(0, endOfOpeningTagIndex + closingTag.length),
'\n',
'\n',
- newContent.replace('\n', `\n${' '.repeat(nbSpaces - 1)}`),
+ newContent.replace('\n', `\n${' '.repeat(nbSpaces)}`),
'',
'\n',
'\n\n',