mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
...
This commit is contained in:
commit
ebe9b90c86
@ -62,24 +62,22 @@ class OEB2HTML(object):
|
||||
self.links[aid] = 'calibre_link-%s' % len(self.links.keys())
|
||||
return self.links[aid]
|
||||
|
||||
def rewrite_links(self, tag, attribs, page):
|
||||
def rewrite_link(self, tag, attribs, page):
|
||||
# Rewrite ids.
|
||||
if 'id' in attribs:
|
||||
attribs['id'] = self.get_link_id(page.href, attribs['id'])
|
||||
# Rewrite links.
|
||||
if tag == 'a':
|
||||
href = attribs['href']
|
||||
href = page.abshref(href)
|
||||
if tag == 'a' and 'href' in attribs:
|
||||
href = page.abshref(attribs['href'])
|
||||
if self.url_is_relative(href):
|
||||
if '#' not in href:
|
||||
href += '#'
|
||||
if href not in self.links:
|
||||
self.links[href] = 'calibre_link-%s' % len(self.links.keys())
|
||||
href = '#%s' % self.links[href]
|
||||
attribs['href'] = href
|
||||
id = ''
|
||||
if '#' in href:
|
||||
href, n, id = href.partition('#')
|
||||
href = '#%s' % self.get_link_id(href, id)
|
||||
attribs['href'] = href
|
||||
return attribs
|
||||
|
||||
def rewrite_images(self, tag, attribs, page):
|
||||
def rewrite_image(self, tag, attribs, page):
|
||||
if tag == 'img':
|
||||
src = attribs.get('src', None)
|
||||
if src:
|
||||
@ -131,6 +129,10 @@ class OEB2HTMLNoCSSizer(OEB2HTML):
|
||||
tags = []
|
||||
tag = barename(elem.tag)
|
||||
attribs = elem.attrib
|
||||
|
||||
attribs = self.rewrite_link(tag, attribs, page)
|
||||
attribs = self.rewrite_image(tag, attribs, page)
|
||||
|
||||
if tag == 'body':
|
||||
tag = 'div'
|
||||
attribs['id'] = self.get_link_id(page.href, '')
|
||||
@ -147,9 +149,6 @@ class OEB2HTMLNoCSSizer(OEB2HTML):
|
||||
if 'style' in attribs:
|
||||
del attribs['style']
|
||||
|
||||
attribs = self.rewrite_links(tag, attribs, page)
|
||||
attribs = self.rewrite_images(tag, attribs, page)
|
||||
|
||||
# Turn the rest of the attributes into a string we can write with the tag.
|
||||
at = ''
|
||||
for k, v in attribs.items():
|
||||
@ -219,6 +218,9 @@ class OEB2HTMLInlineCSSizer(OEB2HTML):
|
||||
tag = barename(elem.tag)
|
||||
attribs = elem.attrib
|
||||
|
||||
attribs = self.rewrite_link(tag, attribs, page)
|
||||
attribs = self.rewrite_image(tag, attribs, page)
|
||||
|
||||
style_a = '%s' % style
|
||||
if tag == 'body':
|
||||
tag = 'div'
|
||||
@ -233,9 +235,6 @@ class OEB2HTMLInlineCSSizer(OEB2HTML):
|
||||
if 'style' in attribs:
|
||||
del attribs['style']
|
||||
|
||||
attribs = self.rewrite_links(tag, attribs, page)
|
||||
attribs = self.rewrite_images(tag, attribs, page)
|
||||
|
||||
# Turn the rest of the attributes into a string we can write with the tag.
|
||||
at = ''
|
||||
for k, v in attribs.items():
|
||||
@ -312,6 +311,9 @@ class OEB2HTMLClassCSSizer(OEB2HTML):
|
||||
tag = barename(elem.tag)
|
||||
attribs = elem.attrib
|
||||
|
||||
attribs = self.rewrite_link(tag, attribs, page)
|
||||
attribs = self.rewrite_image(tag, attribs, page)
|
||||
|
||||
if tag == 'body':
|
||||
tag = 'div'
|
||||
attribs['id'] = self.get_link_id(page.href, '')
|
||||
@ -321,9 +323,6 @@ class OEB2HTMLClassCSSizer(OEB2HTML):
|
||||
if 'style' in attribs:
|
||||
del attribs['style']
|
||||
|
||||
attribs = self.rewrite_links(tag, attribs, page)
|
||||
attribs = self.rewrite_images(tag, attribs, page)
|
||||
|
||||
# Turn the rest of the attributes into a string we can write with the tag.
|
||||
at = ''
|
||||
for k, v in attribs.items():
|
||||
|
@ -37,7 +37,7 @@ class MarkdownMLizer(object):
|
||||
if not self.opts.keep_links:
|
||||
html = re.sub(r'<\s*/*\s*a[^>]*>', '', html)
|
||||
if not self.opts.keep_image_references:
|
||||
html = re.sub(r'<\s*img[^>]*>', '', html)\
|
||||
html = re.sub(r'<\s*img[^>]*>', '', html)
|
||||
|
||||
text = html2text(html)
|
||||
|
||||
|
@ -11,7 +11,7 @@ from lxml import etree
|
||||
|
||||
from calibre.customize.conversion import OutputFormatPlugin, \
|
||||
OptionRecommendation
|
||||
from calibre.ebooks.oeb.base import OEB_IMAGES
|
||||
from calibre.ebooks.oeb.base import OEB_IMAGES
|
||||
from calibre.ebooks.txt.txtml import TXTMLizer
|
||||
from calibre.ebooks.txt.newlines import TxtNewlines, specified_newlines
|
||||
from calibre.ptempfile import TemporaryDirectory, TemporaryFile
|
||||
|
Loading…
x
Reference in New Issue
Block a user