Добавил опцию "Инлайн в центр"

This commit is contained in:
Book Pauk
2019-02-20 21:39:17 +07:00
parent 8491c40890
commit 5f2206e766
7 changed files with 26 additions and 9 deletions

View File

@@ -5,7 +5,11 @@ import {sleep} from '../../../share/utils';
const maxImageLineCount = 100;
export default class BookParser {
constructor() {
constructor(settings) {
if (settings) {
this.showInlineImagesInCenter = settings.showInlineImagesInCenter;
}
// defaults
this.p = 30;// px, отступ параграфа
this.w = 300;// px, ширина страницы
@@ -151,10 +155,13 @@ export default class BookParser {
if (tag == 'image') {
let attrs = sax.getAttrsSync(tail);
if (attrs.href.value) {
if (inPara)
if (inPara && !this.showInlineImagesInCenter)
growParagraph(`<image-inline href="${attrs.href.value}"></image-inline>`, 0);
else
newParagraph(`<image href="${attrs.href.value}">${' '.repeat(maxImageLineCount)}</image>`, maxImageLineCount);
if (inPara && this.showInlineImagesInCenter)
newParagraph(' ', 1);
}
}

View File

@@ -18,7 +18,8 @@ const bmRecentStore = localForage.createInstance({
});
class BookManager {
async init() {
async init(settings) {
this.settings = settings;
this.books = {};
this.recent = {};
this.recentChanged1 = true;
@@ -131,7 +132,7 @@ class BookManager {
async parseBook(meta, data, callback) {
if (!this.books)
await this.init();
const parsed = new BookParser();
const parsed = new BookParser(this.settings);
const parsedMeta = await parsed.parse(data, callback);
const result = Object.assign({}, meta, parsedMeta, {