Adding title and css to xhtmls.

This commit is contained in:
Vahagn Khachatryan
2019-01-11 00:15:59 +00:00
parent 99edfd4794
commit f679c253a7
2 changed files with 41 additions and 8 deletions

View File

@@ -52,14 +52,26 @@ class EpubXhtml{
let html = textDecoder.decode(content);
let dom = domParser.parseFromString(html, 'text/html');
let xml = xmlSerializer.serializeToString(dom);
// let cnt = `<?xml version="1.0" encoding="utf-8" standalone="no"?>
// <!DOCTYPE html>
let cnt = `<?xml version="1.0" encoding="utf-8" standalone="no"?>
let css_link = ''
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>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:epub="http://www.idpf.org/2007/ops">
<head>
<title></title>
<title>${title}</title>
${css_link}
</head>
<body>
${xml}
@@ -229,15 +241,13 @@ class EpubMeta{
}
addManifest(filename, mime){
let key = filename
if (mime && mime.startsWith('text/html')){
let o = new EpubXhtml(filename)
this.override[key] = o
filename = o.filename
this.override[filename] = o
mime = o.mime
}
let id = 'id_' + filename.replace(/[^a-z0-9]/gi, '_').toLowerCase()
this.manifest[key] =
this.manifest[filename] =
{
filename : filename,
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){
return this.manifest[filename].id
}

View File

@@ -243,6 +243,20 @@ function fillManifest(epub, book)
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)
{
for (let i in book.book_toc){
@@ -278,6 +292,8 @@ function createEpub(book, epub){
// NCX and NAV files.
fillToc(epub, book)
fillHtmlComponents(epub, book)
for (let url in book.book_files){
file = book.book_files[url]
epub.addFile(file.filename, file.body)