Skip to content

Commit f2377f4

Browse files
Refine regex in cleanUp function to handle additional whitespace scenarios and remove unused console.log.
1 parent 56f09d9 commit f2377f4

2 files changed

Lines changed: 7 additions & 8 deletions

File tree

dist/index.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34408,7 +34408,6 @@ const previewUpdater = async () => {
3440834408
// Read file
3440934409
const content = (0, filesystem_1.readFile)(config, config.path.readme);
3441034410
const preview = (0, preview_1.setPreview)(content, config);
34411-
console.log(preview);
3441234411
if (content === preview) {
3441334412
(0, core_1.info)(`File "${config.path.readme}" is up to date`);
3441434413
return;
@@ -34738,16 +34737,16 @@ const image_1 = __nccwpck_require__(7828);
3473834737
const strings_1 = __nccwpck_require__(3063);
3473934738
const hasHeader = (content) => content.match(/^#\s+/);
3474034739
const cleanUp = (content) => content
34741-
.replace(/^(#\s+.+\n+)\s*<picture>[.\w\W]+<\/picture>[\n\s]*/, '$1')
34742-
.replace(/^(#\s+.+\n+)(!\[.+]\(.*\)\n?){1,2}[\n\s]*/, '$1\n')
34743-
.replace(/^(#\s+.+\n+)(<img\s.*\/>\n?){1,2}[\n\s]*/, '$1\n');
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');
3474434743
const setPreview = (content, config) => {
3474534744
if (!hasHeader(content)) {
3474634745
const title = (0, strings_1.titleCase)(config.image.parameters.title);
3474734746
content = `# ${title}\n\n${content}`;
3474834747
}
3474934748
const images = (0, image_1.getImages)(config);
34750-
return cleanUp(content).replace(/^(#\s+.+\n\n)/, '$1' + images + '\n\n');
34749+
return cleanUp(content).replace(/^(#\s+.+[\n\s]+)/, '$1' + images + '\n\n');
3475134750
};
3475234751
exports.setPreview = setPreview;
3475334752

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\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')
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')
1111

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

0 commit comments

Comments
 (0)