mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
DOCX Input: Fix conversion breaking for files that use heading style
paragraphs to insert line rules
This commit is contained in:
parent
2a0f6bbeae
commit
6afb55fdfb
@ -8,7 +8,7 @@ __copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from calibre.ebooks.docx.names import ancestor
|
from calibre.ebooks.docx.names import XPath
|
||||||
|
|
||||||
def mergeable(previous, current):
|
def mergeable(previous, current):
|
||||||
if previous.tail or current.tail:
|
if previous.tail or current.tail:
|
||||||
@ -100,14 +100,17 @@ def before_count(root, tag, limit=10):
|
|||||||
|
|
||||||
def cleanup_markup(log, root, styles, dest_dir, detect_cover):
|
def cleanup_markup(log, root, styles, dest_dir, detect_cover):
|
||||||
# Move <hr>s outside paragraphs, if possible.
|
# Move <hr>s outside paragraphs, if possible.
|
||||||
|
pancestor = XPath('|'.join('ancestor::%s[1]' % x for x in ('p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6')))
|
||||||
for hr in root.xpath('//span/hr'):
|
for hr in root.xpath('//span/hr'):
|
||||||
p = ancestor(hr, 'p')
|
p = pancestor(hr)
|
||||||
descendants = tuple(p.iterdescendants())
|
if p:
|
||||||
if descendants[-1] is hr:
|
p = p[0]
|
||||||
parent = p.getparent()
|
descendants = tuple(p.iterdescendants())
|
||||||
idx = parent.index(p)
|
if descendants[-1] is hr:
|
||||||
parent.insert(idx+1, hr)
|
parent = p.getparent()
|
||||||
hr.tail = '\n\t'
|
idx = parent.index(p)
|
||||||
|
parent.insert(idx+1, hr)
|
||||||
|
hr.tail = '\n\t'
|
||||||
|
|
||||||
# Merge consecutive spans that have the same styling
|
# Merge consecutive spans that have the same styling
|
||||||
current_run = []
|
current_run = []
|
||||||
@ -176,5 +179,3 @@ def cleanup_markup(log, root, styles, dest_dir, detect_cover):
|
|||||||
img.getparent().remove(img)
|
img.getparent().remove(img)
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user