From d4f6536caad1fd05c4fe8ac1521f07da0d47e130 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Thu, 24 Dec 2020 16:33:44 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=BA?= =?UTF-8?q?=D0=B8=20=D0=BF=D0=BE=20=D1=80=D0=B5=D0=B7=D1=83=D0=BB=D1=8C?= =?UTF-8?q?=D1=82=D0=B0=D1=82=D1=83=20=D1=82=D0=B5=D1=81=D1=82=D0=B8=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/components/Reader/share/BookParser.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/client/components/Reader/share/BookParser.js b/client/components/Reader/share/BookParser.js index f6b10d78..fc8d9c22 100644 --- a/client/components/Reader/share/BookParser.js +++ b/client/components/Reader/share/BookParser.js @@ -98,6 +98,7 @@ export default class BookParser { */ const getImageDimensions = (binaryId, binaryType, data) => { return new Promise ((resolve, reject) => { (async() => { + data = data.replace(/[\n\r\s]/g, ''); const i = new Image(); let resolved = false; i.onload = () => { @@ -218,8 +219,8 @@ export default class BookParser { if (tag == 'binary') { let attrs = sax.getAttrsSync(tail); binaryType = (attrs['content-type'] && attrs['content-type'].value ? attrs['content-type'].value : ''); - binaryType = (binaryType == 'image/jpg' ? 'image/jpeg' : binaryType); - if (binaryType == 'image/jpeg' || binaryType == 'image/png' || binaryType == 'application/octet-stream') + binaryType = (binaryType == 'image/jpg' || binaryType == 'application/octet-stream' ? 'image/jpeg' : binaryType); + if (binaryType == 'image/jpeg' || binaryType == 'image/png') binaryId = (attrs.id.value ? attrs.id.value : ''); } @@ -244,8 +245,11 @@ export default class BookParser { } else {//external imageNum++; - if (!this.sets.isTesting) + if (!this.sets.isTesting) { dimPromises.push(getExternalImageDimensions(href)); + } else { + dimPromises.push(this.sets.getExternalImageDimensions(this, href)); + } newParagraph(`${' '.repeat(maxImageLineCount)}`, maxImageLineCount); this.images.push({paraIndex, num: imageNum, id, local, alt}); @@ -492,8 +496,12 @@ export default class BookParser { growParagraph(`${tOpen}${text}${tClose}`, text.length); } - if (binaryId && !this.sets.isTesting) { - dimPromises.push(getImageDimensions(binaryId, binaryType, text)); + if (binaryId) { + if (!this.sets.isTesting) { + dimPromises.push(getImageDimensions(binaryId, binaryType, text)); + } else { + dimPromises.push(this.sets.getImageDimensions(this, binaryId, binaryType, text)); + } } };