Skip to content

Commit

Permalink
Merge pull request #76 from theslavicbear/epub-indent
Browse files Browse the repository at this point in the history
added indents for TOC for chyoa in epub format. closes #60
  • Loading branch information
theslavicbear authored Jul 17, 2021
2 parents 5843884 + 94e4e5b commit 4b6c3d9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Ebook-Publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def MakeEpub(site):
if i == 0:
c.append(epub.EpubHtml(title=site.chapters[i], file_name='Chapter '+str(i+1)+'.xhtml', lang='en'))
else:
c.append(epub.EpubHtml(title=site.chapters[i], file_name=str(site.depth[i-1])+'.xhtml', lang='en'))
c.append(epub.EpubHtml(title=site.chapters[i], file_name=str(site.depth[i-1])+'.xhtml', lang='en', tocTitle=str(' _'*int((len(site.depth[i-1])/2)+1))+' '+str(int((len(site.depth[i-1])/2)+2))+'.'+site.depth[i-1].split('.')[-1]+' '+site.chapters[i]))
c[i].content='<h2>\n'+site.chapters[i]+'\n</h2>\n'+str(site.epubrawstoryhtml[i])
elif type(site) is Nhentai.Nhentai:
c.append(epub.EpubHtml(title=site.chapters[i], file_name='Chapter '+str(i+1)+'.xhtml', lang='en'))
Expand Down
10 changes: 7 additions & 3 deletions EpubMaker/epub.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,15 @@ def add_style_sheet(self, styleString):

class EpubHtml:

def __init__(self, title='Title', file_name='file_name.xhtml', lang='lang'):
def __init__(self, title='Title', file_name='file_name.xhtml', lang='lang', tocTitle=None):
self.title = title
self.file_name = file_name
self.lang = lang
self.content=''
if tocTitle is None:
self.tocTitle=self.title
else:
self.tocTitle=tocTitle

#These classes do nothing, but maintain compatibility with my current implementation
class EpubNcx:
Expand Down Expand Up @@ -90,7 +94,7 @@ def write_epub(title, book):
elif isTOC:
navstring = '<?xml version="1.0" encoding="utf-8"?>\n <!DOCTYPE html>\n <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" lang="en" xml:lang="en">\n <head>\n <title>'+book.title+'</title>\n <link rel="stylesheet" type="text/css" href="style.css" />\n </head>\n <body>\n <nav id="id" role="doc-toc" epub:type="toc">\n <h2>'+book.title+'</h2>\n <ol>\n'
for item in book.toc:
navstring += '<li>\n<a href="'+item.file_name+'">'+item.title+'</a>\n</li>\n'
navstring += '<li>\n<a href="'+item.file_name+'">'+item.tocTitle+'</a>\n</li>\n'
navstring += '</ol>\n</nav>\n</body>\n</html>'
Zip.writestr('EPUB/nav.xhtml', navstring)
opf_content +='</manifest>\n<spine toc="ncx">\n'
Expand All @@ -107,4 +111,4 @@ def write_epub(title, book):
Zip.writestr('EPUB/content.opf', opf_content)

if __name__ == '__main__':
print('You have mistakenly run this file, epub.py. It is not meant to be run. It must be impported by another python file (or an implementation can be added to this __main__ section).')
print('You have mistakenly run this file, epub.py. It is not meant to be run. It must be imported by another python file (or an implementation can be added to this __main__ section).')

0 comments on commit 4b6c3d9

Please sign in to comment.