Fix tocpage links and correct index04 vs index, issue #320.

This commit is contained in:
Jim Miller 2018-07-17 10:58:13 -05:00
parent aac7b5912f
commit def6b3991f
8 changed files with 42 additions and 48 deletions

View file

@ -400,16 +400,18 @@ chapter_title_strip_pattern:^[0-9]+[\.: -]+(?=[^0-9]|$)
mark_new_chapters:false mark_new_chapters:false
## chapter title patterns use python template substitution. The ## chapter title patterns use python template substitution. The
## ${index} is the 'chapter' number and ${title} is the chapter title, ## ${number} is the 'chapter' number and ${title} is the chapter
## after applying chapter_title_strip_pattern. Those are the only ## title, after applying chapter_title_strip_pattern. ${index04} is
## variables available. ## chapter number padded with leading zeros (mostly for internal use)
## such as 0001. ${index} == ${number} for backward compatibility. A
## few site adapters add additional chapter metadata.
## The basic pattern used when not using add_chapter_numbers or ## The basic pattern used when not using add_chapter_numbers or
## mark_new_chapters ## mark_new_chapters
chapter_title_def_pattern:${title} chapter_title_def_pattern:${title}
## Pattern used with add_chapter_numbers, but not mark_new_chapters ## Pattern used with add_chapter_numbers, but not mark_new_chapters
chapter_title_add_pattern:${index}. ${title} chapter_title_add_pattern:${number}. ${title}
## Pattern used with mark_new_chapters, but not add_chapter_numbers ## Pattern used with mark_new_chapters, but not add_chapter_numbers
## (new) is just text and can be changed. ## (new) is just text and can be changed.
@ -417,7 +419,7 @@ chapter_title_new_pattern:(new) ${title}
## Pattern used with add_chapter_numbers and mark_new_chapters ## Pattern used with add_chapter_numbers and mark_new_chapters
## (new) is just text and can be changed. ## (new) is just text and can be changed.
chapter_title_addnew_pattern:${index}. (new) ${title} chapter_title_addnew_pattern:${number}. (new) ${title}
## Uses a python template substitution. The ${title} is the default ## Uses a python template substitution. The ${title} is the default
## title of a new anthology, <series name> in the case of a series, or ## title of a new anthology, <series name> in the case of a series, or
@ -684,7 +686,7 @@ use_threadmark_wordcounts:true
## chapter_title_*_pattern settings. ## chapter_title_*_pattern settings.
## Example: ## Example:
#tocpage_entry: #tocpage_entry:
# <a href="#section${index}">${chapter}</a> ${date} ${kwords}<br /> # <a href="#section${index04}">${chapter}</a> ${date} ${kwords}<br />
## The 'date' value for chapters mentioned above can be formated with ## The 'date' value for chapters mentioned above can be formated with
## datethreadmark_format. Otherwise it will default to ## datethreadmark_format. Otherwise it will default to

View file

@ -75,7 +75,7 @@ class BaseSiteAdapter(Configurable):
self.story = Story(configuration) self.story = Story(configuration)
self.story.setMetadata('site',self.getConfigSection()) self.story.setMetadata('site',self.getConfigSection())
self.story.setMetadata('dateCreated',datetime.now()) self.story.setMetadata('dateCreated',datetime.now())
self.chapterUrls = [] # tuples of (chapter title,chapter url) self.chapterUrls = [] # dicts of (chapter title,chapter url)
self.chapterFirst = None self.chapterFirst = None
self.chapterLast = None self.chapterLast = None
self.oldchapters = None self.oldchapters = None
@ -150,7 +150,7 @@ class BaseSiteAdapter(Configurable):
if self.ignore_chapter_url_list == None: if self.ignore_chapter_url_list == None:
self.ignore_chapter_url_list = [ self.normalize_chapterurl(u) for u in self.getConfig('ignore_chapter_url_list').splitlines() ] self.ignore_chapter_url_list = [ self.normalize_chapterurl(u) for u in self.getConfig('ignore_chapter_url_list').splitlines() ]
if self.normalize_chapterurl(url) not in self.ignore_chapter_url_list: if self.normalize_chapterurl(url) not in self.ignore_chapter_url_list:
meta = dict(othermeta) # copy meta = defaultdict(unicode,othermeta) # copy othermeta
meta.update({'title':stripHTML(title),'url':url}) # after other to make sure they are set meta.update({'title':stripHTML(title),'url':url}) # after other to make sure they are set
self.chapterUrls.append(meta) self.chapterUrls.append(meta)
self.story.setMetadata('numChapters', self.num_chapters()) self.story.setMetadata('numChapters', self.num_chapters())
@ -166,7 +166,7 @@ class BaseSiteAdapter(Configurable):
return self.chapterUrls[i].get(attr,None) return self.chapterUrls[i].get(attr,None)
def get_chapters(self): def get_chapters(self):
return copy.copy(self.chapterUrls) return copy.deepcopy(self.chapterUrls)
def del_chapter(self,i): def del_chapter(self,i):
del self.chapterUrls[i] del self.chapterUrls[i]

