Esempio n. 1
0
def opf(docheader, style='default'):
    from core.args import args
    from core.meta import get_uid, date, description, isbn, sort_author
    with open(prog_path+STYLES_PATH+'/'+style+'/'+OPF_HEADER, mode='r') as opf_header_file:
        content = opf_header_file.read()
    content = content.replace('UID', get_uid())
    content += '<dc:Title>'+title(docheader)+'</dc:Title>\n'
    content += '<dc:Language>'+args.l+'</dc:Language>\n'
    content += '<dc:Creator '
    if sort_author():
        content += 'opf:file-as="'+sort_author()+'" '
    content += 'opf:role="aut">'+author(docheader)+'</dc:Creator>\n'
    if date():
        content += '<dc:Date>'+date()+'</dc:Date>\n'
    if description():
        content += '<dc:Description>'+description()+'</dc:Description>\n'
    content += '<dc:Identifier id="uid">'+get_uid()+'</dc:Identifier>\n'
    if isbn():
        content += '<dc:Identifier opf:scheme="ISBN">'+isbn()+'</dc:Identifier>\n'
    content += '</dc-metadata>\n'
    content += '<x-metadata>\n'
    content += '<EmbeddedCover>'+COVER_FILE+'</EmbeddedCover>\n'
    content += '<output encoding="utf-8"></output>\n'
    content += '</x-metadata>\n'
    content += '<meta name="cover" content="my-cover-image" />\n'
    content += '</metadata>\n'
    content += '<manifest>\n'
    content += '<item id="my-cover-image" media-type="image/jpeg" href="'+COVER_FILE+'"/>\n'
    content += '<item id="titlepage" media-type="text/x-oeb1-document" href="'+TITLEPAGE_FILE+'"/>\n'
    content += '<item id="toc" media-type="application/x-dtbncx+xml" href="'+TOC_NCX_FILE+'"/>\n'
    content += '<item id="tocpage" media-type="text/x-oeb1-document" href="'+TOCPAGE_FILE+'"/>\n'
    content += '<item id="body" media-type="text/x-oeb1-document" href="'+BODY_FILE+'"/>\n'
    content += '</manifest>\n'
    content += '<spine toc="toc">\n'
    content += '<itemref idref="titlepage"/>\n'
    content += '<itemref idref="tocpage"/>\n'
    content += '<itemref idref="body"/>\n'
    content += '</spine>\n'
    content += '<guide>\n'
    content += '<reference type="text" title="Go to Beginning" href="'+TITLEPAGE_FILE+'"/>\n'
    content += '<reference type="toc" title="Table of Contents" href="'+TOCPAGE_FILE+'"/>\n'
    content += '</guide>\n'
    content += '</package>'
    return content
Esempio n. 2
0
def toc_ncx(docheader, style='default'):
    from core.meta import get_uid
    with open(prog_path+STYLES_PATH+'/'+style+'/'+NCX_HEADER, mode='r') as ncx_header_file:
        content = ncx_header_file.read()
    content = content.replace('UID', get_uid())
    content += '<docTitle><text>'+title(docheader)+'</text></docTitle>\n'
    content += '<docAuthor><text>'+author(docheader)+'</text></docAuthor>\n'
    content += '<navMap>\n'
    block=docheader.mainmatter.dlink
    while block.rlink:
        content += '<navPoint class="chapter" id="'+block.nr()+'" playOrder="'+block.nr()+'"><navLabel><text>'+reformat_content(block)+'</text></navLabel><content src='+BODY_FILE+'#'+block.nr()+' /></navPoint>\n'
        block = block.rlink
    content += '<navPoint class="chapter" id="'+block.nr()+'" playOrder="'+block.nr()+'"><navLabel><text>'+reformat_content(block)+'</text></navLabel><content src='+BODY_FILE+'#'+block.nr()+' /></navPoint>\n'
    return content + '</navMap>\n</ncx>'