mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Rudimentary support for page-break-after: avoid. May have broken other things.
This commit is contained in:
parent
ae28c0a164
commit
240ca94277
@ -229,11 +229,14 @@ class HTMLConverter(object):
|
|||||||
self.tops = {} #: element representing the top of each HTML file in the LRF file
|
self.tops = {} #: element representing the top of each HTML file in the LRF file
|
||||||
self.previous_text = '' #: Used to figure out when to lstrip
|
self.previous_text = '' #: Used to figure out when to lstrip
|
||||||
self.preserve_block_style = False #: Used so that <p> tags in <blockquote> elements are handled properly
|
self.preserve_block_style = False #: Used so that <p> tags in <blockquote> elements are handled properly
|
||||||
|
self.avoid_page_break = False
|
||||||
|
self.current_page = book.create_page()
|
||||||
|
|
||||||
# Styles
|
# Styles
|
||||||
self.blockquote_style = book.create_block_style(sidemargin=60,
|
self.blockquote_style = book.create_block_style(sidemargin=60,
|
||||||
topskip=20, footskip=20)
|
topskip=20, footskip=20)
|
||||||
self.unindented_style = book.create_text_style(parindent=0)
|
self.unindented_style = book.create_text_style(parindent=0)
|
||||||
|
|
||||||
|
|
||||||
self.in_table = False
|
self.in_table = False
|
||||||
# List processing
|
# List processing
|
||||||
@ -284,7 +287,8 @@ class HTMLConverter(object):
|
|||||||
self.link_level += 1
|
self.link_level += 1
|
||||||
paths = [link['path'] for link in self.links]
|
paths = [link['path'] for link in self.links]
|
||||||
|
|
||||||
|
if self.current_page is not None and self.current_page.has_text():
|
||||||
|
self.book.append(self.current_page)
|
||||||
|
|
||||||
for text, tb in self.extra_toc_entries:
|
for text, tb in self.extra_toc_entries:
|
||||||
ascii_text = text.encode('ascii', 'ignore')
|
ascii_text = text.encode('ascii', 'ignore')
|
||||||
@ -371,8 +375,6 @@ class HTMLConverter(object):
|
|||||||
f.close()
|
f.close()
|
||||||
soup = self.preprocess(raw)
|
soup = self.preprocess(raw)
|
||||||
self.logger.info('\tConverting to BBeB...')
|
self.logger.info('\tConverting to BBeB...')
|
||||||
self.current_page = None
|
|
||||||
self.current_para = None
|
|
||||||
self.current_style = {}
|
self.current_style = {}
|
||||||
self.page_break_found = False
|
self.page_break_found = False
|
||||||
self.target_prefix = path
|
self.target_prefix = path
|
||||||
@ -476,14 +478,15 @@ class HTMLConverter(object):
|
|||||||
if isinstance(item, TextBlock) and not item.contents:
|
if isinstance(item, TextBlock) and not item.contents:
|
||||||
continue
|
continue
|
||||||
return item
|
return item
|
||||||
previous = self.book.last_page()
|
if not self.current_page:
|
||||||
self.current_page = self.book.create_page()
|
self.current_page = self.book.create_page()
|
||||||
self.current_block = self.book.create_text_block()
|
self.current_block = self.book.create_text_block()
|
||||||
self.current_para = Paragraph()
|
self.current_para = Paragraph()
|
||||||
if self.cover:
|
if self.cover:
|
||||||
self.add_image_page(self.cover)
|
self.add_image_page(self.cover)
|
||||||
self.cover = None
|
self.cover = None
|
||||||
top = self.current_block
|
top = self.current_block
|
||||||
|
self.current_block.must_append = True
|
||||||
|
|
||||||
self.process_children(soup, {}, {})
|
self.process_children(soup, {}, {})
|
||||||
|
|
||||||
@ -491,33 +494,12 @@ class HTMLConverter(object):
|
|||||||
self.current_para.append_to(self.current_block)
|
self.current_para.append_to(self.current_block)
|
||||||
if self.current_block and self.current_page:
|
if self.current_block and self.current_page:
|
||||||
self.current_block.append_to(self.current_page)
|
self.current_block.append_to(self.current_page)
|
||||||
if self.current_page and self.current_page.has_text():
|
if self.avoid_page_break:
|
||||||
|
self.avoid_page_break = False
|
||||||
|
elif self.current_page and self.current_page.has_text():
|
||||||
self.book.append(self.current_page)
|
self.book.append(self.current_page)
|
||||||
|
self.current_page = None
|
||||||
|
|
||||||
if not top.parent or not top.contents:
|
|
||||||
if not previous:
|
|
||||||
try:
|
|
||||||
previous = self.book.pages()[0]
|
|
||||||
except IndexError:
|
|
||||||
raise ConversionError, self.file_name + ' does not seem to have any content'
|
|
||||||
top = get_valid_block(previous)
|
|
||||||
if not top or not top.parent:
|
|
||||||
raise ConversionError, self.file_name + ' does not seem to have any content'
|
|
||||||
return top
|
|
||||||
|
|
||||||
found = False
|
|
||||||
for page in self.book.pages():
|
|
||||||
if page == previous:
|
|
||||||
found = True
|
|
||||||
continue
|
|
||||||
if found:
|
|
||||||
top = get_valid_block(page)
|
|
||||||
if not top:
|
|
||||||
continue
|
|
||||||
break
|
|
||||||
|
|
||||||
if not top or not top.parent:
|
|
||||||
raise ConversionError, 'Could not parse ' + self.file_name
|
|
||||||
return top
|
return top
|
||||||
|
|
||||||
def create_link(self, children, tag):
|
def create_link(self, children, tag):
|
||||||
@ -999,9 +981,11 @@ class HTMLConverter(object):
|
|||||||
self.end_page()
|
self.end_page()
|
||||||
tag_css.pop('page-break-before')
|
tag_css.pop('page-break-before')
|
||||||
end_page = False
|
end_page = False
|
||||||
if 'page-break-after' in tag_css.keys() and \
|
if 'page-break-after' in tag_css.keys():
|
||||||
tag_css['page-break-after'].lower() != 'avoid':
|
if tag_css['page-break-after'].lower() == 'avoid':
|
||||||
end_page = True
|
self.avoid_page_break = True
|
||||||
|
else:
|
||||||
|
end_page = True
|
||||||
tag_css.pop('page-break-after')
|
tag_css.pop('page-break-after')
|
||||||
if (self.force_page_break_attr[0].match(tagname) and \
|
if (self.force_page_break_attr[0].match(tagname) and \
|
||||||
tag.has_key(self.force_page_break_attr[1]) and \
|
tag.has_key(self.force_page_break_attr[1]) and \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user