Улучшение парсинга fb2
This commit is contained in:
@@ -36,6 +36,7 @@ export default class BookParser {
|
|||||||
let tag = '';
|
let tag = '';
|
||||||
let center = false;
|
let center = false;
|
||||||
let bold = false;
|
let bold = false;
|
||||||
|
let italic = false;
|
||||||
|
|
||||||
let paraIndex = -1;
|
let paraIndex = -1;
|
||||||
let paraOffset = 0;
|
let paraOffset = 0;
|
||||||
@@ -95,7 +96,7 @@ export default class BookParser {
|
|||||||
tag = elemName;
|
tag = elemName;
|
||||||
path += '/' + elemName;
|
path += '/' + elemName;
|
||||||
|
|
||||||
if ((tag == 'p' || tag == 'empty-line') && path.indexOf('/fictionbook/body/section') == 0) {
|
if ((tag == 'p' || tag == 'empty-line' || tag == 'v') && path.indexOf('/fictionbook/body/section') == 0) {
|
||||||
newParagraph(' ', 1);
|
newParagraph(' ', 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,15 +105,21 @@ export default class BookParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (tag == 'title') {
|
if (tag == 'title') {
|
||||||
//newParagraph(' ', 1);
|
|
||||||
bold = true;
|
bold = true;
|
||||||
center = true;
|
center = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tag == 'subtitle') {
|
if (tag == 'subtitle') {
|
||||||
//newParagraph(' ', 1);
|
|
||||||
bold = true;
|
bold = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tag == 'epigraph') {
|
||||||
|
italic = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tag == 'stanza') {
|
||||||
|
newParagraph(' ', 1);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onEndNode = (elemName) => {// eslint-disable-line no-unused-vars
|
const onEndNode = (elemName) => {// eslint-disable-line no-unused-vars
|
||||||
@@ -126,8 +133,17 @@ export default class BookParser {
|
|||||||
center = false;
|
center = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tag == 'subtitle')
|
if (tag == 'subtitle') {
|
||||||
bold = false;
|
bold = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tag == 'epigraph') {
|
||||||
|
italic = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tag == 'stanza') {
|
||||||
|
newParagraph(' ', 1);
|
||||||
|
}
|
||||||
|
|
||||||
path = path.substr(0, path.length - tag.length - 1);
|
path = path.substr(0, path.length - tag.length - 1);
|
||||||
let i = path.lastIndexOf('/');
|
let i = path.lastIndexOf('/');
|
||||||
@@ -187,8 +203,10 @@ export default class BookParser {
|
|||||||
|
|
||||||
let tOpen = (center ? '<center>' : '');
|
let tOpen = (center ? '<center>' : '');
|
||||||
tOpen += (bold ? '<strong>' : '');
|
tOpen += (bold ? '<strong>' : '');
|
||||||
|
tOpen += (italic ? '<emphasis>' : '');
|
||||||
let tClose = (center ? '</center>' : '');
|
let tClose = (center ? '</center>' : '');
|
||||||
tClose += (bold ? '</strong>' : '');
|
tClose += (bold ? '</strong>' : '');
|
||||||
|
tClose += (italic ? '</emphasis>' : '');
|
||||||
|
|
||||||
if (path.indexOf('/fictionbook/body/title') == 0) {
|
if (path.indexOf('/fictionbook/body/title') == 0) {
|
||||||
newParagraph(`${tOpen}${text}${tClose}`, text.length, true);
|
newParagraph(`${tOpen}${text}${tClose}`, text.length, true);
|
||||||
|
|||||||
Reference in New Issue
Block a user