mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix bug #4411: Include chapter headins when generating toc from pml files.
This commit is contained in:
parent
598094e168
commit
a380a7a284
@ -42,7 +42,9 @@ class Writer(FormatWriter):
|
||||
pml = unicode(pmlmlizer.extract_content(oeb_book, self.opts)).encode('cp1252', 'replace')
|
||||
|
||||
text, text_sizes = self._text(pml)
|
||||
chapter_index = self._index_item(r'(?s)\\C(?P<val>\d)="(?P<text>.+?)"', pml)
|
||||
chapter_index = self._index_item(r'(?s)\\C(?P<val>[0-4)="(?P<text>.+?)"', pml)
|
||||
chapter_index += self.index_item(r'(?s)\\X(?P<val>[0-4])(?P<text>.+?)\\X[0-4]', pml)
|
||||
chapter_index += self.index_item(r'(?s)\\x(?P<text>.+?)\\x', pml)
|
||||
link_index = self._index_item(r'(?s)\\Q="(?P<text>.+?)"', pml)
|
||||
images = self._images(oeb_book.manifest, pmlmlizer.image_hrefs)
|
||||
metadata = [self._metadata(metadata)]
|
||||
|
@ -171,6 +171,9 @@ class PML_HTMLizer(object):
|
||||
# &. It will display as &
|
||||
pml = pml.replace('&', '&')
|
||||
|
||||
pml = re.sub(r'(?<=\\x)(?P<text>.*?)(?=\\x)', lambda match: '="%s"%s' % (self.strip_pml(match.group('text')), match.group('text')), pml)
|
||||
pml = re.sub(r'(?<=\\X[0-4])(?P<text>.*?)(?=\\X[0-4])', lambda match: '="%s"%s' % (self.strip_pml(match.group('text')), match.group('text')), pml)
|
||||
|
||||
pml = re.sub(r'\\a(?P<num>\d{3})', lambda match: '&#%s;' % match.group('num'), pml)
|
||||
pml = re.sub(r'\\U(?P<num>[0-9a-f]{4})', lambda match: '%s' % my_unichr(int(match.group('num'), 16)), pml)
|
||||
|
||||
@ -178,6 +181,19 @@ class PML_HTMLizer(object):
|
||||
|
||||
return pml
|
||||
|
||||
def strip_pml(self, pml):
|
||||
pml = re.sub(r'\\.\d=""', '', pml)
|
||||
pml = re.sub(r'\\.=""', '', pml)
|
||||
pml = re.sub(r'\\.\d', '', pml)
|
||||
pml = re.sub(r'\\.', '', pml)
|
||||
pml = re.sub(r'\\a\d\d\d', '', pml)
|
||||
pml = re.sub(r'\\U\d\d\d\d', '', pml)
|
||||
pml.replace('\r\n', ' ')
|
||||
pml.replace('\n', ' ')
|
||||
pml.replace('\r', ' ')
|
||||
|
||||
return pml
|
||||
|
||||
def cleanup_html(self, html):
|
||||
old = html
|
||||
html = self.cleanup_html_remove_redundant(html)
|
||||
@ -503,9 +519,9 @@ class PML_HTMLizer(object):
|
||||
if c == '\\':
|
||||
c = line.read(1)
|
||||
|
||||
if c in 'xqcrtTiIuobBlk':
|
||||
if c in 'qcrtTiIuobBlk':
|
||||
text = self.process_code(c, line)
|
||||
elif c in 'FSX':
|
||||
elif c in 'FS':
|
||||
l = line.read(1)
|
||||
if '%s%s' % (c, l) == 'Fn':
|
||||
text = self.process_code('Fn', line, 'fn')
|
||||
@ -515,8 +531,24 @@ class PML_HTMLizer(object):
|
||||
text = self.process_code('SB', line)
|
||||
elif '%s%s' % (c, l) == 'Sd':
|
||||
text = self.process_code('Sd', line, 'sb')
|
||||
elif c in 'xXC':
|
||||
# The PML was modified eariler so x and X put the text
|
||||
# inside of ="" so we don't have do special processing
|
||||
# for C.
|
||||
t = ''
|
||||
if c in 'XC':
|
||||
level = line.read(1)
|
||||
id = 'pml_toc-%s' % len(self.toc)
|
||||
value = self.code_value(line)
|
||||
if c == 'x':
|
||||
t = self.process_code(c, line)
|
||||
elif c == 'X':
|
||||
t = self.process_code('%s%s' % (c, level), line)
|
||||
if not value or value == '':
|
||||
text = t
|
||||
else:
|
||||
text = self.process_code('%s%s' % (c, l), line)
|
||||
self.toc.add_item(os.path.basename(self.file_name), id, value)
|
||||
text = '<span id="%s"></span>%s' % (id, t)
|
||||
elif c == 'm':
|
||||
empty = False
|
||||
src = self.code_value(line)
|
||||
@ -528,11 +560,6 @@ class PML_HTMLizer(object):
|
||||
elif c == 'p':
|
||||
empty = False
|
||||
text = '<br /><br style="page-break-after: always;" />'
|
||||
elif c == 'C':
|
||||
line.read(1)
|
||||
id = 'pml_toc-%s' % len(self.toc)
|
||||
self.toc.add_item(os.path.basename(self.file_name), id, self.code_value(line))
|
||||
text = '<span id="%s"></span>' % id
|
||||
elif c == 'n':
|
||||
pass
|
||||
elif c == 'w':
|
||||
|
@ -233,7 +233,7 @@ class PMLMLizer(object):
|
||||
w += '="50%"'
|
||||
text.append(w)
|
||||
toc_id = elem.attrib.get('id', None)
|
||||
if toc_id:
|
||||
if toc_id and tag not in ('h1', 'h2','h3','h4','h5','h6',):
|
||||
if self.toc.get(page.href, None):
|
||||
toc_title = self.toc[page.href].get(toc_id, None)
|
||||
if toc_title:
|
||||
|
Loading…
x
Reference in New Issue
Block a user