Adding title and css to xhtmls.
This commit is contained in:
33
src/epub.js
33
src/epub.js
@@ -52,14 +52,26 @@ class EpubXhtml{
|
|||||||
let html = textDecoder.decode(content);
|
let html = textDecoder.decode(content);
|
||||||
let dom = domParser.parseFromString(html, 'text/html');
|
let dom = domParser.parseFromString(html, 'text/html');
|
||||||
let xml = xmlSerializer.serializeToString(dom);
|
let xml = xmlSerializer.serializeToString(dom);
|
||||||
// let cnt = `<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
|
||||||
// <!DOCTYPE html>
|
let css_link = ''
|
||||||
let cnt = `<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
if (this.css) {
|
||||||
|
for (let i in this.css){
|
||||||
|
css_link += ` <link href="${this.css[i]}" rel="stylesheet" type="text/css"/>\n`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let title = ''
|
||||||
|
if (this.title) {
|
||||||
|
title = this.title
|
||||||
|
}
|
||||||
|
|
||||||
|
let cnt = `<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml"
|
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||||
xmlns:epub="http://www.idpf.org/2007/ops">
|
xmlns:epub="http://www.idpf.org/2007/ops">
|
||||||
<head>
|
<head>
|
||||||
<title></title>
|
<title>${title}</title>
|
||||||
|
${css_link}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
${xml}
|
${xml}
|
||||||
@@ -229,15 +241,13 @@ class EpubMeta{
|
|||||||
}
|
}
|
||||||
|
|
||||||
addManifest(filename, mime){
|
addManifest(filename, mime){
|
||||||
let key = filename
|
|
||||||
if (mime && mime.startsWith('text/html')){
|
if (mime && mime.startsWith('text/html')){
|
||||||
let o = new EpubXhtml(filename)
|
let o = new EpubXhtml(filename)
|
||||||
this.override[key] = o
|
this.override[filename] = o
|
||||||
filename = o.filename
|
|
||||||
mime = o.mime
|
mime = o.mime
|
||||||
}
|
}
|
||||||
let id = 'id_' + filename.replace(/[^a-z0-9]/gi, '_').toLowerCase()
|
let id = 'id_' + filename.replace(/[^a-z0-9]/gi, '_').toLowerCase()
|
||||||
this.manifest[key] =
|
this.manifest[filename] =
|
||||||
{
|
{
|
||||||
filename : filename,
|
filename : filename,
|
||||||
mime : mime,
|
mime : mime,
|
||||||
@@ -245,6 +255,13 @@ class EpubMeta{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addHtmlComponents(filename, title, css){
|
||||||
|
if (filename in this.override){
|
||||||
|
this.override[filename].title = title
|
||||||
|
this.override[filename].css = css
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
getId(filename){
|
getId(filename){
|
||||||
return this.manifest[filename].id
|
return this.manifest[filename].id
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -243,6 +243,20 @@ function fillManifest(epub, book)
|
|||||||
epub.meta.addCover(f.filename)
|
epub.meta.addCover(f.filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function fillHtmlComponents(epub, book)
|
||||||
|
{
|
||||||
|
for (let i in book.book_info.chapters){
|
||||||
|
let url = book.book_info.chapters[i]
|
||||||
|
let chapter = book.chapter_info[url]
|
||||||
|
|
||||||
|
css = []
|
||||||
|
for (let i in chapter.stylesheets){
|
||||||
|
css.push(chapter.stylesheets[i].full_path)
|
||||||
|
}
|
||||||
|
epub.meta.addHtmlComponents(chapter.full_path, chapter.title, css)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function fillToc(epub, book)
|
function fillToc(epub, book)
|
||||||
{
|
{
|
||||||
for (let i in book.book_toc){
|
for (let i in book.book_toc){
|
||||||
@@ -278,6 +292,8 @@ function createEpub(book, epub){
|
|||||||
// NCX and NAV files.
|
// NCX and NAV files.
|
||||||
fillToc(epub, book)
|
fillToc(epub, book)
|
||||||
|
|
||||||
|
fillHtmlComponents(epub, book)
|
||||||
|
|
||||||
for (let url in book.book_files){
|
for (let url in book.book_files){
|
||||||
file = book.book_files[url]
|
file = book.book_files[url]
|
||||||
epub.addFile(file.filename, file.body)
|
epub.addFile(file.filename, file.body)
|
||||||
|
|||||||
Reference in New Issue
Block a user