Улучшил отображение subtitle
This commit is contained in:
@@ -54,14 +54,13 @@ export default class BookParser {
|
|||||||
text: String //текст параграфа (или title или epigraph и т.д) с вложенными тегами
|
text: String //текст параграфа (или title или epigraph и т.д) с вложенными тегами
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
const newParagraph = (text, len, single) => {
|
const newParagraph = (text, len) => {
|
||||||
paraIndex++;
|
paraIndex++;
|
||||||
let p = {
|
let p = {
|
||||||
index: paraIndex,
|
index: paraIndex,
|
||||||
offset: paraOffset,
|
offset: paraOffset,
|
||||||
length: len,
|
length: len,
|
||||||
text: text,
|
text: text,
|
||||||
single: single
|
|
||||||
};
|
};
|
||||||
|
|
||||||
para[paraIndex] = p;
|
para[paraIndex] = p;
|
||||||
@@ -70,10 +69,6 @@ export default class BookParser {
|
|||||||
const growParagraph = (text, len) => {
|
const growParagraph = (text, len) => {
|
||||||
let p = para[paraIndex];
|
let p = para[paraIndex];
|
||||||
if (p) {
|
if (p) {
|
||||||
if (p.single) {
|
|
||||||
newParagraph(text, len);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
paraOffset -= p.length;
|
paraOffset -= p.length;
|
||||||
if (p.length == 1 && p.text[0] == ' ' && len > 0) {
|
if (p.length == 1 && p.text[0] == ' ' && len > 0) {
|
||||||
p.length = 0;
|
p.length = 0;
|
||||||
@@ -111,8 +106,10 @@ export default class BookParser {
|
|||||||
growParagraph(`<${tag}>`, 0);
|
growParagraph(`<${tag}>`, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tag == 'title' || tag == 'subtitle')
|
if (tag == 'title' || tag == 'subtitle') {
|
||||||
|
newParagraph(' ', 1);
|
||||||
center = true;
|
center = true;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
parser.on('endNode', (elemName, isTagStart, getStrNode) => {// eslint-disable-line no-unused-vars
|
parser.on('endNode', (elemName, isTagStart, getStrNode) => {// eslint-disable-line no-unused-vars
|
||||||
@@ -174,8 +171,8 @@ export default class BookParser {
|
|||||||
fb2.annotation += text;
|
fb2.annotation += text;
|
||||||
}
|
}
|
||||||
|
|
||||||
let cOpen = (center ? '<center>' : '');
|
let cOpen = (center ? '<center><strong>' : '');
|
||||||
let cClose = (center ? '</center>' : '');
|
let cClose = (center ? '</strong></center>' : '');
|
||||||
|
|
||||||
if (path.indexOf('/FictionBook/body/title') == 0) {
|
if (path.indexOf('/FictionBook/body/title') == 0) {
|
||||||
newParagraph(`${cOpen}${text}${cClose}`, text.length, true);
|
newParagraph(`${cOpen}${text}${cClose}`, text.length, true);
|
||||||
@@ -186,10 +183,6 @@ export default class BookParser {
|
|||||||
case 'p':
|
case 'p':
|
||||||
growParagraph(`${cOpen}${text}${cClose}`, text.length);
|
growParagraph(`${cOpen}${text}${cClose}`, text.length);
|
||||||
break;
|
break;
|
||||||
//case 'section':
|
|
||||||
case 'title':
|
|
||||||
newParagraph(`${cOpen}${text}${cClose}`, text.length, center);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
growParagraph(`${cOpen}${text}${cClose}`, text.length);
|
growParagraph(`${cOpen}${text}${cClose}`, text.length);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,6 +58,10 @@ class BookConverter {
|
|||||||
pars.push({_n: 'p', _t: ''});
|
pars.push({_n: 'p', _t: ''});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const newSubTitle = () => {
|
||||||
|
pars.push({_n: 'subtitle', _t: ''});
|
||||||
|
};
|
||||||
|
|
||||||
const growParagraph = (text) => {
|
const growParagraph = (text) => {
|
||||||
const l = pars.length;
|
const l = pars.length;
|
||||||
if (l) {
|
if (l) {
|
||||||
@@ -77,7 +81,7 @@ class BookConverter {
|
|||||||
path += '/' + elemName;
|
path += '/' + elemName;
|
||||||
tag = elemName;
|
tag = elemName;
|
||||||
} else {
|
} else {
|
||||||
if (elemName == 'p' || elemName == 'dd') {
|
if (!center && (elemName == 'p' || elemName == 'dd')) {
|
||||||
newParagraph();
|
newParagraph();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,8 +94,10 @@ class BookConverter {
|
|||||||
break;
|
break;
|
||||||
case 'div':
|
case 'div':
|
||||||
var a = getAttr();
|
var a = getAttr();
|
||||||
if (a && a.align == 'center')
|
if (a && a.align == 'center') {
|
||||||
center = true;
|
center = true;
|
||||||
|
newSubTitle();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -153,11 +159,8 @@ class BookConverter {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let cOpen = (center ? '<subtitle>' : '');
|
|
||||||
let cClose = (center ? '</subtitle>' : '');
|
|
||||||
|
|
||||||
if (inText)
|
if (inText)
|
||||||
growParagraph(`${cOpen}${text}${cClose}`);
|
growParagraph(text);
|
||||||
});
|
});
|
||||||
|
|
||||||
parser.on('cdata', (data) => {// eslint-disable-line no-unused-vars
|
parser.on('cdata', (data) => {// eslint-disable-line no-unused-vars
|
||||||
|
|||||||
Reference in New Issue
Block a user