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')
|
pml = unicode(pmlmlizer.extract_content(oeb_book, self.opts)).encode('cp1252', 'replace')
|
||||||
|
|
||||||
text, text_sizes = self._text(pml)
|
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)
|
link_index = self._index_item(r'(?s)\\Q="(?P<text>.+?)"', pml)
|
||||||
images = self._images(oeb_book.manifest, pmlmlizer.image_hrefs)
|
images = self._images(oeb_book.manifest, pmlmlizer.image_hrefs)
|
||||||
metadata = [self._metadata(metadata)]
|
metadata = [self._metadata(metadata)]
|
||||||
|
@ -171,6 +171,9 @@ class PML_HTMLizer(object):
|
|||||||
# &. It will display as &
|
# &. It will display as &
|
||||||
pml = pml.replace('&', '&')
|
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'\\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)
|
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
|
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):
|
def cleanup_html(self, html):
|
||||||
old = html
|
old = html
|
||||||
html = self.cleanup_html_remove_redundant(html)
|
html = self.cleanup_html_remove_redundant(html)
|
||||||
@ -503,9 +519,9 @@ class PML_HTMLizer(object):
|
|||||||
if c == '\\':
|
if c == '\\':
|
||||||
c = line.read(1)
|
c = line.read(1)
|
||||||
|
|
||||||
if c in 'xqcrtTiIuobBlk':
|
if c in 'qcrtTiIuobBlk':
|
||||||
text = self.process_code(c, line)
|
text = self.process_code(c, line)
|
||||||
elif c in 'FSX':
|
elif c in 'FS':
|
||||||
l = line.read(1)
|
l = line.read(1)
|
||||||
if '%s%s' % (c, l) == 'Fn':
|
if '%s%s' % (c, l) == 'Fn':
|
||||||
text = self.process_code('Fn', line, 'fn')
|
text = self.process_code('Fn', line, 'fn')
|
||||||
@ -515,8 +531,24 @@ class PML_HTMLizer(object):
|
|||||||
text = self.process_code('SB', line)
|
text = self.process_code('SB', line)
|
||||||
elif '%s%s' % (c, l) == 'Sd':
|
elif '%s%s' % (c, l) == 'Sd':
|
||||||
text = self.process_code('Sd', line, 'sb')
|
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:
|
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':
|
elif c == 'm':
|
||||||
empty = False
|
empty = False
|
||||||
src = self.code_value(line)
|
src = self.code_value(line)
|
||||||
@ -528,11 +560,6 @@ class PML_HTMLizer(object):
|
|||||||
elif c == 'p':
|
elif c == 'p':
|
||||||
empty = False
|
empty = False
|
||||||
text = '<br /><br style="page-break-after: always;" />'
|
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':
|
elif c == 'n':
|
||||||
pass
|
pass
|
||||||
elif c == 'w':
|
elif c == 'w':
|
||||||
|
@ -233,7 +233,7 @@ class PMLMLizer(object):
|
|||||||
w += '="50%"'
|
w += '="50%"'
|
||||||
text.append(w)
|
text.append(w)
|
||||||
toc_id = elem.attrib.get('id', None)
|
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):
|
if self.toc.get(page.href, None):
|
||||||
toc_title = self.toc[page.href].get(toc_id, None)
|
toc_title = self.toc[page.href].get(toc_id, None)
|
||||||
if toc_title:
|
if toc_title:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user