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

@ -10,18 +10,18 @@ These people contributed to the project:
<!-- ALL-CONTRIBUTORS-LIST:START --> <!-- ALL-CONTRIBUTORS-LIST:START -->
<!-- prettier-ignore-start --> <!-- prettier-ignore-start -->
<!-- markdownlint-disable --> <!-- markdownlint-disable -->
<table> <table>
<tbody> <tbody>
<tr> <tr>
<td align=\\"center\\">Kent C. Dodds is awesome!</td> <td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\">Divjot Singh is awesome!</td> <td align=\\"center\\">Divjot Singh is awesome!</td>
<td align=\\"center\\">Jeroen Engels is awesome!</td> <td align=\\"center\\">Jeroen Engels is awesome!</td>
</tr> </tr>
</tbody> </tbody>
<tfoot> <tfoot>
</tfoot> </tfoot>
</table> </table>
<!-- markdownlint-restore --> <!-- markdownlint-restore -->
<!-- prettier-ignore-end --> <!-- prettier-ignore-end -->
@ -41,12 +41,12 @@ These people contributed to the project:
<!-- ALL-CONTRIBUTORS-LIST:START --> <!-- ALL-CONTRIBUTORS-LIST:START -->
<!-- prettier-ignore-start --> <!-- prettier-ignore-start -->
<!-- markdownlint-disable --> <!-- markdownlint-disable -->
<table> <table>
<tbody> <tbody>
<tr> <tr>
<td align=\\"center\\">Kent C. Dodds is awesome!</td> <td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\">Divjot Singh is awesome!</td> <td align=\\"center\\">Divjot Singh is awesome!</td>
<td align=\\"center\\">Jeroen Engels is awesome!</td> <td align=\\"center\\">Jeroen Engels is awesome!</td>
</tr> </tr>
</tbody> </tbody>
<tfoot> <tfoot>
@ -58,7 +58,7 @@ These people contributed to the project:
</td> </td>
</tr> </tr>
</tfoot> </tfoot>
</table> </table>
<!-- markdownlint-restore --> <!-- markdownlint-restore -->
<!-- prettier-ignore-end --> <!-- prettier-ignore-end -->
@ -78,24 +78,24 @@ These people contributed to the project:
<!-- ALL-CONTRIBUTORS-LIST:START --> <!-- ALL-CONTRIBUTORS-LIST:START -->
<!-- prettier-ignore-start --> <!-- prettier-ignore-start -->
<!-- markdownlint-disable --> <!-- markdownlint-disable -->
<table> <table>
<tbody> <tbody>
<tr> <tr>
<td align=\\"center\\">Kent C. Dodds is awesome!</td> <td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\">Kent C. Dodds is awesome!</td> <td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\">Kent C. Dodds is awesome!</td> <td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\">Kent C. Dodds is awesome!</td> <td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\">Kent C. Dodds is awesome!</td> <td align=\\"center\\">Kent C. Dodds is awesome!</td>
</tr> </tr>
<tr> <tr>
<td align=\\"center\\">Kent C. Dodds is awesome!</td> <td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\">Kent C. Dodds is awesome!</td> <td align=\\"center\\">Kent C. Dodds is awesome!</td>
</tr> </tr>
</tbody> </tbody>
<tfoot> <tfoot>
</tfoot> </tfoot>
</table> </table>
<!-- markdownlint-restore --> <!-- markdownlint-restore -->
<!-- prettier-ignore-end --> <!-- prettier-ignore-end -->
@ -115,18 +115,18 @@ These people contributed to the project:
<!-- ALL-CONTRIBUTORS-LIST:START --> <!-- ALL-CONTRIBUTORS-LIST:START -->
<!-- prettier-ignore-start --> <!-- prettier-ignore-start -->
<!-- markdownlint-disable --> <!-- markdownlint-disable -->
<table> <table>
<tbody> <tbody>
<tr> <tr>
<td align=\\"center\\">Kent C. Dodds is awesome!</td> <td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\">Kent C. Dodds is awesome!</td> <td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\">Kent C. Dodds is awesome!</td> <td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\">Kent C. Dodds is awesome!</td> <td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\">Kent C. Dodds is awesome!</td> <td align=\\"center\\">Kent C. Dodds is awesome!</td>
</tr> </tr>
<tr> <tr>
<td align=\\"center\\">Kent C. Dodds is awesome!</td> <td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\">Kent C. Dodds is awesome!</td> <td align=\\"center\\">Kent C. Dodds is awesome!</td>
</tr> </tr>
</tbody> </tbody>
<tfoot> <tfoot>
@ -138,7 +138,7 @@ These people contributed to the project:
</td> </td>
</tr> </tr>
</tfoot> </tfoot>
</table> </table>
<!-- markdownlint-restore --> <!-- markdownlint-restore -->
<!-- prettier-ignore-end --> <!-- prettier-ignore-end -->

