mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Fix bugs in merging CSS from style tags and external stylesheets
This commit is contained in:
parent
be8345b0c2
commit
21c84c914f
@ -33,7 +33,7 @@ You may have to adjust the GROUP and the location of the rules file to
|
|||||||
suit your distribution.
|
suit your distribution.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__version__ = "0.3.23"
|
__version__ = "0.3.24"
|
||||||
__docformat__ = "epytext"
|
__docformat__ = "epytext"
|
||||||
__author__ = "Kovid Goyal <kovid@kovidgoyal.net>"
|
__author__ = "Kovid Goyal <kovid@kovidgoyal.net>"
|
||||||
|
|
||||||
|
@ -232,21 +232,6 @@ class HTMLConverter(object):
|
|||||||
self.para = para
|
self.para = para
|
||||||
self.tag = tag
|
self.tag = tag
|
||||||
|
|
||||||
# Defaults for various formatting tags
|
|
||||||
css = dict(
|
|
||||||
h1 = {"font-size" :"xx-large", "font-weight":"bold", 'text-indent':'0pt'},
|
|
||||||
h2 = {"font-size" :"x-large", "font-weight":"bold", 'text-indent':'0pt'},
|
|
||||||
h3 = {"font-size" :"large", "font-weight":"bold", 'text-indent':'0pt'},
|
|
||||||
h4 = {"font-size" :"large", 'text-indent':'0pt'},
|
|
||||||
h5 = {"font-weight" :"bold", 'text-indent':'0pt'},
|
|
||||||
b = {"font-weight" :"bold"},
|
|
||||||
strong = {"font-weight" :"bold"},
|
|
||||||
i = {"font-style" :"italic"},
|
|
||||||
em = {"font-style" :"italic"},
|
|
||||||
small = {'font-size' :'small'},
|
|
||||||
pre = {'font-family' :'monospace' },
|
|
||||||
center = {'text-align' : 'center'}
|
|
||||||
)
|
|
||||||
processed_files = {} #: Files that have been processed
|
processed_files = {} #: Files that have been processed
|
||||||
|
|
||||||
def __init__(self, book, path, dpi=166, width=575, height=747,
|
def __init__(self, book, path, dpi=166, width=575, height=747,
|
||||||
@ -284,6 +269,21 @@ class HTMLConverter(object):
|
|||||||
@type chapter_detection: C{bool}
|
@type chapter_detection: C{bool}
|
||||||
@param chapter_regex: The compiled regular expression used to search for chapter titles
|
@param chapter_regex: The compiled regular expression used to search for chapter titles
|
||||||
'''
|
'''
|
||||||
|
# Defaults for various formatting tags
|
||||||
|
self.css = dict(
|
||||||
|
h1 = {"font-size" :"xx-large", "font-weight":"bold", 'text-indent':'0pt'},
|
||||||
|
h2 = {"font-size" :"x-large", "font-weight":"bold", 'text-indent':'0pt'},
|
||||||
|
h3 = {"font-size" :"large", "font-weight":"bold", 'text-indent':'0pt'},
|
||||||
|
h4 = {"font-size" :"large", 'text-indent':'0pt'},
|
||||||
|
h5 = {"font-weight" :"bold", 'text-indent':'0pt'},
|
||||||
|
b = {"font-weight" :"bold"},
|
||||||
|
strong = {"font-weight" :"bold"},
|
||||||
|
i = {"font-style" :"italic"},
|
||||||
|
em = {"font-style" :"italic"},
|
||||||
|
small = {'font-size' :'small'},
|
||||||
|
pre = {'font-family' :'monospace' },
|
||||||
|
center = {'text-align' : 'center'}
|
||||||
|
)
|
||||||
self.page_width = width #: The width of the page
|
self.page_width = width #: The width of the page
|
||||||
self.page_height = height #: The height of the page
|
self.page_height = height #: The height of the page
|
||||||
self.dpi = dpi #: The DPI of the intended display device
|
self.dpi = dpi #: The DPI of the intended display device
|
||||||
@ -810,10 +810,17 @@ class HTMLConverter(object):
|
|||||||
else:
|
else:
|
||||||
print >>sys.stderr, "Failed to process:", tag
|
print >>sys.stderr, "Failed to process:", tag
|
||||||
elif tagname in ['style', 'link']:
|
elif tagname in ['style', 'link']:
|
||||||
|
def update_css(ncss):
|
||||||
|
for key in ncss.keys():
|
||||||
|
if self.css.has_key(key):
|
||||||
|
self.css[key].update(ncss[key])
|
||||||
|
else:
|
||||||
|
self.css[key] = ncss[key]
|
||||||
|
ncss = None
|
||||||
if tagname == 'style':
|
if tagname == 'style':
|
||||||
for c in tag.contents:
|
for c in tag.contents:
|
||||||
if isinstance(c, NavigableString):
|
if isinstance(c, NavigableString):
|
||||||
self.css.update(self.parse_css(str(c)))
|
ncss = self.parse_css(str(c))
|
||||||
elif tag.has_key('type') and tag['type'] == "text/css" \
|
elif tag.has_key('type') and tag['type'] == "text/css" \
|
||||||
and tag.has_key('href'):
|
and tag.has_key('href'):
|
||||||
url = tag['href']
|
url = tag['href']
|
||||||
@ -822,10 +829,12 @@ class HTMLConverter(object):
|
|||||||
f = urlopen(url)
|
f = urlopen(url)
|
||||||
else:
|
else:
|
||||||
f = open(unquote(url))
|
f = open(unquote(url))
|
||||||
self.parse_css(f.read())
|
ncss = self.parse_css(f.read())
|
||||||
f.close()
|
f.close()
|
||||||
except IOError:
|
except IOError:
|
||||||
pass
|
pass
|
||||||
|
if ncss:
|
||||||
|
update_css(ncss)
|
||||||
elif tagname == 'pre':
|
elif tagname == 'pre':
|
||||||
self.end_current_para()
|
self.end_current_para()
|
||||||
self.current_block.append_to(self.current_page)
|
self.current_block.append_to(self.current_page)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user