Улучшен парсинг fb2
This commit is contained in:
@@ -3,6 +3,7 @@ import sax from '../../../../server/core/sax';
|
|||||||
import * as utils from '../../../share/utils';
|
import * as utils from '../../../share/utils';
|
||||||
|
|
||||||
const maxImageLineCount = 100;
|
const maxImageLineCount = 100;
|
||||||
|
const maxParaTextLength = 10000;
|
||||||
|
|
||||||
// defaults
|
// defaults
|
||||||
const defaultSettings = {
|
const defaultSettings = {
|
||||||
@@ -226,13 +227,25 @@ export default class BookParser {
|
|||||||
paraOffset += len;
|
paraOffset += len;
|
||||||
};
|
};
|
||||||
|
|
||||||
const growParagraph = (text, len) => {
|
const growParagraph = (text, len, textRaw) => {
|
||||||
if (paraIndex < 0) {
|
if (paraIndex < 0) {
|
||||||
newParagraph();
|
newParagraph();
|
||||||
growParagraph(text, len);
|
growParagraph(text, len);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//ограничение на размер куска текста в параграфе
|
||||||
|
if (textRaw && textRaw.length > maxParaTextLength) {
|
||||||
|
while (textRaw.length > 0) {
|
||||||
|
const textPart = textRaw.substring(0, maxParaTextLength);
|
||||||
|
textRaw = textRaw.substring(maxParaTextLength);
|
||||||
|
|
||||||
|
newParagraph();
|
||||||
|
growParagraph(textPart, textPart.length);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (inSubtitle) {
|
if (inSubtitle) {
|
||||||
curSubtitle.title += text;
|
curSubtitle.title += text;
|
||||||
} else if (inTitle) {
|
} else if (inTitle) {
|
||||||
@@ -536,7 +549,7 @@ export default class BookParser {
|
|||||||
tClose += (center ? '</center>' : '');
|
tClose += (center ? '</center>' : '');
|
||||||
|
|
||||||
if (text != ' ')
|
if (text != ' ')
|
||||||
growParagraph(`${tOpen}${text}${tClose}`, text.length);
|
growParagraph(`${tOpen}${text}${tClose}`, text.length, text);
|
||||||
else
|
else
|
||||||
growParagraph(' ', 1);
|
growParagraph(' ', 1);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user