From de78865c54f99d04706700b7b5caba0970194ceb Mon Sep 17 00:00:00 2001 From: 12rambau Date: Fri, 30 Apr 2021 13:33:35 +0200 Subject: [PATCH 1/6] feat: adapt to rst Adapt the indentation level of what's written to the initial indent of the opening tag. It should change nothing to markdown input. --- src/generate/index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/generate/index.js b/src/generate/index.js index cacc21e6..e80466cf 100644 --- a/src/generate/index.js +++ b/src/generate/index.js @@ -24,11 +24,13 @@ function injectListBetweenTags(newContent) { ) { return previousContent } + const startIndent = max(0, previousContent.LastIndexOf('\n', startOfOpeningTagIndex)) + const nbSpaces = startOfOpeningTagIndex - min(startOfOpeningTagIndex, startIndent) return [ previousContent.slice(0, endOfOpeningTagIndex + closingTag.length), '\n', '\n', - newContent, + newContent.replace('\n', '\n'+ ' '.repeat(nbSpaces)), '', '\n', '\n\n', @@ -84,10 +86,12 @@ function replaceBadge(newContent) { ) { return previousContent } + const startIndent = max(0, previousContent.LastIndexOf('\n', startOfOpeningTagIndex)) + const nbSpaces = startOfOpeningTagIndex - min(startOfOpeningTagIndex, startIndent) return [ previousContent.slice(0, endOfOpeningTagIndex + closingTag.length), '\n', - newContent, + newContent.replace('\n', '\n'+ ' '.repeat(nbSpaces)), '\n', previousContent.slice(startOfClosingTagIndex), ].join('') From 505264dd2b636e28c706a48ebe215853e3630de5 Mon Sep 17 00:00:00 2001 From: Rambaud Pierrick <12rambau@users.noreply.github.com> Date: Tue, 29 Jun 2021 11:54:55 +0200 Subject: [PATCH 2/6] use Math lib Co-authored-by: Maximilian Berkmann --- src/generate/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/generate/index.js b/src/generate/index.js index e80466cf..a4f2885c 100644 --- a/src/generate/index.js +++ b/src/generate/index.js @@ -24,8 +24,8 @@ function injectListBetweenTags(newContent) { ) { return previousContent } - const startIndent = max(0, previousContent.LastIndexOf('\n', startOfOpeningTagIndex)) - const nbSpaces = startOfOpeningTagIndex - min(startOfOpeningTagIndex, startIndent) + const startIndent = Math.max(0, previousContent.lastIndexOf('\n', startOfOpeningTagIndex)) + const nbSpaces = startOfOpeningTagIndex - Math.min(startOfOpeningTagIndex, startIndent) return [ previousContent.slice(0, endOfOpeningTagIndex + closingTag.length), '\n', From f1744907874c3a5e8a4a41f27cee7b49e866e808 Mon Sep 17 00:00:00 2001 From: Rambaud Pierrick <12rambau@users.noreply.github.com> Date: Tue, 29 Jun 2021 11:55:43 +0200 Subject: [PATCH 3/6] formatting Co-authored-by: Maximilian Berkmann --- src/generate/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/generate/index.js b/src/generate/index.js index a4f2885c..e52f0883 100644 --- a/src/generate/index.js +++ b/src/generate/index.js @@ -30,7 +30,7 @@ function injectListBetweenTags(newContent) { previousContent.slice(0, endOfOpeningTagIndex + closingTag.length), '\n', '\n', - newContent.replace('\n', '\n'+ ' '.repeat(nbSpaces)), + newContent.replace('\n', '\n' + ' '.repeat(nbSpaces)), '', '\n', '\n\n', From 34aa681a8898ead2531317df803c85f0ec54b160 Mon Sep 17 00:00:00 2001 From: Rambaud Pierrick <12rambau@users.noreply.github.com> Date: Tue, 29 Jun 2021 11:56:57 +0200 Subject: [PATCH 4/6] use Math lib Co-authored-by: Maximilian Berkmann --- src/generate/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/generate/index.js b/src/generate/index.js index e52f0883..bf044ae2 100644 --- a/src/generate/index.js +++ b/src/generate/index.js @@ -86,8 +86,8 @@ function replaceBadge(newContent) { ) { return previousContent } - const startIndent = max(0, previousContent.LastIndexOf('\n', startOfOpeningTagIndex)) - const nbSpaces = startOfOpeningTagIndex - min(startOfOpeningTagIndex, startIndent) + const startIndent = Math.max(0, previousContent.lastIndexOf('\n', startOfOpeningTagIndex)) + const nbSpaces = startOfOpeningTagIndex - Math.min(startOfOpeningTagIndex, startIndent) return [ previousContent.slice(0, endOfOpeningTagIndex + closingTag.length), '\n', From 6d50b76e8edc8b9f15130c3266d9e54f91727a7e Mon Sep 17 00:00:00 2001 From: Rambaud Pierrick <12rambau@users.noreply.github.com> Date: Tue, 29 Jun 2021 11:57:09 +0200 Subject: [PATCH 5/6] formatting Co-authored-by: Maximilian Berkmann --- src/generate/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/generate/index.js b/src/generate/index.js index bf044ae2..e1abedd2 100644 --- a/src/generate/index.js +++ b/src/generate/index.js @@ -91,7 +91,7 @@ function replaceBadge(newContent) { return [ previousContent.slice(0, endOfOpeningTagIndex + closingTag.length), '\n', - newContent.replace('\n', '\n'+ ' '.repeat(nbSpaces)), + newContent.replace('\n', '\n' + ' '.repeat(nbSpaces)), '\n', previousContent.slice(startOfClosingTagIndex), ].join('') From ddaeabf84823b3b851347d8dc03694680895629d Mon Sep 17 00:00:00 2001 From: Angel Aviel Domaoan <13580338+tenshiAMD@users.noreply.github.com> Date: Tue, 27 Sep 2022 22:52:12 +0800 Subject: [PATCH 6/6] fix: lint and failing tests --- src/generate/index.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/generate/index.js b/src/generate/index.js index a616faac..1f14e1e1 100644 --- a/src/generate/index.js +++ b/src/generate/index.js @@ -24,13 +24,17 @@ function injectListBetweenTags(newContent) { ) { return previousContent } - const startIndent = Math.max(0, previousContent.lastIndexOf('\n', startOfOpeningTagIndex)) - const nbSpaces = startOfOpeningTagIndex - Math.min(startOfOpeningTagIndex, startIndent) + 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.replace('\n', '\n' + ' '.repeat(nbSpaces)), + newContent.replace('\n', `\n${' '.repeat(nbSpaces - 1)}`), '', '\n', '\n\n', @@ -87,12 +91,16 @@ function replaceBadge(newContent) { ) { return previousContent } - const startIndent = Math.max(0, previousContent.lastIndexOf('\n', startOfOpeningTagIndex)) - const nbSpaces = startOfOpeningTagIndex - Math.min(startOfOpeningTagIndex, startIndent) + 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.replace('\n', '\n' + ' '.repeat(nbSpaces)), + newContent.replace('\n', `\n${' '.repeat(nbSpaces)}`), '\n', previousContent.slice(startOfClosingTagIndex), ].join('')