Skip to content

Commit 94cfbaa

Browse files
Add test for html-tag scenario and update preview utility to clean <picture> tags
1 parent 40d69c6 commit 94cfbaa

5 files changed

Lines changed: 28 additions & 0 deletions

File tree

dist/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34739,6 +34739,7 @@ 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')
3474234743
.replace(/^(#\s+.+\n+)(!\[.+]\(.*\)\n?){1,2}\n?/, '$1\n')
3474334744
.replace(/^(#\s+.+\n+)(<img\s.*\/>\n?){1,2}\n?/, '$1\n');
3474434745
const setPreview = (content, config) => {

src/utils/preview.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ 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')
89
.replace(/^(#\s+.+\n+)(!\[.+]\(.*\)\n?){1,2}\n?/, '$1\n')
910
.replace(/^(#\s+.+\n+)(<img\s.*\/>\n?){1,2}\n?/, '$1\n')
1011

tests/fixtures/readme/html-tag.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Preview Updater
2+
3+
<picture>
4+
<source media="(prefers-color-scheme: dark)" srcset="https://example.com?theme=dark">
5+
<img src="https://example.com?theme=light" alt="some">
6+
</picture>
7+
8+
## Usage
9+
10+
Something

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,21 @@ exports[`empty 1`] = `
1111
"
1212
`;
1313
14+
exports[`html-tag 1`] = `
15+
"# Preview Updater
16+
17+
<picture>
18+
<source media="(prefers-color-scheme: dark)" srcset="https://banners.beyondco.de/Preview%20Updater.png?theme=dark&pattern=topography&style=style_2&fontSize=100px&images=code&packageManager=npm+install&packageName=TheDragonCode%2Fpreview-updater&description=Lightweight+preview+update+in+your+repository">
19+
<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">
20+
</picture>
21+
22+
23+
## Usage
24+
25+
Something
26+
"
27+
`;
28+
1429
exports[`just-text 1`] = `
1530
"# Preview Updater
1631

tests/unit/preview.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ test('with-two-images', () => expect(getReadme('with-two-images.md')).toMatchSna
88
test('with-two-images-without-header', () => expect(getReadme('with-two-images-without-header.md')).toMatchSnapshot())
99
test('without-all', () => expect(getReadme('without-all.md')).toMatchSnapshot())
1010
test('without-images', () => expect(getReadme('without-images.md')).toMatchSnapshot())
11+
test('html-tag', () => expect(getReadme('html-tag.md')).toMatchSnapshot())

0 commit comments

Comments
 (0)