From 2fcdbca76609e95ec87235aa8b6b02202ade5564 Mon Sep 17 00:00:00 2001 From: Jim Miller Date: Sun, 30 Sep 2012 15:47:18 -0500 Subject: [PATCH] Add add_chapter_numbers: toconly option. --- defaults.ini | 15 +++++++++------ fanficdownloader/story.py | 7 ++++--- fanficdownloader/writers/base_writer.py | 2 +- fanficdownloader/writers/writer_epub.py | 2 +- plugin-defaults.ini | 13 +++++++------ 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/defaults.ini b/defaults.ini index 0ae23ba..a9a8f49 100644 --- a/defaults.ini +++ b/defaults.ini @@ -184,10 +184,14 @@ keep_summary_html:true ## Don't like the numbers at the start of chapter titles on some ## sites? You can use strip_chapter_numbers to strip them off. Just ## want to make them all look the same? Strip them off, then add them -## back on with add_chapter_numbers. Don't like the way it strips -## numbers or adds them back? See chapter_title_strip_pattern and -## chapter_title_add_pattern. +## back on with add_chapter_numbers:true. Only want them added back +## on for Table of Contents(toc)? Use add_chapter_numbers:toconly. +## (toconly doesn't work on mobi output.) Don't like the way it +## strips numbers or adds them back? See chapter_title_strip_pattern +## and chapter_title_add_pattern. strip_chapter_numbers:false + +## add_chapter_numbers can be true, false or toconly add_chapter_numbers:false ## (Two versions of chapter_title_strip_pattern are shown below. You @@ -556,9 +560,8 @@ cliches_label:Character Cliches ## specific entries to titlepage/logpage without having to copy the ## entire titlepage_entries line. (But if you want them higher than ## the end, you will need to copy titlepage_entries.) -#extra_titlepage_entries: themes,hermiones,dracos,timeline,cliches - -## adds to include_subject_tags instead of replacing it. +#extra_titlepage_entries: themes,timeline,cliches +#extra_logpage_entries: themes,timeline,cliches #extra_subject_tags: themes,timeline,cliches [erosnsappho.sycophanthex.com] diff --git a/fanficdownloader/story.py b/fanficdownloader/story.py index 733d835..b36dbfa 100644 --- a/fanficdownloader/story.py +++ b/fanficdownloader/story.py @@ -411,11 +411,12 @@ class Story(Configurable): title = re.sub(self.getConfig('chapter_title_strip_pattern'),"",title) self.chapters.append( (title,html) ) - def getChapters(self): + def getChapters(self,fortoc=False): "Chapters will be tuples of (title,html)" retval = [] - if self.getConfig('add_chapter_numbers') and \ - self.getConfig('chapter_title_add_pattern'): + if (self.getConfig('add_chapter_numbers') == "true" \ + or (self.getConfig('add_chapter_numbers') == "toconly" and fortoc)) \ + and self.getConfig('chapter_title_add_pattern'): for index, (title,html) in enumerate(self.chapters): retval.append( (string.Template(self.getConfig('chapter_title_add_pattern')).substitute({'index':index+1,'title':title}),html) ) else: diff --git a/fanficdownloader/writers/base_writer.py b/fanficdownloader/writers/base_writer.py index 9832871..657625d 100644 --- a/fanficdownloader/writers/base_writer.py +++ b/fanficdownloader/writers/base_writer.py @@ -148,7 +148,7 @@ class BaseStoryWriter(Configurable): if len(self.story.getChapters()) > 1 and self.getConfig("include_tocpage") and not self.metaonly : self._write(out,START.substitute(self.story.getAllMetadata())) - for index, (title,html) in enumerate(self.story.getChapters()): + for index, (title,html) in enumerate(self.story.getChapters(fortoc=True)): if html: self._write(out,ENTRY.substitute({'chapter':title, 'index':"%04d"%(index+1)})) diff --git a/fanficdownloader/writers/writer_epub.py b/fanficdownloader/writers/writer_epub.py index 4f92643..036a1dd 100644 --- a/fanficdownloader/writers/writer_epub.py +++ b/fanficdownloader/writers/writer_epub.py @@ -451,7 +451,7 @@ div { margin: 0pt; padding: 0pt; } items.append(("log_page","OEBPS/log_page.xhtml","application/xhtml+xml","Update Log")) itemrefs.append("log_page") - for index, (title,html) in enumerate(self.story.getChapters()): + for index, (title,html) in enumerate(self.story.getChapters(fortoc=True)): if html: i=index+1 items.append(("file%04d"%i, diff --git a/plugin-defaults.ini b/plugin-defaults.ini index 3a7f6af..d94cafe 100644 --- a/plugin-defaults.ini +++ b/plugin-defaults.ini @@ -168,10 +168,14 @@ keep_summary_html:true ## Don't like the numbers at the start of chapter titles on some ## sites? You can use strip_chapter_numbers to strip them off. Just ## want to make them all look the same? Strip them off, then add them -## back on with add_chapter_numbers. Don't like the way it strips -## numbers or adds them back? See chapter_title_strip_pattern and -## chapter_title_add_pattern. +## back on with add_chapter_numbers:true. Only want them added back +## on for Table of Contents(toc)? Use add_chapter_numbers:toconly. +## (toconly doesn't work on mobi output.) Don't like the way it +## strips numbers or adds them back? See chapter_title_strip_pattern +## and chapter_title_add_pattern. strip_chapter_numbers:false + +## add_chapter_numbers can be true, false or toconly add_chapter_numbers:false ## (Two versions of chapter_title_strip_pattern are shown below. You @@ -557,9 +561,6 @@ cliches_label:Character Cliches # themes=>#bcolumn,a # timeline=>#ccolumn,n -## adds to include_subject_tags instead of replacing it. -#extra_subject_tags: themes,timeline,cliches - [erosnsappho.sycophanthex.com] ## Site dedicated to these categories/characters/ships extracategories:Harry Potter