mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Conversion pipeline: Support for the :first-letter pseudo selector
This commit is contained in:
parent
5e5a613b8f
commit
76c7add44c
@ -176,6 +176,9 @@ class Stylizer(object):
|
|||||||
class_sel_pat = re.compile(r'\.[a-z]+', re.IGNORECASE)
|
class_sel_pat = re.compile(r'\.[a-z]+', re.IGNORECASE)
|
||||||
capital_sel_pat = re.compile(r'h|[A-Z]+')
|
capital_sel_pat = re.compile(r'h|[A-Z]+')
|
||||||
for _, _, cssdict, text, _ in rules:
|
for _, _, cssdict, text, _ in rules:
|
||||||
|
fl = ':first-letter' in text
|
||||||
|
if fl:
|
||||||
|
text = text.replace(':first-letter', '')
|
||||||
try:
|
try:
|
||||||
selector = CSSSelector(text)
|
selector = CSSSelector(text)
|
||||||
except (AssertionError, ExpressionError, etree.XPathSyntaxError,
|
except (AssertionError, ExpressionError, etree.XPathSyntaxError,
|
||||||
@ -202,6 +205,19 @@ class Stylizer(object):
|
|||||||
if found:
|
if found:
|
||||||
self.logger.warn('Ignoring case mismatches for CSS selector: %s in %s'
|
self.logger.warn('Ignoring case mismatches for CSS selector: %s in %s'
|
||||||
%(text, item.href))
|
%(text, item.href))
|
||||||
|
if fl:
|
||||||
|
from lxml.builder import ElementMaker
|
||||||
|
E = ElementMaker(namespace=XHTML_NS)
|
||||||
|
for elem in matches:
|
||||||
|
for x in elem.iter():
|
||||||
|
if x.text:
|
||||||
|
span = E.span(x.text[0])
|
||||||
|
span.tail = x.text[1:]
|
||||||
|
x.text = None
|
||||||
|
x.insert(0, span)
|
||||||
|
self.style(span)._update_cssdict(cssdict)
|
||||||
|
break
|
||||||
|
else:
|
||||||
for elem in matches:
|
for elem in matches:
|
||||||
self.style(elem)._update_cssdict(cssdict)
|
self.style(elem)._update_cssdict(cssdict)
|
||||||
for elem in xpath(tree, '//h:img[@width or @height]'):
|
for elem in xpath(tree, '//h:img[@width or @height]'):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user