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 `]+?(?=[\"\'][>\s\/])/gi, (uri: string) => { imageIndex++; const fileType = getImageType(uri); const path = `OEBPS/images/${idRef}.${fileType}`; @@ -126,8 +126,8 @@ export default class EpubFile { return `../../${path}`; }) .replace(/ /g, '') - .replace(/(]+>)(?!\s*<\/img>)/g, '$1') - .replace(/<\/?(?:html|head|body|input)[^>]*>/g, ''); + .replace(/]+>(?!\s*<\/img>)/g, '$&') + .replace(/<\/?(?:html|head|body|input)\b[^>]*>/g, ''); manifest.push(manifestChapter(idRef, chapter.fileName)); files.push(createChapter(chapter)); diff --git a/src/methods/createChapter.ts b/src/methods/createChapter.ts index 375de5a..7460f6d 100644 --- a/src/methods/createChapter.ts +++ b/src/methods/createChapter.ts @@ -113,7 +113,7 @@ export function createChapter(chapter: EpubChapter) { allowedAttributes: false, //@ts-ignore // disallowedTagsMode: 'completelyDiscard', }) - .replace(//gm, '') //? remove comments + .replace(//g, '') //? remove comments } 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 } /**