View file

@ -403,16 +403,18 @@ chapter_title_strip_pattern:^[0-9]+[\.: -]+(?=[^0-9]|$)
mark_new_chapters:false mark_new_chapters:false
## chapter title patterns use python template substitution. The ## chapter title patterns use python template substitution. The
## ${index} is the 'chapter' number and ${title} is the chapter title, ## ${number} is the 'chapter' number and ${title} is the chapter
## after applying chapter_title_strip_pattern. Those are the only ## title, after applying chapter_title_strip_pattern. ${index04} is
## variables available. ## chapter number padded with leading zeros (mostly for internal use)
## such as 0001. ${index} == ${number} for backward compatibility. A
## few site adapters add additional chapter metadata.
## The basic pattern used when not using add_chapter_numbers or ## The basic pattern used when not using add_chapter_numbers or
## mark_new_chapters ## mark_new_chapters
chapter_title_def_pattern:${title} chapter_title_def_pattern:${title}
## Pattern used with add_chapter_numbers, but not mark_new_chapters ## Pattern used with add_chapter_numbers, but not mark_new_chapters
chapter_title_add_pattern:${index}. ${title} chapter_title_add_pattern:${number}. ${title}
## Pattern used with mark_new_chapters, but not add_chapter_numbers ## Pattern used with mark_new_chapters, but not add_chapter_numbers
## (new) is just text and can be changed. ## (new) is just text and can be changed.
@ -420,7 +422,7 @@ chapter_title_new_pattern:(new) ${title}
## Pattern used with add_chapter_numbers and mark_new_chapters ## Pattern used with add_chapter_numbers and mark_new_chapters
## (new) is just text and can be changed. ## (new) is just text and can be changed.
chapter_title_addnew_pattern:${index}. (new) ${title} chapter_title_addnew_pattern:${number}. (new) ${title}
## Reorder ships so b/a and c/b/a become a/b and a/b/c. '/' is no ## Reorder ships so b/a and c/b/a become a/b and a/b/c. '/' is no
## longer hard coded and can be changed and added to with ## longer hard coded and can be changed and added to with
@ -711,7 +713,7 @@ use_threadmark_wordcounts:true
## chapter_title_*_pattern settings. ## chapter_title_*_pattern settings.
## Example: ## Example:
#tocpage_entry: #tocpage_entry:
# <a href="#section${index}">${chapter}</a> ${date} ${kwords}<br /> # <a href="#section${index04}">${chapter}</a> ${date} ${kwords}<br />
## The 'date' value for chapters mentioned above can be formated with ## The 'date' value for chapters mentioned above can be formated with
## datethreadmark_format. Otherwise it will default to ## datethreadmark_format. Otherwise it will default to

View file

