Улучшил отображение subtitle

This commit is contained in:
Book Pauk
2019-01-22 23:36:13 +07:00
parent db3ecde741
commit 275898c68a
2 changed files with 15 additions and 19 deletions

View File

@@ -54,14 +54,13 @@ export default class BookParser {
text: String //текст параграфа (или title или epigraph и т.д) с вложенными тегами
}
*/
const newParagraph = (text, len, single) => {
const newParagraph = (text, len) => {
paraIndex++;
let p = {
index: paraIndex,
offset: paraOffset,
length: len,
text: text,
single: single
};
para[paraIndex] = p;
@@ -70,10 +69,6 @@ export default class BookParser {
const growParagraph = (text, len) => {
let p = para[paraIndex];
if (p) {
if (p.single) {
newParagraph(text, len);
return;
}
paraOffset -= p.length;
if (p.length == 1 && p.text[0] == ' ' && len > 0) {
p.length = 0;
@@ -111,8 +106,10 @@ export default class BookParser {
growParagraph(`<${tag}>`, 0);
}
if (tag == 'title' || tag == 'subtitle')
if (tag == 'title' || tag == 'subtitle') {
newParagraph(' ', 1);
center = true;
}
});
parser.on('endNode', (elemName, isTagStart, getStrNode) => {// eslint-disable-line no-unused-vars
@@ -174,8 +171,8 @@ export default class BookParser {
fb2.annotation += text;
}
let cOpen = (center ? '<center>' : '');
let cClose = (center ? '</center>' : '');
let cOpen = (center ? '<center><strong>' : '');
let cClose = (center ? '</strong></center>' : '');
if (path.indexOf('/FictionBook/body/title') == 0) {
newParagraph(`${cOpen}${text}${cClose}`, text.length, true);
@@ -186,10 +183,6 @@ export default class BookParser {
case 'p':
growParagraph(`${cOpen}${text}${cClose}`, text.length);
break;
//case 'section':
case 'title':
newParagraph(`${cOpen}${text}${cClose}`, text.length, center);
break;
default:
growParagraph(`${cOpen}${text}${cClose}`, text.length);
}

View File

@@ -58,6 +58,10 @@ class BookConverter {
pars.push({_n: 'p', _t: ''});
};
const newSubTitle = () => {
pars.push({_n: 'subtitle', _t: ''});
};
const growParagraph = (text) => {
const l = pars.length;
if (l) {
@@ -77,7 +81,7 @@ class BookConverter {
path += '/' + elemName;
tag = elemName;
} else {
if (elemName == 'p' || elemName == 'dd') {
if (!center && (elemName == 'p' || elemName == 'dd')) {
newParagraph();
}
@@ -90,8 +94,10 @@ class BookConverter {
break;
case 'div':
var a = getAttr();
if (a && a.align == 'center')
if (a && a.align == 'center') {
center = true;
newSubTitle();
}
break;
}
}
@@ -153,11 +159,8 @@ class BookConverter {
return;
}
let cOpen = (center ? '<subtitle>' : '');
let cClose = (center ? '</subtitle>' : '');
if (inText)
growParagraph(`${cOpen}${text}${cClose}`);
growParagraph(text);
});
parser.on('cdata', (data) => {// eslint-disable-line no-unused-vars