Skip to content

Commit 0e90864

Browse files
Refine regex in cleanUp function to remove unnecessary newline insertion after <picture>, <img>, and Markdown image tags.
1 parent 1c15f0d commit 0e90864

3 files changed

Lines changed: 6 additions & 10 deletions

File tree

dist/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34737,9 +34737,9 @@ const image_1 = __nccwpck_require__(7828);
3473734737
const strings_1 = __nccwpck_require__(3063);
3473834738
const hasHeader = (content) => content.match(/^#\s+/);
3473934739
const cleanUp = (content) => content
34740-
.replace(/^(#\s+.+[\n\s]+)\s*<picture>[.\w\W]+<\/picture>[\n\s]*/, '$1\n')
34741-
.replace(/^(#\s+.+[\n\s]+)(!\[.+]\(.*\)\n?){1,2}[\n\s]*/, '$1\n')
34742-
.replace(/^(#\s+.+[\n\s]+)(<img\s.*\/>\n?){1,2}[\n\s]*/, '$1\n');
34740+
.replace(/^(#\s+.+[\n\s]+)\s*<picture>[.\w\W]+<\/picture>[\n\s]*/, '$1')
34741+
.replace(/^(#\s+.+[\n\s]+)(!\[.+]\(.*\)\n?){1,2}[\n\s]*/, '$1')
34742+
.replace(/^(#\s+.+[\n\s]+)(<img\s.*\/>\n?){1,2}[\n\s]*/, '$1');
3474334743
const setPreview = (content, config) => {
3474434744
if (!hasHeader(content)) {
3474534745
const title = (0, strings_1.titleCase)(config.image.parameters.title);

src/utils/preview.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import { titleCase } from './strings'
55
const hasHeader = (content: string) => content.match(/^#\s+/)
66

77
const cleanUp = (content: string): string => content
8-
.replace(/^(#\s+.+[\n\s]+)\s*<picture>[.\w\W]+<\/picture>[\n\s]*/, '$1\n')
9-
.replace(/^(#\s+.+[\n\s]+)(!\[.+]\(.*\)\n?){1,2}[\n\s]*/, '$1\n')
10-
.replace(/^(#\s+.+[\n\s]+)(<img\s.*\/>\n?){1,2}[\n\s]*/, '$1\n')
8+
.replace(/^(#\s+.+[\n\s]+)\s*<picture>[.\w\W]+<\/picture>[\n\s]*/, '$1')
9+
.replace(/^(#\s+.+[\n\s]+)(!\[.+]\(.*\)\n?){1,2}[\n\s]*/, '$1')
10+
.replace(/^(#\s+.+[\n\s]+)(<img\s.*\/>\n?){1,2}[\n\s]*/, '$1')
1111

1212
export const setPreview = (content: string, config: Config) => {
1313
if (! hasHeader(content)) {

tests/unit/__snapshots__/preview.test.ts.snap

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ exports[`with-one-image 1`] = `
4545
<img src="https://banners.beyondco.de/Preview%20Updater.png?theme=light&pattern=topography&style=style_2&fontSize=100px&images=code&packageManager=npm+install&packageName=TheDragonCode%2Fpreview-updater&description=Lightweight+preview+update+in+your+repository" alt="Preview Updater">
4646
</picture>
4747
48-
4948
## Usage
5049
5150
Something
@@ -60,7 +59,6 @@ exports[`with-one-image-without-header 1`] = `
6059
<img src="https://banners.beyondco.de/Preview%20Updater.png?theme=light&pattern=topography&style=style_2&fontSize=100px&images=code&packageManager=npm+install&packageName=TheDragonCode%2Fpreview-updater&description=Lightweight+preview+update+in+your+repository" alt="Preview Updater">
6160
</picture>
6261
63-
6462
## Usage
6563
6664
Something
@@ -75,7 +73,6 @@ exports[`with-two-images 1`] = `
7573
<img src="https://banners.beyondco.de/Preview%20Updater.png?theme=light&pattern=topography&style=style_2&fontSize=100px&images=code&packageManager=npm+install&packageName=TheDragonCode%2Fpreview-updater&description=Lightweight+preview+update+in+your+repository" alt="Preview Updater">
7674
</picture>
7775
78-
7976
## Usage
8077
8178
Something
@@ -90,7 +87,6 @@ exports[`with-two-images-without-header 1`] = `
9087
<img src="https://banners.beyondco.de/Preview%20Updater.png?theme=light&pattern=topography&style=style_2&fontSize=100px&images=code&packageManager=npm+install&packageName=TheDragonCode%2Fpreview-updater&description=Lightweight+preview+update+in+your+repository" alt="Preview Updater">
9188
</picture>
9289
93-
9490
## Usage
9591
9692
Something

0 commit comments

Comments
 (0)