mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
PML Input: Modernize the generated HTML a bit. Fixes #1839689 [Some PML conversions cause FlightCrew errors](https://bugs.launchpad.net/calibre/+bug/1839689)
This commit is contained in:
parent
c1663d3cc8
commit
6099c69d6f
@ -143,3 +143,23 @@ class PMLInput(InputFormatPlugin):
|
|||||||
opf.render(opffile, tocfile, 'toc.ncx')
|
opf.render(opffile, tocfile, 'toc.ncx')
|
||||||
|
|
||||||
return os.path.join(getcwd(), 'metadata.opf')
|
return os.path.join(getcwd(), 'metadata.opf')
|
||||||
|
|
||||||
|
def postprocess_book(self, oeb, opts, log):
|
||||||
|
from calibre.ebooks.oeb.base import XHTML, barename
|
||||||
|
for item in oeb.spine:
|
||||||
|
if hasattr(item.data, 'xpath'):
|
||||||
|
for heading in item.data.iterdescendants(*map(XHTML, 'h1 h2 h3 h4 h5 h6'.split())):
|
||||||
|
if not len(heading):
|
||||||
|
continue
|
||||||
|
span = heading[0]
|
||||||
|
if not heading.text and not span.text and not len(span) and barename(span.tag) == 'span':
|
||||||
|
if not heading.get('id') and span.get('id'):
|
||||||
|
heading.set('id', span.get('id'))
|
||||||
|
heading.text = span.tail
|
||||||
|
heading.remove(span)
|
||||||
|
if len(heading) == 1 and heading[0].get('style') == 'text-align: center; margin: auto;':
|
||||||
|
div = heading[0]
|
||||||
|
if barename(div.tag) == 'div' and not len(div) and not div.get('id') and not heading.get('style'):
|
||||||
|
heading.text = (heading.text or '') + (div.text or '') + (div.tail or '')
|
||||||
|
heading.remove(div)
|
||||||
|
heading.set('style', 'text-align: center')
|
||||||
|
@ -220,7 +220,7 @@ class PML_HTMLizer(object):
|
|||||||
return html
|
return html
|
||||||
|
|
||||||
def cleanup_html_remove_redundant(self, html):
|
def cleanup_html_remove_redundant(self, html):
|
||||||
for key in self.STATES_TAGS.keys():
|
for key in self.STATES_TAGS:
|
||||||
open, close = self.STATES_TAGS[key]
|
open, close = self.STATES_TAGS[key]
|
||||||
if key in self.STATES_VALUE_REQ:
|
if key in self.STATES_VALUE_REQ:
|
||||||
html = re.sub(r'(?u)%s\s*%s' % (open % '.*?', close), '', html)
|
html = re.sub(r'(?u)%s\s*%s' % (open % '.*?', close), '', html)
|
||||||
@ -618,7 +618,7 @@ class PML_HTMLizer(object):
|
|||||||
pass
|
pass
|
||||||
elif c == 'w':
|
elif c == 'w':
|
||||||
empty = False
|
empty = False
|
||||||
text = '<hr width="%s" />' % self.code_value(line)
|
text = '<hr style="width: %s" />' % self.code_value(line)
|
||||||
elif c == 't':
|
elif c == 't':
|
||||||
indent_state['t'] = not indent_state['t']
|
indent_state['t'] = not indent_state['t']
|
||||||
elif c == 'T':
|
elif c == 'T':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user