diff --git a/src/generate/index.js b/src/generate/index.js index 9982829..1f14e1e 100644 --- a/src/generate/index.js +++ b/src/generate/index.js @@ -24,11 +24,17 @@ function injectListBetweenTags(newContent) { ) { return previousContent } + const startIndent = Math.max( + 0, + previousContent.lastIndexOf('\n', startOfOpeningTagIndex), + ) + const nbSpaces = + startOfOpeningTagIndex - Math.min(startOfOpeningTagIndex, startIndent) return [ previousContent.slice(0, endOfOpeningTagIndex + closingTag.length), '\n', '\n', - newContent, + newContent.replace('\n', `\n${' '.repeat(nbSpaces - 1)}`), '', '\n', '\n\n', @@ -85,10 +91,16 @@ function replaceBadge(newContent) { ) { return previousContent } + const startIndent = Math.max( + 0, + previousContent.lastIndexOf('\n', startOfOpeningTagIndex), + ) + const nbSpaces = + startOfOpeningTagIndex - Math.min(startOfOpeningTagIndex, startIndent) return [ previousContent.slice(0, endOfOpeningTagIndex + closingTag.length), '\n', - newContent, + newContent.replace('\n', `\n${' '.repeat(nbSpaces)}`), '\n', previousContent.slice(startOfClosingTagIndex), ].join('')