mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix bug in html2lrf that affected external links without a fragment.
This commit is contained in:
parent
50811803d0
commit
0df0475b05
@ -15,7 +15,7 @@ Var MUI_TEMP
|
|||||||
|
|
||||||
!define PRODUCT_NAME "libprs500"
|
!define PRODUCT_NAME "libprs500"
|
||||||
!define XPUI_BRANDINGTEXT "${PRODUCT_NAME} created by Kovid Goyal"
|
!define XPUI_BRANDINGTEXT "${PRODUCT_NAME} created by Kovid Goyal"
|
||||||
!define PRODUCT_VERSION "0.3.14"
|
!define PRODUCT_VERSION "0.3.15"
|
||||||
!define WEBSITE "https://libprs500.kovidgoyal.net"
|
!define WEBSITE "https://libprs500.kovidgoyal.net"
|
||||||
!define PY2EXE_DIR "C:\libprs500"
|
!define PY2EXE_DIR "C:\libprs500"
|
||||||
!define LIBUSB_DIR "C:\libusb-prs500"
|
!define LIBUSB_DIR "C:\libusb-prs500"
|
||||||
|
@ -344,6 +344,7 @@ class HTMLConverter(object):
|
|||||||
return prop
|
return prop
|
||||||
|
|
||||||
def parse_file(self):
|
def parse_file(self):
|
||||||
|
previous = self.book.last_page()
|
||||||
self.current_page = Page()
|
self.current_page = Page()
|
||||||
self.current_block = TextBlock()
|
self.current_block = TextBlock()
|
||||||
self.current_para = Paragraph()
|
self.current_para = Paragraph()
|
||||||
@ -358,6 +359,22 @@ class HTMLConverter(object):
|
|||||||
self.current_block.append_to(self.current_page)
|
self.current_block.append_to(self.current_page)
|
||||||
if self.current_page and self.current_page.get_text().strip():
|
if self.current_page and self.current_page.get_text().strip():
|
||||||
self.book.append(self.current_page)
|
self.book.append(self.current_page)
|
||||||
|
previous = self.current_page
|
||||||
|
|
||||||
|
if not self.top.parent:
|
||||||
|
if not previous:
|
||||||
|
previous = self.current_page
|
||||||
|
found = False
|
||||||
|
for page in self.book.pages():
|
||||||
|
if page == previous:
|
||||||
|
found = True
|
||||||
|
if found:
|
||||||
|
self.top = page.contents[0]
|
||||||
|
break
|
||||||
|
if not self.top.parent:
|
||||||
|
print self.top
|
||||||
|
raise ConversionError, 'Could not parse ' + self.file_name
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_text(self, tag):
|
def get_text(self, tag):
|
||||||
@ -385,6 +402,7 @@ class HTMLConverter(object):
|
|||||||
if not path or os.path.basename(path) == self.file_name:
|
if not path or os.path.basename(path) == self.file_name:
|
||||||
if fragment in self.targets.keys():
|
if fragment in self.targets.keys():
|
||||||
tb = self.targets[fragment]
|
tb = self.targets[fragment]
|
||||||
|
sys.stdout.flush()
|
||||||
jb = JumpButton(tb)
|
jb = JumpButton(tb)
|
||||||
self.book.append(jb)
|
self.book.append(jb)
|
||||||
cb = CharButton(jb, text=self.get_text(tag))
|
cb = CharButton(jb, text=self.get_text(tag))
|
||||||
@ -401,7 +419,7 @@ class HTMLConverter(object):
|
|||||||
self.files[path] = HTMLConverter(self.book, path, \
|
self.files[path] = HTMLConverter(self.book, path, \
|
||||||
font_delta=self.font_delta, verbose=self.verbose)
|
font_delta=self.font_delta, verbose=self.verbose)
|
||||||
HTMLConverter.processed_files[path] = self.files[path]
|
HTMLConverter.processed_files[path] = self.files[path]
|
||||||
except Exception, e:
|
except Exception:
|
||||||
print >>sys.stderr, 'Unable to process', path
|
print >>sys.stderr, 'Unable to process', path
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
continue
|
continue
|
||||||
@ -566,6 +584,7 @@ class HTMLConverter(object):
|
|||||||
self.current_page.append(self.current_block)
|
self.current_page.append(self.current_block)
|
||||||
self.current_block = TextBlock()
|
self.current_block = TextBlock()
|
||||||
else:
|
else:
|
||||||
|
print 'yay'
|
||||||
found, marked = False, False
|
found, marked = False, False
|
||||||
for item in self.current_page.contents:
|
for item in self.current_page.contents:
|
||||||
if item == previous:
|
if item == previous:
|
||||||
|
@ -456,6 +456,27 @@ class Book(Delegator):
|
|||||||
self.applySettings(settings, testValid=True)
|
self.applySettings(settings, testValid=True)
|
||||||
|
|
||||||
|
|
||||||
|
def pages(self):
|
||||||
|
'''Return list of Page objects in this book '''
|
||||||
|
ans = []
|
||||||
|
for item in self.delegates:
|
||||||
|
if isinstance(item, Main):
|
||||||
|
for candidate in item.contents:
|
||||||
|
if isinstance(candidate, Page):
|
||||||
|
ans.append(candidate)
|
||||||
|
break
|
||||||
|
return ans
|
||||||
|
|
||||||
|
def last_page(self):
|
||||||
|
'''Return last Page in this book '''
|
||||||
|
for item in self.delegates:
|
||||||
|
if isinstance(item, Main):
|
||||||
|
temp = list(item.contents)
|
||||||
|
temp.reverse()
|
||||||
|
for candidate in temp:
|
||||||
|
if isinstance(candidate, Page):
|
||||||
|
return candidate
|
||||||
|
|
||||||
def getSettings(self):
|
def getSettings(self):
|
||||||
return ["sourceencoding"]
|
return ["sourceencoding"]
|
||||||
|
|
||||||
|
@ -13,17 +13,18 @@ def descrambleBuf(buf, l, xorKey):
|
|||||||
l-=1
|
l-=1
|
||||||
return a.tostring()
|
return a.tostring()
|
||||||
|
|
||||||
f = open(sys.argv[1], 'rb')
|
if __name__ == '__main__':
|
||||||
f.seek(0x0a)
|
f = open(sys.argv[1], 'rb')
|
||||||
xorkey = struct.unpack('<H', f.read(2))[0]
|
f.seek(0x0a)
|
||||||
|
xorkey = struct.unpack('<H', f.read(2))[0]
|
||||||
|
|
||||||
f.seek(int(sys.argv[2], 16) + 0x10)
|
f.seek(int(sys.argv[2], 16) + 0x10)
|
||||||
flags = struct.unpack('<H', f.read(2))[0]
|
flags = struct.unpack('<H', f.read(2))[0]
|
||||||
f.read(2)
|
f.read(2)
|
||||||
l = struct.unpack('<I', f.read(4))[0]
|
l = struct.unpack('<I', f.read(4))[0]
|
||||||
f.read(2)
|
f.read(2)
|
||||||
raw = f.read(l)
|
raw = f.read(l)
|
||||||
key = (l % xorkey) + 0x0f
|
key = (l % xorkey) + 0x0f
|
||||||
descrambled = descrambleBuf(raw, l, key) if (flags & 0x200) else raw
|
descrambled = descrambleBuf(raw, l, key) if (flags & 0x200) else raw
|
||||||
stream = zlib.decompress(descrambled[4:]) if (flags & 0x100) else descrambled
|
stream = zlib.decompress(descrambled[4:]) if (flags & 0x100) else descrambled
|
||||||
print stream
|
print stream
|
||||||
|
Loading…
x
Reference in New Issue
Block a user