Skip to content

Commit

Permalink
fix regular expression to contain nested div[align="center"]
Browse files Browse the repository at this point in the history
  • Loading branch information
chenxsan committed Aug 16, 2021
1 parent 8a97840 commit 557e4e9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/utilities/process-readme.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ module.exports = function processREADME(body, options = {}) {
let processingString = body
// remove items other than paragraphs in div[align="center"]
// e.g., logo, title and so on.
.replace(/[^]*?<div align="center">([^]*?)<\/div>/, (match, content) => {
.replace(/[^]*?<div align="center">([^]*)<\/div>/, (match, content) => {
let parsed = content.match(/<p>\s+([^]*?)\s+<\/?p>/);
return parsed ? parsed[1] : '';
})
Expand Down
31 changes: 31 additions & 0 deletions src/utilities/process-readme.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,35 @@ describe('processReadme', () => {
</div>`;
expect(processReadme(loaderMDData)).toEqual('');
});

it('should clean up div[align="center"] with nested dev[align="center"]', () => {
// see https://raw.githubusercontent.com/webpack-contrib/postcss-loader/master/README.md
const loaderMDData = `
<div align="center">
<img
width="180"
height="180"
hspace="10"
alt="PostCSS Logo"
src="https://api.postcss.org/logo.svg">
<a href="https://github.com/webpack/webpack">
<img
width="200"
height="200"
hspace="10"
src="https://cdn.rawgit.com/webpack/media/e7485eb2/logo/icon.svg">
</a>
<div align="center">
<a href="https://evilmartians.com/?utm_source=postcss">
<img
src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg"
alt="Sponsored by Evil Martians"
width="236"
height="54"
vspace="10">
</a>
</div>
</div>`;
expect(processReadme(loaderMDData)).toEqual('');
});
});

0 comments on commit 557e4e9

Please sign in to comment.