mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Handle long strings
This commit is contained in:
parent
edd8a2ce83
commit
5599164fef
@ -717,7 +717,14 @@ class HTMLConverter(object):
|
|||||||
@param css: A dict
|
@param css: A dict
|
||||||
'''
|
'''
|
||||||
src = tag.string if hasattr(tag, 'string') else tag
|
src = tag.string if hasattr(tag, 'string') else tag
|
||||||
|
if len(src) > 32767:
|
||||||
|
pos = 0
|
||||||
|
while pos < len(src):
|
||||||
|
self.add_text(src[pos:pos+32767], css, pseudo_css, force_span_use)
|
||||||
|
pos += 32767
|
||||||
|
return
|
||||||
src = src.replace('\r\n', '\n').replace('\r', '\n')
|
src = src.replace('\r\n', '\n').replace('\r', '\n')
|
||||||
|
|
||||||
if pseudo_css.has_key('first-letter') and len(src) > 1:
|
if pseudo_css.has_key('first-letter') and len(src) > 1:
|
||||||
src = src.lstrip()
|
src = src.lstrip()
|
||||||
f = src[0]
|
f = src[0]
|
||||||
|
@ -69,10 +69,15 @@ PYLRF_VERSION = "1.0"
|
|||||||
# anyway.
|
# anyway.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
class LrfError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
def writeByte(f, byte):
|
def writeByte(f, byte):
|
||||||
f.write(struct.pack("<B", byte))
|
f.write(struct.pack("<B", byte))
|
||||||
|
|
||||||
def writeWord(f, word):
|
def writeWord(f, word):
|
||||||
|
if int(word) > 65535:
|
||||||
|
raise LrfError('Cannot encode a number greater than 65535 in a word.')
|
||||||
f.write(struct.pack("<H", int(word)))
|
f.write(struct.pack("<H", int(word)))
|
||||||
|
|
||||||
def writeSignedWord(f, sword):
|
def writeSignedWord(f, sword):
|
||||||
@ -112,7 +117,10 @@ def writeUnicode(f, string, encoding):
|
|||||||
string = string.decode(encoding)
|
string = string.decode(encoding)
|
||||||
|
|
||||||
string = string.encode("utf-16-le")
|
string = string.encode("utf-16-le")
|
||||||
writeWord(f, len(string))
|
length = len(string)
|
||||||
|
if length > 65535:
|
||||||
|
raise LrfError('Cannot write strings longer than 65535 characters.')
|
||||||
|
writeWord(f, length)
|
||||||
writeString(f, string)
|
writeString(f, string)
|
||||||
|
|
||||||
def writeRaw(f, string, encoding):
|
def writeRaw(f, string, encoding):
|
||||||
@ -327,11 +335,6 @@ TAG_INFO = dict(
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class LrfError(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ObjectTableEntry(object):
|
class ObjectTableEntry(object):
|
||||||
def __init__(self, objId, offset, size):
|
def __init__(self, objId, offset, size):
|
||||||
self.objId = objId
|
self.objId = objId
|
||||||
|
Loading…
x
Reference in New Issue
Block a user