@ -1020,8 +1020,12 @@ class Story(Configurable):
'toctitle':chapter['title'], 'toctitle':chapter['title'],
'new':newchap, 'new':newchap,
'number':len(self.chapters)+1, 'number':len(self.chapters)+1,
'index':len(self.chapters)+1, 'index04':"%04d"%(len(self.chapters)+1)})
'0index':"%04d"%(len(self.chapters)+1)}) ## Due to poor planning on my part, chapter_title_*_pattern
## expect index==1 while output settings expected index=0001.
## index04 is to disambiguate, but index is kept for users'
## pre-existing settings.
chapter['index']=chapter['index04']
self.chapters.append(chapter) self.chapters.append(chapter)
def getChapters(self,fortoc=False): def getChapters(self,fortoc=False):
@ -1065,22 +1069,17 @@ class Story(Configurable):
else: else:
usetempl = templ usetempl = templ
# logger.debug("chap(%s)"%chap) # logger.debug("chap(%s)"%chap)
# Chapter = namedtuple('Chapter', 'url title html origtitle toctitle new')
chapter = defaultdict(unicode,chap) chapter = defaultdict(unicode,chap)
chapter['chapter'] = chapter['title'] = usetempl.substitute(chap) ## Due to poor planning on my part,
chapter['origtitle'] = templ.substitute(chap) ## chapter_title_*_pattern expect index==1 not
chapter['toctitle'] = toctempl.substitute(chap) ## index=0001 like output settings. index04 is now
chapter['index'] = chap['number'] ## Due to poor planning on my part, chapter_title_*_pattern ## used, but index is still included for backward
retval.append(chapter) ## expect index==1 not index=0001 like output settings. ## compatibility.
# Chapter(chap.url, chapter['index'] = chapter['number']
# # 'new' chapter['chapter'] = chapter['title'] = usetempl.substitute(chapter)
# usetempl.substitute({'index':index+1,'title':chap.title}), chapter['origtitle'] = templ.substitute(chapter)
# chap.html, chapter['toctitle'] = toctempl.substitute(chapter)
# # 'orig' retval.append(chapter)
# templ.substitute({'index':index+1,'title':chap.title}),
# # 'toc'
# toctempl.substitute({'index':index+1,'title':chap.title}),
# chap.new) )
else: else:
retval = self.chapters retval = self.chapters

View file

