From 5938b332074980989d8a0bba4cd92440f5d21187 Mon Sep 17 00:00:00 2001 From: Palloxin <75091899+Palloxin@users.noreply.github.com> Date: Mon, 8 Sep 2025 14:03:48 +0200 Subject: [PATCH 1/7] Update helper.ts --- src/methods/helper.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/methods/helper.ts b/src/methods/helper.ts index 3ab77f4..500c31d 100644 --- a/src/methods/helper.ts +++ b/src/methods/helper.ts @@ -91,10 +91,9 @@ export function parseJSon(json: string) { * @returns The extracted JSON string, or an empty string if no JSON is found. */ export function jsonExtractor(content: string) { - const jsonReg = new RegExp(/(.|\n)*?<\/JSON>/, 'mgi'); + const jsonReg = new RegExp(/[^]*?<\/JSON>/, 'mgi'); return (single(jsonReg.exec(content)) ?? '') - .replace(//gim, '') - .replace(/<\/JSON>/gim, ''); + .replace(/<\/?JSON>/gim, ''); } /** @@ -104,10 +103,9 @@ export function jsonExtractor(content: string) { * @returns The extracted body content without the tags. */ export function bodyExtrator(content: string) { - const jsonReg = new RegExp(/(.|\n)*?<\/body>/, 'mgi'); + const jsonReg = new RegExp(/[^]*?<\/body>/, 'mgi'); return (single(jsonReg.exec(content)) ?? '') - .replace(//gim, '') - .replace(/<\/body>/gim, ''); + .replace(/<\/?body>/gim, ''); } /** @@ -138,7 +136,8 @@ export function getImageType(path: string) { * console.log(result); // Output: "example" */ export function removeFileExtension(name: string) { - return name.replace(/(.*)(\.opf|\.epub)/, '$1'); + return name + .replace(/([^]+)(?:\.opf|\.epub)/, '$1'); } /** @@ -153,7 +152,7 @@ export function removeFileExtension(name: string) { * console.log(sanitizedFileName); // Output: "my_filetxt" */ export function sanitizeFileName(fileName: string) { - return fileName.replaceAll(' ', '_').replace(/[^\w]/gi, ''); // remove all non-word and non-space characters + return fileName.replaceAll(' ', '_').replace(/[^\w]+/gi, ''); // remove all non-word and non-space characters } /** From 4c26f533b53b56c16e8e18d9af5fc02efd5a1d14 Mon Sep 17 00:00:00 2001 From: Palloxin <75091899+Palloxin@users.noreply.github.com> Date: Mon, 8 Sep 2025 14:43:03 +0200 Subject: [PATCH 2/7] Update manifestConstructor.ts --- src/constructors/manifestConstructor.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/constructors/manifestConstructor.ts b/src/constructors/manifestConstructor.ts index 4bb14a6..a243cd0 100644 --- a/src/constructors/manifestConstructor.ts +++ b/src/constructors/manifestConstructor.ts @@ -63,7 +63,7 @@ export function manifestCover(fileFormat: string): string { */ export function manifestImage(uri: string, fileFormat: string): string { return `]+?(?=[\"\'][> ])/gi, (uri: string) => { imageIndex++; const fileType = getImageType(uri); const path = `OEBPS/images/${idRef}.${fileType}`; @@ -127,7 +127,7 @@ export default class EpubFile { }) .replace(/ /g, '') .replace(/(]+>)(?!\s*<\/img>)/g, '$1') - .replace(/<\/?(?:html|head|body|input)[^>]*>/g, ''); + .replace(/<\/?(?:html|head|body|input)\b[^>]*>/g, ''); manifest.push(manifestChapter(idRef, chapter.fileName)); files.push(createChapter(chapter)); From 90bcb2e2023bd94fcf7c23a2c2421e7eff431745 Mon Sep 17 00:00:00 2001 From: Palloxin <75091899+Palloxin@users.noreply.github.com> Date: Mon, 8 Sep 2025 15:01:51 +0200 Subject: [PATCH 5/7] Update main.ts --- src/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index 9199eef..eaaee95 100644 --- a/src/main.ts +++ b/src/main.ts @@ -117,7 +117,7 @@ export default class EpubFile { const idRef = `${sanitizeFileName(chapter.title)}_image_${imageIndex}`; chapter.htmlBody = chapter.htmlBody - .replace(/(?<=]+?\bsrc=[\"|\'])[^>]+?(?=[\"\'][> ])/gi, (uri: string) => { + .replace(/(?<=]+?\bsrc=[\"\'])[^>]+?(?=[\"\'][> ])/gi, (uri: string) => { imageIndex++; const fileType = getImageType(uri); const path = `OEBPS/images/${idRef}.${fileType}`; From 58d87acaf55667616d70907d8ce4b6ce2e855f7e Mon Sep 17 00:00:00 2001 From: Palloxin <75091899+Palloxin@users.noreply.github.com> Date: Tue, 9 Sep 2025 08:04:30 +0200 Subject: [PATCH 6/7] little flaw fix --- src/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index eaaee95..817fe3e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -117,7 +117,7 @@ export default class EpubFile { const idRef = `${sanitizeFileName(chapter.title)}_image_${imageIndex}`; chapter.htmlBody = chapter.htmlBody - .replace(/(?<=]+?\bsrc=[\"\'])[^>]+?(?=[\"\'][> ])/gi, (uri: string) => { + .replace(/(?<=]+?\bsrc=[\"\'])[^>]+?(?=[\"\'][>\s\/])/gi, (uri: string) => { imageIndex++; const fileType = getImageType(uri); const path = `OEBPS/images/${idRef}.${fileType}`; From eb88b382bc68713c9d573123b7dec97b815706b0 Mon Sep 17 00:00:00 2001 From: Palloxin <75091899+Palloxin@users.noreply.github.com> Date: Tue, 9 Sep 2025 08:35:35 +0200 Subject: [PATCH 7/7] Update main.ts --- src/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index 817fe3e..09e253c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -126,7 +126,7 @@ export default class EpubFile { return `../../${path}`; }) .replace(/ /g, '') - .replace(/(]+>)(?!\s*<\/img>)/g, '$1') + .replace(/]+>(?!\s*<\/img>)/g, '$&') .replace(/<\/?(?:html|head|body|input)\b[^>]*>/g, ''); manifest.push(manifestChapter(idRef, chapter.fileName));