Реструктуризация

This commit is contained in:
Book Pauk
2022-11-10 00:51:18 +07:00
parent ec6b72868b
commit 1d99472ca1
2 changed files with 130 additions and 23 deletions

View File

@@ -1,28 +1,6 @@
const XmlParser = require('../xml/XmlParser');
class Fb2Parser {
constructor() {
this.xml = new XmlParser();
}
toString(options) {
return this.xml.toString(options);
}
fromString(fb2String) {
this.xml.fromString(fb2String);
return this;
}
toObject(options) {
return this.xml.toObject(options);
}
fromObject(fb2Object) {
this.xml.fromObject(fb2Object);
return this;
}
class Fb2Parser extends XmlParser {
bookInfo(fb2Object) {
if (!fb2Object)
fb2Object = this.toObject();
@@ -33,6 +11,33 @@ class Fb2Parser {
bookInfoList(fb2Object) {
}
toHtml(xmlString) {
const substs = {
'<subtitle>': '<p><b>',
'</subtitle>': '</b></p>',
'<empty-line/>': '<br>',
'<strong>': '<b>',
'</strong>': '</b>',
'<emphasis>': '<i>',
'</emphasis>': '</i>',
'<stanza>': '<br>',
'</stanza>': '',
'<poem>': '<br>',
'</poem>': '',
'<cite>': '<i>',
'</cite>': '</i>',
'<table>': '<br>',
'</table>': '',
};
for (const [tag, s] of Object.entries(substs)) {
const r = new RegExp(`${tag}`, 'g');
xmlString = xmlString.replace(r, s);
}
return xmlString;
}
}
module.exports = Fb2Parser;