Рефакторинг

This commit is contained in:
Book Pauk
2020-12-15 21:56:14 +07:00
parent e48af7ee7d
commit 37e14b397c
2 changed files with 15 additions and 17 deletions

View File

@@ -195,9 +195,7 @@ class ContentsPage extends Vue {
const ims = parsed.images; const ims = parsed.images;
for (i = 0; i < ims.length; i++) { for (i = 0; i < ims.length; i++) {
const image = ims[i]; const image = ims[i];
let id = image.href; let {id} = parsed.imageHrefToId(image.href);
if (id[0] == "#")
id = id.substr(1);
const label = `Изображение ${image.num}`; const label = `Изображение ${image.num}`;
const indentStyle = getIndentStyle(1); const indentStyle = getIndentStyle(1);

View File

@@ -497,6 +497,15 @@ export default class BookParser {
return {fb2}; return {fb2};
} }
imageHrefToId(id) {
let local = false;
if (id[0] == '#') {
id = id.substr(1);
local = true;
}
return {id, local};
}
findParaIndex(bookPos) { findParaIndex(bookPos) {
let result = undefined; let result = undefined;
//дихотомия //дихотомия
@@ -562,28 +571,19 @@ export default class BookParser {
case 'image': { case 'image': {
let attrs = sax.getAttrsSync(tail); let attrs = sax.getAttrsSync(tail);
if (attrs.href && attrs.href.value) { if (attrs.href && attrs.href.value) {
let id = attrs.href.value; image = this.imageHrefToId(attrs.href.value);
let local = false; image.inline = false;
if (id[0] == '#') {
id = id.substr(1);
local = true;
}
image = {local, inline: false, id};
} }
break; break;
} }
case 'image-inline': { case 'image-inline': {
let attrs = sax.getAttrsSync(tail); let attrs = sax.getAttrsSync(tail);
if (attrs.href && attrs.href.value) { if (attrs.href && attrs.href.value) {
let id = attrs.href.value; const img = this.imageHrefToId(attrs.href.value);
let local = false; img.inline = true;
if (id[0] == '#') {
id = id.substr(1);
local = true;
}
result.push({ result.push({
style: Object.assign({}, style), style: Object.assign({}, style),
image: {local, inline: true, id}, image: img,
text: '' text: ''
}); });
} }