From 7a9150fa526e4776b7e76fd9931e717eea1df843 Mon Sep 17 00:00:00 2001 From: Rambaud Pierrick <12rambau@users.noreply.github.com> Date: Tue, 27 Sep 2022 19:07:15 +0200 Subject: [PATCH] feat: adapt to rst (#301) Co-authored-by: Maximilian Berkmann Co-authored-by: Angel Aviel Domaoan <13580338+tenshiAMD@users.noreply.github.com> --- src/generate/index.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) 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('')