@ -118,7 +118,7 @@ ${value}<br />
''') ''')
self.EPUB_TOC_ENTRY = string.Template(''' self.EPUB_TOC_ENTRY = string.Template('''
<a href="file${index}.xhtml">${chapter}</a><br /> <a href="file${index04}.xhtml">${chapter}</a><br />
''') ''')
self.EPUB_TOC_PAGE_END = string.Template(''' self.EPUB_TOC_PAGE_END = string.Template('''
@ -540,12 +540,12 @@ div { margin: 0pt; padding: 0pt; }
for index, chap in enumerate(self.story.getChapters(fortoc=True)): for index, chap in enumerate(self.story.getChapters(fortoc=True)):
if chap['html']: if chap['html']:
i=index+1 i=index+1
items.append(("file%04d"%i, items.append(("file%s"%chap['index04'],
"OEBPS/file%04d.xhtml"%i, "OEBPS/file%s.xhtml"%chap['index04'],
"application/xhtml+xml", "application/xhtml+xml",
chap['title'])) chap['title']))
itemrefs.append("file%04d"%i) itemrefs.append("file%s"%chap['index04'])
chapurlmap[chap['url']]="file%04d.xhtml"%i # url -> relative epub file name. chapurlmap[chap['url']]="file%s.xhtml"%chap['index04'] # url -> relative epub file name.
if dologpage: if dologpage:
if self.getConfig("logpage_at_end") == "true": if self.getConfig("logpage_at_end") == "true":
@ -715,12 +715,6 @@ div { margin: 0pt; padding: 0pt; }
chap['title']=removeEntities(chap['title']) chap['title']=removeEntities(chap['title'])
chap['origchapter']=removeEntities(chap['origtitle']) chap['origchapter']=removeEntities(chap['origtitle'])
chap['tocchapter']=removeEntities(chap['toctitle']) chap['tocchapter']=removeEntities(chap['toctitle'])
# vals={'url':removeEntities(chap.url),
# 'chapter':removeEntities(chap.title),
# 'origchapter':removeEntities(chap.origtitle),
# 'tocchapter':removeEntities(chap.toctitle),
# 'index':"%04d"%(index+1),
# 'number':index+1}
# escape double quotes in all vals. # escape double quotes in all vals.
for k,v in chap.items(): for k,v in chap.items():
if isinstance(v,basestring): chap[k]=v.replace('"','&quot;') if isinstance(v,basestring): chap[k]=v.replace('"','&quot;')
@ -734,7 +728,7 @@ div { margin: 0pt; padding: 0pt; }
# (200k+) # (200k+)
fullhtml = re.sub(r'(</p>|<br ?/>)\n*',r'\1\n',fullhtml) fullhtml = re.sub(r'(</p>|<br ?/>)\n*',r'\1\n',fullhtml)
outputepub.writestr("OEBPS/file%04d.xhtml"%(index+1),fullhtml.encode('utf-8')) outputepub.writestr("OEBPS/file%s.xhtml"%chap['index04'],fullhtml.encode('utf-8'))
del fullhtml del fullhtml
if self.story.calibrebookmark: if self.story.calibrebookmark:

View file

@ -137,7 +137,7 @@ ${output_css}
## anchor to work. Which it does by default. This ## anchor to work. Which it does by default. This
## could also be made configurable if some user ## could also be made configurable if some user
## changed it. ## changed it.
chapurlmap[chap['url']]="#section%04d"%(index+1) # url -> index chapurlmap[chap['url']]="#section"%chap['index04'] # url -> index
for index, chap in enumerate(self.story.getChapters()): for index, chap in enumerate(self.story.getChapters()):
if chap['html']: if chap['html']:
@ -157,7 +157,6 @@ ${output_css}
logging.debug('Writing chapter text for: %s' % chap['title']) logging.debug('Writing chapter text for: %s' % chap['title'])
# vals={'url':chap.url, 'chapter':chap.title, 'index':"%04d"%(index+1), 'number':index+1}
self._write(out,CHAPTER_START.substitute(chap)) self._write(out,CHAPTER_START.substitute(chap))
self._write(out,chap_data) self._write(out,chap_data)
self._write(out,CHAPTER_END.substitute(chap)) self._write(out,CHAPTER_END.substitute(chap))

View file

@ -164,7 +164,6 @@ ${value}<br />
for index, chap in enumerate(self.story.getChapters()): for index, chap in enumerate(self.story.getChapters()):
if chap['html']: if chap['html']:
logger.debug('Writing chapter text for: %s' % chap['title']) logger.debug('Writing chapter text for: %s' % chap['title'])
# vals={'url':chap.url, 'chapter':chap.title, 'index':"%04d"%(index+1), 'number':index+1}
fullhtml = CHAPTER_START.substitute(chap) + chap['html'] + CHAPTER_END.substitute(chap) fullhtml = CHAPTER_START.substitute(chap) + chap['html'] + CHAPTER_END.substitute(chap)
# ffnet(& maybe others) gives the whole chapter text # ffnet(& maybe others) gives the whole chapter text
# as one line. This causes problems for nook(at # as one line. This causes problems for nook(at

View file

@ -157,7 +157,6 @@ End file.
for index, chap in enumerate(self.story.getChapters()): for index, chap in enumerate(self.story.getChapters()):
if chap['html']: if chap['html']:
logging.debug('Writing chapter text for: %s' % chap['title']) logging.debug('Writing chapter text for: %s' % chap['title'])
# vals={'url':chap.url, 'chapter':chap.title, 'index':"%04d"%(index+1), 'number':index+1}
self._write(out,self.lineends(self.wraplines(removeAllEntities(CHAPTER_START.substitute(chap))))) self._write(out,self.lineends(self.wraplines(removeAllEntities(CHAPTER_START.substitute(chap)))))
self._write(out,self.lineends(html2text(chap['html'],bodywidth=self.wrap_width))) self._write(out,self.lineends(html2text(chap['html'],bodywidth=self.wrap_width)))
self._write(out,self.lineends(self.wraplines(removeAllEntities(CHAPTER_END.substitute(chap))))) self._write(out,self.lineends(self.wraplines(removeAllEntities(CHAPTER_END.substitute(chap)))))