mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
DOCX Input: Nicer markup for paragraphs containing only a page break
DOCX Input: Fix page-breaks created as a page break inside an otherwise empty paragraph not being rendered on conversion to PDF. Fixes #1249502 [Can't apply page breaks on word to pdf](https://bugs.launchpad.net/calibre/+bug/1249502)
This commit is contained in:
parent
a4c35af27d
commit
229232f6cf
@ -9,6 +9,7 @@ __copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from calibre.ebooks.docx.names import XPath
|
from calibre.ebooks.docx.names import XPath
|
||||||
|
NBSP = '\xa0'
|
||||||
|
|
||||||
def mergeable(previous, current):
|
def mergeable(previous, current):
|
||||||
if previous.tail or current.tail:
|
if previous.tail or current.tail:
|
||||||
@ -161,6 +162,17 @@ def cleanup_markup(log, root, styles, dest_dir, detect_cover):
|
|||||||
for span in root.xpath('//span[not(@class) and not(@id) and not(@style)]'):
|
for span in root.xpath('//span[not(@class) and not(@id) and not(@style)]'):
|
||||||
lift(span)
|
lift(span)
|
||||||
|
|
||||||
|
# Convert <p><br style="page-break-after:always"> </p> style page breaks
|
||||||
|
# into something the viewer will render as a page break
|
||||||
|
for p in root.xpath('//p[br[@style="page-break-after:always"]]'):
|
||||||
|
if len(p) == 1 and (not p[0].tail or not p[0].tail.strip()):
|
||||||
|
p.remove(p[0])
|
||||||
|
prefix = p.get('style', '')
|
||||||
|
if prefix:
|
||||||
|
prefix += '; '
|
||||||
|
p.set('style', prefix + 'page-break-after:always')
|
||||||
|
p.text = NBSP
|
||||||
|
|
||||||
if detect_cover:
|
if detect_cover:
|
||||||
# Check if the first image in the document is possibly a cover
|
# Check if the first image in the document is possibly a cover
|
||||||
img = root.xpath('//img[@src][1]')
|
img = root.xpath('//img[@src][1]')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user