Fixing &ndsp; problem in opf file.

This commit is contained in:
Vahagn Khachatryan
2019-01-23 18:36:13 +00:00
parent 20b2657440
commit de9eb51894

View File

@@ -7,6 +7,10 @@ var xmlSerializer = new XMLSerializer();
// var DOMParser = require('xmldom').DOMParser
var domParser = new DOMParser();
var generatedBufferType = 'blob'
var opf_file_base = 'epub_cA3Wt6s6'
var opf_file_name = opf_file_base+'.opf'
var ncx_file_name = opf_file_base+'.ncx'
var nav_file_name = opf_file_base+'.xhtml'
/**
* I hope JS is single threaded and not preemptive.
@@ -14,7 +18,9 @@ var generatedBufferType = 'blob'
* @param {*} text
*/
var escape = function (text){
return $('<div>').text(text).html()
let html = $('<div>').text(text).html()
html = html.replace(/&nbsp;/gi, " ")
return html
}
var html2txt = function (html) {
@@ -339,15 +345,15 @@ class EpubMeta{
}
opf(){
return new EpubOpf("content.opf", this)
return new EpubOpf(opf_file_name, this)
}
ncx(){
return new EpubNcx("content.ncx", this)
return new EpubNcx(ncx_file_name, this)
}
nav(){
return new EpubNav("content.xhtml", this)
return new EpubNav(nav_file_name, this)
}
}
@@ -365,7 +371,7 @@ class EpubWriter{
`<?xml version='1.0' encoding='utf-8'?>
<container xmlns="urn:oasis:names:tc:opendocument:xmlns:container" version="1.0">
<rootfiles>
<rootfile media-type="application/oebps-package+xml" full-path="EPUB/content.opf"/>
<rootfile media-type="application/oebps-package+xml" full-path="EPUB/${opf_file_name}"/>
</rootfiles>
</container>
` );