This commit is contained in:
Kovid Goyal 2013-05-22 12:16:34 +05:30
parent 95102dee29
commit 3e715dd604
2 changed files with 12 additions and 4 deletions

View File

@ -7,6 +7,7 @@ __license__ = 'GPL v3'
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>' __copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
import re import re
from future_builtins import map
from lxml.etree import XPath as X from lxml.etree import XPath as X
@ -94,3 +95,8 @@ def generate_anchor(name, existing):
c += 1 c += 1
return y return y
def children(elem, *args):
return elem.iterchildren(*map(expand, args))
def descendants(elem, *args):
return elem.iterdescendants(*map(expand, args))

View File

@ -14,7 +14,9 @@ from lxml.html.builder import (
HTML, HEAD, TITLE, BODY, LINK, META, P, SPAN, BR, DIV) HTML, HEAD, TITLE, BODY, LINK, META, P, SPAN, BR, DIV)
from calibre.ebooks.docx.container import DOCX, fromstring from calibre.ebooks.docx.container import DOCX, fromstring
from calibre.ebooks.docx.names import XPath, is_tag, XML, STYLES, NUMBERING, FONTS, expand, get, generate_anchor from calibre.ebooks.docx.names import (
XPath, is_tag, XML, STYLES, NUMBERING, FONTS, get, generate_anchor,
descendants)
from calibre.ebooks.docx.styles import Styles, inherit, PageProperties from calibre.ebooks.docx.styles import Styles, inherit, PageProperties
from calibre.ebooks.docx.numbering import Numbering from calibre.ebooks.docx.numbering import Numbering
from calibre.ebooks.docx.fonts import Fonts from calibre.ebooks.docx.fonts import Fonts
@ -120,8 +122,8 @@ class Convert(object):
current = [] current = []
self.page_map = OrderedDict() self.page_map = OrderedDict()
for p in XPath('//w:p')(doc): for p in descendants(doc, 'w:p'):
sect = XPath('descendant::w:sectPr')(p) sect = tuple(descendants(p, 'w:sectPr'))
if sect: if sect:
pr = PageProperties(sect) pr = PageProperties(sect)
for x in current + [p]: for x in current + [p]:
@ -197,7 +199,7 @@ class Convert(object):
current_anchor = None current_anchor = None
for x in p.iterdescendants(expand('w:r'), expand('w:bookmarkStart')): for x in descendants(p, 'w:r', 'w:bookmarkStart'):
if x.tag.endswith('}r'): if x.tag.endswith('}r'):
span = self.convert_run(x) span = self.convert_run(x)
if current_anchor is not None: if current_anchor is not None: