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
|
||||
|
||||
from calibre.ebooks.docx.names import ancestor
|
||||
from calibre.ebooks.docx.names import XPath
|
||||
|
||||
def mergeable(previous, current):
|
||||
if previous.tail or current.tail:
|
||||
@ -100,8 +100,11 @@ def before_count(root, tag, limit=10):
|
||||
|
||||
def cleanup_markup(log, root, styles, dest_dir, detect_cover):
|
||||
# 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'):
|
||||
p = ancestor(hr, 'p')
|
||||
p = pancestor(hr)
|
||||
if p:
|
||||
p = p[0]
|
||||
descendants = tuple(p.iterdescendants())
|
||||
if descendants[-1] is hr:
|
||||
parent = p.getparent()
|
||||
@ -176,5 +179,3 @@ def cleanup_markup(log, root, styles, dest_dir, detect_cover):
|
||||
img.getparent().remove(img)
|
||||
return path
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user