fix & & problem in title; Issue #10

This commit is contained in:
Alex Adam 2017-10-25 20:43:45 +03:00
parent 1bfaa75c12
commit eefc97bdfb
3 changed files with 22 additions and 8 deletions

View file

@ -154,8 +154,7 @@ function force($content, withError) {
contentString = contentString.replace(/ /gi, ' '); contentString = contentString.replace(/ /gi, ' ');
// getHref() replace does not work (& is overwritten) // getHref() replace does not work (& is overwritten)
contentString = contentString.replace(/&/ig, '&'); contentString = escapeAmp(contentString);
contentString = contentString.replace(/&/ig, '&');
return contentString; return contentString;
} catch (e) { } catch (e) {
@ -284,6 +283,7 @@ function getPageTitle(title) {
if (title.trim().length === 0) { if (title.trim().length === 0) {
return 'ebook'; return 'ebook';
} }
title = escapeAmp(title);
return title; return title;
} }

View file

@ -35,10 +35,14 @@ function _buildEbook(allPages) {
console.log('Prepare Content...'); console.log('Prepare Content...');
var ebookFileName = 'eBook.epub';
if (ebookTitle) { if (ebookTitle) {
ebookName = ebookTitle + '.epub'; ebookName = ebookTitle;
ebookFileName = getEbookFileName(bookTitle) + '.epub';
} else { } else {
ebookName = allPages[0].title + '.epub'; ebookName = allPages[0].title;
ebookFileName = getEbookFileName(allPages[0].title) + '.epub';
} }
var zip = new JSZip(); var zip = new JSZip();
@ -168,7 +172,7 @@ function _buildEbook(allPages) {
.then(function(content) { .then(function(content) {
done = true; done = true;
console.log("done !"); console.log("done !");
saveAs(content, ebookName); saveAs(content, ebookFileName);
}); });
setTimeout(function() { setTimeout(function() {
@ -179,7 +183,7 @@ function _buildEbook(allPages) {
type: "blob" type: "blob"
}) })
.then(function(content) { .then(function(content) {
saveAs(content, ebookName); saveAs(content, ebookFileName);
}); });
}, 60000); }, 60000);

View file

@ -167,8 +167,7 @@ function getAbsoluteUrl(urlStr) {
} else if (urlStr.indexOf('http') !== 0) { } else if (urlStr.indexOf('http') !== 0) {
absoluteUrl = currentUrl + '/' + urlStr; absoluteUrl = currentUrl + '/' + urlStr;
} }
absoluteUrl = absoluteUrl.replace(/&/ig, '&'); absoluteUrl = escapeAmp(absoluteUrl);
absoluteUrl = absoluteUrl.replace(/&/ig, '&');
return absoluteUrl; return absoluteUrl;
} catch (e) { } catch (e) {
console.log('Error:', e); console.log('Error:', e);
@ -291,3 +290,14 @@ function generateRandomTag(tagLen) {
} }
return text; return text;
} }
function escapeAmp(text) {
var newText = text.replace(/&/ig, '&');
newText = newText.replace(/&/ig, '&');
return newText;
}
function getEbookFileName(name) {
var newName = name.replace(/&/ig, '&');
return newName;
}