Реструктуризация
This commit is contained in:
@@ -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;
|
||||
Reference in New Issue
Block a user