From d59d0a6a42d6ca829a9674e7c34ea8c04aa9ce28 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Mon, 18 Feb 2019 23:55:32 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=BC=D0=B5=D0=B6=D1=83?= =?UTF-8?q?=D1=82=D0=BE=D1=87=D0=BD=D1=8B=D0=B9=20=D0=BA=D0=BE=D0=BC=D0=BC?= =?UTF-8?q?=D0=B8=D1=82,=20=D0=BF=D0=B0=D1=80=D1=81=D0=B8=D0=BD=D0=B3=20?= =?UTF-8?q?=D0=B8=D0=B7=D0=BE=D0=B1=D1=80=D0=B0=D0=B6=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/components/Reader/share/BookParser.js | 30 +++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/client/components/Reader/share/BookParser.js b/client/components/Reader/share/BookParser.js index 91d50581..5a4dafcb 100644 --- a/client/components/Reader/share/BookParser.js +++ b/client/components/Reader/share/BookParser.js @@ -2,6 +2,8 @@ import he from 'he'; import sax from '../../../../server/core/BookConverter/sax'; import {sleep} from '../../../share/utils'; +const maxImageLineCount = 100; + export default class BookParser { constructor() { // defaults @@ -143,6 +145,12 @@ export default class BookParser { binaryId = (attrs.id.value ? attrs.id.value : ''); } + if (tag == 'image') { + let attrs = sax.getAttrsSync(tail); + if (attrs.href.value) + newParagraph(`${' '.repeat(maxImageLineCount)}`, maxImageLineCount); + } + if (path.indexOf('/fictionbook/body') == 0) { if (tag == 'title') { newParagraph(' ', 1); @@ -301,6 +309,7 @@ export default class BookParser { try { await Promise.all(dimPromises); } catch (e) { + // } } @@ -340,18 +349,26 @@ export default class BookParser { splitToStyle(s) { let result = [];/*array of { style: {bold: Boolean, italic: Boolean, center: Boolean}, + image: Boolean, + imageId: String, text: String, }*/ let style = {}; + let image = {}; + /*let attrs = sax.getAttrsSync(tail); + if (attrs.href.value) + newParagraph(' '.repeat(maxImageLineCount) + ``, maxImageLineCount); +*/ const onTextNode = async(text) => {// eslint-disable-line no-unused-vars result.push({ style: Object.assign({}, style), - text: text + image, + text }); }; - const onStartNode = async(elemName) => {// eslint-disable-line no-unused-vars + const onStartNode = async(elemName, tail) => {// eslint-disable-line no-unused-vars switch (elemName) { case 'strong': style.bold = true; @@ -362,6 +379,9 @@ export default class BookParser { case 'center': style.center = true; break; + case 'image': + image = {}; + break; } }; @@ -376,6 +396,9 @@ export default class BookParser { case 'center': style.center = false; break; + case 'image': + image = {}; + break; } }; @@ -383,7 +406,6 @@ export default class BookParser { onStartNode, onEndNode, onTextNode }); - //длинные слова (или белиберду без пробелов) тоже разобьем const maxWordLength = this.maxWordLength; const parts = result; @@ -398,7 +420,7 @@ export default class BookParser { if (i - spaceIndex >= maxWordLength && i < p.text.length - 1 && this.measureText(p.text.substr(spaceIndex + 1, i - spaceIndex), p.style) >= this.w - this.p) { - result.push({style: p.style, text: p.text.substr(0, i + 1)}); + result.push({style: p.style, image: p.image, text: p.text.substr(0, i + 1)}); p = {style: p.style, text: p.text.substr(i + 1)}; spaceIndex = -1; i = -1;