mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
DOCX: Remove dependency on lxml > 3
This commit is contained in:
parent
52349965c6
commit
ced5676aa1
@ -7,7 +7,6 @@ __license__ = 'GPL v3'
|
||||
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
import re
|
||||
from future_builtins import map
|
||||
|
||||
from lxml.etree import XPath as X
|
||||
|
||||
@ -99,7 +98,7 @@ def generate_anchor(name, existing):
|
||||
return y
|
||||
|
||||
def children(elem, *args):
|
||||
return elem.iterchildren(*map(expand, args))
|
||||
return XPath('|'.join('child::%s' % a for a in args))(elem)
|
||||
|
||||
def descendants(elem, *args):
|
||||
return elem.iterdescendants(*map(expand, args))
|
||||
return XPath('|'.join('descendant::%s' % a for a in args))(elem)
|
||||
|
@ -16,7 +16,7 @@ from lxml.html.builder import (
|
||||
from calibre.ebooks.docx.container import DOCX, fromstring
|
||||
from calibre.ebooks.docx.names import (
|
||||
XPath, is_tag, XML, STYLES, NUMBERING, FONTS, get, generate_anchor,
|
||||
descendants, ancestor, FOOTNOTES, ENDNOTES)
|
||||
descendants, ancestor, FOOTNOTES, ENDNOTES, children)
|
||||
from calibre.ebooks.docx.styles import Styles, inherit, PageProperties
|
||||
from calibre.ebooks.docx.numbering import Numbering
|
||||
from calibre.ebooks.docx.fonts import Fonts
|
||||
@ -148,7 +148,7 @@ class Convert(object):
|
||||
html_obj.set('class', cls)
|
||||
|
||||
if notes_header is not None:
|
||||
for h in self.body.iterchildren('h1', 'h2', 'h3'):
|
||||
for h in children(self.body, 'h1', 'h2', 'h3'):
|
||||
notes_header.tag = h.tag
|
||||
cls = h.get('class', None)
|
||||
if cls and cls != 'notes-header':
|
||||
@ -262,7 +262,7 @@ class Convert(object):
|
||||
elem.set('id', ans)
|
||||
return ans
|
||||
|
||||
for item in root.iterdescendants(*headings):
|
||||
for item in descendants(root, *headings):
|
||||
lvl = plvl = item_level_map.get(item, None)
|
||||
if lvl is None:
|
||||
continue
|
||||
|
Loading…
x
Reference in New Issue
Block a user