feat: adapt to rst (#301)

Co-authored-by: Maximilian Berkmann <maxieberkmann@gmail.com>
Co-authored-by: Angel Aviel Domaoan <13580338+tenshiAMD@users.noreply.github.com>
This commit is contained in:
Rambaud Pierrick 2022-09-27 19:07:15 +02:00 committed by GitHub
parent 8db67102cb
commit 7a9150fa52
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -24,11 +24,17 @@ function injectListBetweenTags(newContent) {
) { ) {
return previousContent return previousContent
} }
const startIndent = Math.max(
0,
previousContent.lastIndexOf('\n', startOfOpeningTagIndex),
)
const nbSpaces =
startOfOpeningTagIndex - Math.min(startOfOpeningTagIndex, startIndent)
return [ return [
previousContent.slice(0, endOfOpeningTagIndex + closingTag.length), previousContent.slice(0, endOfOpeningTagIndex + closingTag.length),
'\n<!-- prettier-ignore-start -->', '\n<!-- prettier-ignore-start -->',
'\n<!-- markdownlint-disable -->', '\n<!-- markdownlint-disable -->',
newContent, newContent.replace('\n', `\n${' '.repeat(nbSpaces - 1)}`),
'<!-- markdownlint-restore -->', '<!-- markdownlint-restore -->',
'\n<!-- prettier-ignore-end -->', '\n<!-- prettier-ignore-end -->',
'\n\n', '\n\n',
@ -85,10 +91,16 @@ function replaceBadge(newContent) {
) { ) {
return previousContent return previousContent
} }
const startIndent = Math.max(
0,
previousContent.lastIndexOf('\n', startOfOpeningTagIndex),
)
const nbSpaces =
startOfOpeningTagIndex - Math.min(startOfOpeningTagIndex, startIndent)
return [ return [
previousContent.slice(0, endOfOpeningTagIndex + closingTag.length), previousContent.slice(0, endOfOpeningTagIndex + closingTag.length),
'\n', '\n',
newContent, newContent.replace('\n', `\n${' '.repeat(nbSpaces)}`),
'\n', '\n',
previousContent.slice(startOfClosingTagIndex), previousContent.slice(startOfClosingTagIndex),
].join('') ].join('')