Fb2Parser.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. const XmlParser = require('../xml/XmlParser');
  2. class Fb2Parser extends XmlParser {
  3. bookInfo(fb2Object) {
  4. if (!fb2Object)
  5. fb2Object = this.toObject();
  6. //const result = {};
  7. }
  8. bookInfoList(fb2Object) {
  9. }
  10. toHtml(xmlString) {
  11. const substs = {
  12. '<subtitle>': '<p><b>',
  13. '</subtitle>': '</b></p>',
  14. '<empty-line/>': '<br>',
  15. '<strong>': '<b>',
  16. '</strong>': '</b>',
  17. '<emphasis>': '<i>',
  18. '</emphasis>': '</i>',
  19. '<stanza>': '<br>',
  20. '</stanza>': '',
  21. '<poem>': '<br>',
  22. '</poem>': '',
  23. '<cite>': '<i>',
  24. '</cite>': '</i>',
  25. '<table>': '<br>',
  26. '</table>': '',
  27. };
  28. for (const [tag, s] of Object.entries(substs)) {
  29. const r = new RegExp(`${tag}`, 'g');
  30. xmlString = xmlString.replace(r, s);
  31. }
  32. return xmlString;
  33. }
  34. }
  35. module.exports = Fb2Parser;