Skip to content

Commit a30d1d5

Browse files
Refine regex in cleanUp function to handle trailing whitespace after <picture>, <img>, and Markdown image tags.
1 parent 405b57c commit a30d1d5

3 files changed

Lines changed: 6 additions & 7 deletions

File tree

dist/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34739,9 +34739,9 @@ const image_1 = __nccwpck_require__(7828);
3473934739
const strings_1 = __nccwpck_require__(3063);
3474034740
const hasHeader = (content) => content.match(/^#\s+/);
3474134741
const cleanUp = (content) => content
34742-
.replace(/^(#\s+.+\n+)(\s*<picture>[.\w\W]+<\/picture>\n?)/, '$1')
34743-
.replace(/^(#\s+.+\n+)(!\[.+]\(.*\)\n?){1,2}\n?/, '$1\n')
34744-
.replace(/^(#\s+.+\n+)(<img\s.*\/>\n?){1,2}\n?/, '$1\n');
34742+
.replace(/^(#\s+.+\n+)\s*<picture>[.\w\W]+<\/picture>[\n\s]*/, '$1')
34743+
.replace(/^(#\s+.+\n+)(!\[.+]\(.*\)\n?){1,2}[\n\s]*/, '$1\n')
34744+
.replace(/^(#\s+.+\n+)(<img\s.*\/>\n?){1,2}[\n\s]*/, '$1\n');
3474534745
const setPreview = (content, config) => {
3474634746
if (!hasHeader(content)) {
3474734747
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*<picture>[.\w\W]+<\/picture>\n?)/, '$1')
9-
.replace(/^(#\s+.+\n+)(!\[.+]\(.*\)\n?){1,2}\n?/, '$1\n')
10-
.replace(/^(#\s+.+\n+)(<img\s.*\/>\n?){1,2}\n?/, '$1\n')
8+
.replace(/^(#\s+.+\n+)\s*<picture>[.\w\W]+<\/picture>[\n\s]*/, '$1')
9+
.replace(/^(#\s+.+\n+)(!\[.+]\(.*\)\n?){1,2}[\n\s]*/, '$1\n')
10+
.replace(/^(#\s+.+\n+)(<img\s.*\/>\n?){1,2}[\n\s]*/, '$1\n')
1111

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

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ exports[`html-tag 1`] = `
1919
<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">
2020
</picture>
2121
22-
2322
## Usage
2423
2524
Something

0 commit comments

Comments
 (0)