From 0d27dabd626c934f10a288e2d0c335bd75accd86 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Wed, 13 Feb 2019 14:49:51 +0700 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=BB=D1=83=D1=87=D1=88=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BF=D0=B0=D1=80=D1=81=D0=B8=D0=BD=D0=B3=D0=B0?= =?UTF-8?q?=20fb2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/components/Reader/share/BookParser.js | 96 ++++++++++---------- 1 file changed, 50 insertions(+), 46 deletions(-) diff --git a/client/components/Reader/share/BookParser.js b/client/components/Reader/share/BookParser.js index 522f22a0..96aa1b1b 100644 --- a/client/components/Reader/share/BookParser.js +++ b/client/components/Reader/share/BookParser.js @@ -63,7 +63,8 @@ export default class BookParser { const growParagraph = (text, len) => { if (paraIndex < 0) { - newParagraph(text, len); + newParagraph(' ', 1); + growParagraph(text, len); return; } @@ -96,62 +97,65 @@ export default class BookParser { tag = elemName; path += '/' + elemName; - if ((tag == 'p' || tag == 'empty-line' || tag == 'v') && path.indexOf('/fictionbook/body/section') == 0) { - newParagraph(' ', 1); - } - - if (tag == 'emphasis' || tag == 'strong') { - growParagraph(`<${tag}>`, 0); - } - - if (tag == 'title') { - newParagraph(' ', 1); - bold = true; - center = true; - } - - if (tag == 'subtitle') { - newParagraph(' ', 1); - bold = true; - } - - if (tag == 'epigraph') { - italic = true; - } - - if (tag == 'stanza') { - newParagraph(' ', 1); - } - - if (tag == 'text-author') { - newParagraph(' ', 4); - } - - }; - - const onEndNode = (elemName) => {// eslint-disable-line no-unused-vars - if (tag == elemName) { - if (tag == 'emphasis' || tag == 'strong') { - growParagraph(``, 0); + if (path.indexOf('/fictionbook/body') == 0) { + if (tag == 'title') { + newParagraph(' ', 1); + bold = true; + center = true; } - if (tag == 'title') { - bold = false; - center = false; + if (tag == 'emphasis' || tag == 'strong') { + growParagraph(`<${tag}>`, 0); + } + + if ((tag == 'p' || tag == 'empty-line' || tag == 'v')) { + newParagraph(' ', 1); } if (tag == 'subtitle') { - bold = false; + newParagraph(' ', 1); + bold = true; } if (tag == 'epigraph') { - italic = false; + italic = true; } if (tag == 'stanza') { newParagraph(' ', 1); } + if (tag == 'text-author') { + newParagraph(' ', 4); + } + } + }; + + const onEndNode = (elemName) => {// eslint-disable-line no-unused-vars + if (tag == elemName) { + if (path.indexOf('/fictionbook/body') == 0) { + if (tag == 'title') { + bold = false; + center = false; + } + + if (tag == 'emphasis' || tag == 'strong') { + growParagraph(``, 0); + } + + if (tag == 'subtitle') { + bold = false; + } + + if (tag == 'epigraph') { + italic = false; + } + + if (tag == 'stanza') { + newParagraph(' ', 1); + } + } + path = path.substr(0, path.length - tag.length - 1); let i = path.lastIndexOf('/'); if (i >= 0) { @@ -211,12 +215,12 @@ export default class BookParser { let tOpen = (center ? '
' : ''); tOpen += (bold ? '' : ''); tOpen += (italic ? '' : ''); - let tClose = (center ? '
' : ''); + let tClose = (italic ? '' : ''); tClose += (bold ? '' : ''); - tClose += (italic ? '' : ''); + tClose += (center ? '' : ''); if (path.indexOf('/fictionbook/body/title') == 0) { - newParagraph(`${tOpen}${text}${tClose}`, text.length, true); + growParagraph(`${tOpen}${text}${tClose}`, text.length, true); } if (path.indexOf('/fictionbook/body/section') == 0) {