mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Make inline style transformation its own re-useable function
This commit is contained in:
parent
be58929e95
commit
07bd906363
@ -221,25 +221,7 @@ def filter_sheet(sheet, properties=()):
|
|||||||
return changed
|
return changed
|
||||||
|
|
||||||
|
|
||||||
def transform_css(container, transform_sheet=None, transform_style=None, names=()):
|
def transform_inline_styles(container, name, transform_sheet, transform_style):
|
||||||
if not names:
|
|
||||||
types = OEB_STYLES | OEB_DOCS
|
|
||||||
names = []
|
|
||||||
for name, mt in iteritems(container.mime_map):
|
|
||||||
if mt in types:
|
|
||||||
names.append(name)
|
|
||||||
|
|
||||||
doc_changed = False
|
|
||||||
|
|
||||||
for name in names:
|
|
||||||
mt = container.mime_map[name]
|
|
||||||
if mt in OEB_STYLES:
|
|
||||||
sheet = container.parsed(name)
|
|
||||||
filtered = transform_sheet(sheet)
|
|
||||||
if filtered:
|
|
||||||
container.dirty(name)
|
|
||||||
doc_changed = True
|
|
||||||
elif mt in OEB_DOCS:
|
|
||||||
root = container.parsed(name)
|
root = container.parsed(name)
|
||||||
changed = False
|
changed = False
|
||||||
for style in root.xpath('//*[local-name()="style"]'):
|
for style in root.xpath('//*[local-name()="style"]'):
|
||||||
@ -259,7 +241,28 @@ def transform_css(container, transform_sheet=None, transform_style=None, names=(
|
|||||||
del elem.attrib['style']
|
del elem.attrib['style']
|
||||||
else:
|
else:
|
||||||
elem.set('style', force_unicode(style.getCssText(separator=' '), 'utf-8'))
|
elem.set('style', force_unicode(style.getCssText(separator=' '), 'utf-8'))
|
||||||
if changed:
|
return changed
|
||||||
|
|
||||||
|
|
||||||
|
def transform_css(container, transform_sheet=None, transform_style=None, names=()):
|
||||||
|
if not names:
|
||||||
|
types = OEB_STYLES | OEB_DOCS
|
||||||
|
names = []
|
||||||
|
for name, mt in iteritems(container.mime_map):
|
||||||
|
if mt in types:
|
||||||
|
names.append(name)
|
||||||
|
|
||||||
|
doc_changed = False
|
||||||
|
|
||||||
|
for name in names:
|
||||||
|
mt = container.mime_map[name]
|
||||||
|
if mt in OEB_STYLES:
|
||||||
|
sheet = container.parsed(name)
|
||||||
|
if transform_sheet(sheet):
|
||||||
|
container.dirty(name)
|
||||||
|
doc_changed = True
|
||||||
|
elif mt in OEB_DOCS:
|
||||||
|
if transform_inline_styles(container, name, transform_sheet, transform_style):
|
||||||
container.dirty(name)
|
container.dirty(name)
|
||||||
doc_changed = True
|
doc_changed = True
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user