View file

@ -3,7 +3,7 @@ const formatBadge = require('./format-badge')
const formatContributor = require('./format-contributor') const formatContributor = require('./format-contributor')
function injectListBetweenTags(newContent) { function injectListBetweenTags(newContent) {
return function (previousContent) { return function(previousContent) {
const tagToLookFor = `<!-- ALL-CONTRIBUTORS-LIST:` const tagToLookFor = `<!-- ALL-CONTRIBUTORS-LIST:`
const closingTag = '-->' const closingTag = '-->'
const startOfOpeningTagIndex = previousContent.indexOf( const startOfOpeningTagIndex = previousContent.indexOf(
@ -24,28 +24,24 @@ function injectListBetweenTags(newContent) {
) { ) {
return previousContent return previousContent
} }
const startIndent = Math.max( const startIndent = Math.max(0, previousContent.lastIndexOf('\n', startOfOpeningTagIndex))
0, const nbSpaces = startOfOpeningTagIndex - Math.min(startOfOpeningTagIndex, startIndent)
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${ ' '.repeat(nbSpaces - 1) }<!-- prettier-ignore-start -->`,
'\n<!-- markdownlint-disable -->', `\n${ ' '.repeat(nbSpaces - 1) }<!-- markdownlint-disable -->`,
newContent.replace('\n', `\n${' '.repeat(nbSpaces - 1)}`), ' '.repeat(nbSpaces - 1) + newContent.replace('\n', `\n${ ' '.repeat(nbSpaces)}`).replace('</table>', `${' '.repeat(nbSpaces) }</table>`),
'<!-- markdownlint-restore -->', `${' '.repeat(nbSpaces - 1) }<!-- markdownlint-restore -->`,
'\n<!-- prettier-ignore-end -->', `\n${ ' '.repeat(nbSpaces - 1) }<!-- prettier-ignore-end -->`,
'\n\n', '\n\n',
previousContent.slice(startOfClosingTagIndex), ' '.repeat(nbSpaces - 1) + previousContent.slice(startOfClosingTagIndex),
].join('') ].join('')
} }
} }
function formatLine(contributors) { function formatLine(contributors) {
return `<td align="center">${contributors.join( return `<td align="center">${contributors.join(
'</td>\n <td align="center">', '</td>\n <td align="center">',
)}</td>` )}</td>`
} }
@ -82,7 +78,7 @@ function generateContributorsList(options, contributors) {
} }
function replaceBadge(newContent) { function replaceBadge(newContent) {
return function (previousContent) { return function(previousContent) {
const tagToLookFor = `<!-- ALL-CONTRIBUTORS-BADGE:` const tagToLookFor = `<!-- ALL-CONTRIBUTORS-BADGE:`
const closingTag = '-->' const closingTag = '-->'
const startOfOpeningTagIndex = previousContent.indexOf( const startOfOpeningTagIndex = previousContent.indexOf(
@ -103,18 +99,14 @@ function replaceBadge(newContent) {
) { ) {
return previousContent return previousContent
} }
const startIndent = Math.max( const startIndent = Math.max(0, previousContent.lastIndexOf('\n', startOfOpeningTagIndex))
0, const nbSpaces = startOfOpeningTagIndex - Math.min(startOfOpeningTagIndex, startIndent)
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.replace('\n', `\n${' '.repeat(nbSpaces)}`), ' '.repeat(nbSpaces - 1) + newContent.replace('\n', `\n${ ' '.repeat(nbSpaces)}`),
'\n', '\n',
previousContent.slice(startOfClosingTagIndex), ' '.repeat(nbSpaces - 1) + previousContent.slice(startOfClosingTagIndex),
].join('') ].join('')
} }
} }