fix: resolve format issues in rst

This commit is contained in:
Angel Aviel Domaoan 2022-09-30 03:51:12 +08:00
parent 048b4e304c
commit 7ea56c2768
2 changed files with 37 additions and 45 deletions

View file

@ -24,21 +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<!-- prettier-ignore-start -->',
'\n<!-- markdownlint-disable -->',
newContent.replace('\n', `\n${' '.repeat(nbSpaces - 1)}`),
'<!-- markdownlint-restore -->',
'\n<!-- prettier-ignore-end -->',
`\n${ ' '.repeat(nbSpaces - 1) }<!-- prettier-ignore-start -->`,
`\n${ ' '.repeat(nbSpaces - 1) }<!-- markdownlint-disable -->`,
' '.repeat(nbSpaces - 1) + newContent.replace('\n', `\n${ ' '.repeat(nbSpaces)}`).replace('</table>', `${' '.repeat(nbSpaces) }</table>`),
`${' '.repeat(nbSpaces - 1) }<!-- markdownlint-restore -->`,
`\n${ ' '.repeat(nbSpaces - 1) }<!-- prettier-ignore-end -->`,
'\n\n',
previousContent.slice(startOfClosingTagIndex),
' '.repeat(nbSpaces - 1) + previousContent.slice(startOfClosingTagIndex),
].join('')
}
}
@ -103,18 +99,14 @@ 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)}`),
' '.repeat(nbSpaces - 1) + newContent.replace('\n', `\n${ ' '.repeat(nbSpaces)}`),
'\n',
previousContent.slice(startOfClosingTagIndex),
' '.repeat(nbSpaces - 1) + previousContent.slice(startOfClosingTagIndex),
].join('')
}
}