mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
Refactoring.
This commit is contained in:
parent
4be2cbb770
commit
24ca1a1134
2
setup.py
2
setup.py
@ -89,7 +89,7 @@ if __name__ == '__main__':
|
|||||||
include_dirs=['src/calibre/utils/msdes']),
|
include_dirs=['src/calibre/utils/msdes']),
|
||||||
|
|
||||||
Extension('calibre.plugins.cPalmdoc',
|
Extension('calibre.plugins.cPalmdoc',
|
||||||
sources=['src/calibre/ebooks/mobi/palmdoc.c']),
|
sources=['src/calibre/ebooks/compression/palmdoc.c']),
|
||||||
|
|
||||||
PyQtExtension('calibre.plugins.pictureflow',
|
PyQtExtension('calibre.plugins.pictureflow',
|
||||||
['src/calibre/gui2/pictureflow/pictureflow.cpp',
|
['src/calibre/gui2/pictureflow/pictureflow.cpp',
|
||||||
|
5
src/calibre/ebooks/compression/__init__.py
Normal file
5
src/calibre/ebooks/compression/__init__.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
__license__ = 'GPL 3'
|
||||||
|
__copyright__ = '2009, John Schember <john@nachtimwald.com>'
|
||||||
|
__docformat__ = 'restructuredtext en'
|
@ -25,15 +25,9 @@ TAG_MAP = {
|
|||||||
'div' : 'p',
|
'div' : 'p',
|
||||||
}
|
}
|
||||||
|
|
||||||
STYLE_MAP = {
|
|
||||||
'bold' : 'strong',
|
|
||||||
'bolder' : 'strong',
|
|
||||||
'italic' : 'emphasis',
|
|
||||||
}
|
|
||||||
|
|
||||||
STYLES = [
|
STYLES = [
|
||||||
'font-weight',
|
('font-weight', {'bold' : 'strong', 'bolder' : 'strong'}),
|
||||||
'font-style',
|
('font-style', {'italic' : 'emphasis'}),
|
||||||
]
|
]
|
||||||
|
|
||||||
class FB2MLizer(object):
|
class FB2MLizer(object):
|
||||||
@ -107,8 +101,9 @@ class FB2MLizer(object):
|
|||||||
fb2_text += '<%s>' % fb2_tag
|
fb2_text += '<%s>' % fb2_tag
|
||||||
tag_stack.append(fb2_tag)
|
tag_stack.append(fb2_tag)
|
||||||
|
|
||||||
|
# Processes style information
|
||||||
for s in STYLES:
|
for s in STYLES:
|
||||||
style_tag = STYLE_MAP.get(style[s], None)
|
style_tag = s[1].get(style[s[0]], None)
|
||||||
if style_tag:
|
if style_tag:
|
||||||
tag_count += 1
|
tag_count += 1
|
||||||
fb2_text += '<%s>' % style_tag
|
fb2_text += '<%s>' % style_tag
|
||||||
|
@ -1,11 +1,17 @@
|
|||||||
from __future__ import with_statement
|
|
||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
'''
|
'''
|
||||||
Read data from .mobi files
|
Read data from .mobi files
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import struct, os, cStringIO, re, functools, datetime, textwrap
|
import datetime
|
||||||
|
import functools
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import struct
|
||||||
|
import textwrap
|
||||||
|
|
||||||
|
import cStringIO
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from PIL import Image as PILImage
|
from PIL import Image as PILImage
|
||||||
@ -21,8 +27,8 @@ from calibre.ebooks import DRMError
|
|||||||
from calibre.ebooks.chardet import ENCODING_PATS
|
from calibre.ebooks.chardet import ENCODING_PATS
|
||||||
from calibre.ebooks.mobi import MobiError
|
from calibre.ebooks.mobi import MobiError
|
||||||
from calibre.ebooks.mobi.huffcdic import HuffReader
|
from calibre.ebooks.mobi.huffcdic import HuffReader
|
||||||
from calibre.ebooks.mobi.palmdoc import decompress_doc
|
|
||||||
from calibre.ebooks.mobi.langcodes import main_language, sub_language
|
from calibre.ebooks.mobi.langcodes import main_language, sub_language
|
||||||
|
from calibre.ebooks.compression.palmdoc import decompress_doc
|
||||||
from calibre.ebooks.metadata import MetaInformation
|
from calibre.ebooks.metadata import MetaInformation
|
||||||
from calibre.ebooks.metadata.opf2 import OPFCreator, OPF
|
from calibre.ebooks.metadata.opf2 import OPFCreator, OPF
|
||||||
from calibre.ebooks.metadata.toc import TOC
|
from calibre.ebooks.metadata.toc import TOC
|
||||||
|
@ -1,27 +1,32 @@
|
|||||||
'''
|
'''
|
||||||
Write content to Mobipocket books.
|
Write content to Mobipocket books.
|
||||||
'''
|
'''
|
||||||
from __future__ import with_statement
|
|
||||||
|
|
||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2008, Marshall T. Vandegrift <llasram@gmail.cam>'
|
__copyright__ = '2008, Marshall T. Vandegrift <llasram@gmail.cam>'
|
||||||
|
|
||||||
|
from collections import defaultdict
|
||||||
|
from itertools import count
|
||||||
|
from itertools import izip
|
||||||
|
import random
|
||||||
|
import re
|
||||||
from struct import pack
|
from struct import pack
|
||||||
import time
|
import time
|
||||||
import random
|
|
||||||
from cStringIO import StringIO
|
|
||||||
import re
|
|
||||||
from itertools import izip, count
|
|
||||||
from collections import defaultdict
|
|
||||||
from urlparse import urldefrag
|
from urlparse import urldefrag
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from calibre.ebooks.oeb.base import XML_NS, XHTML, XHTML_NS, OEB_DOCS, \
|
from cStringIO import StringIO
|
||||||
OEB_RASTER_IMAGES
|
|
||||||
from calibre.ebooks.oeb.base import namespace, prefixname
|
|
||||||
from calibre.ebooks.oeb.base import urlnormalize
|
|
||||||
from calibre.ebooks.mobi.palmdoc import compress_doc
|
|
||||||
from calibre.ebooks.mobi.langcodes import iana2mobi
|
from calibre.ebooks.mobi.langcodes import iana2mobi
|
||||||
from calibre.ebooks.mobi.mobiml import MBP_NS
|
from calibre.ebooks.mobi.mobiml import MBP_NS
|
||||||
|
from calibre.ebooks.oeb.base import OEB_DOCS
|
||||||
|
from calibre.ebooks.oeb.base import OEB_RASTER_IMAGES
|
||||||
|
from calibre.ebooks.oeb.base import XHTML
|
||||||
|
from calibre.ebooks.oeb.base import XHTML_NS
|
||||||
|
from calibre.ebooks.oeb.base import XML_NS
|
||||||
|
from calibre.ebooks.oeb.base import namespace
|
||||||
|
from calibre.ebooks.oeb.base import prefixname
|
||||||
|
from calibre.ebooks.oeb.base import urlnormalize
|
||||||
|
from calibre.ebooks.compression.palmdoc import compress_doc
|
||||||
|
|
||||||
# TODO:
|
# TODO:
|
||||||
# - Allow override CSS (?)
|
# - Allow override CSS (?)
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import with_statement
|
|
||||||
|
|
||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2009, John Schember <john@nachtimwald.com>'
|
__copyright__ = '2009, John Schember <john@nachtimwald.com>'
|
||||||
@ -10,8 +9,8 @@ class PDBError(Exception):
|
|||||||
|
|
||||||
|
|
||||||
from calibre.ebooks.pdb.ereader.reader import Reader as ereader_reader
|
from calibre.ebooks.pdb.ereader.reader import Reader as ereader_reader
|
||||||
from calibre.ebooks.pdb.ztxt.reader import Reader as ztxt_reader
|
|
||||||
from calibre.ebooks.pdb.palmdoc.reader import Reader as palmdoc_reader
|
from calibre.ebooks.pdb.palmdoc.reader import Reader as palmdoc_reader
|
||||||
|
from calibre.ebooks.pdb.ztxt.reader import Reader as ztxt_reader
|
||||||
|
|
||||||
FORMAT_READERS = {
|
FORMAT_READERS = {
|
||||||
'PNPdPPrs': ereader_reader,
|
'PNPdPPrs': ereader_reader,
|
||||||
|
@ -8,16 +8,19 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2009, John Schember <john@nachtimwald.com>'
|
__copyright__ = '2009, John Schember <john@nachtimwald.com>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import os, re, struct, zlib
|
import os
|
||||||
|
import re
|
||||||
|
import struct
|
||||||
|
import zlib
|
||||||
|
|
||||||
from calibre import CurrentDir
|
from calibre import CurrentDir
|
||||||
from calibre.ebooks import DRMError
|
from calibre.ebooks import DRMError
|
||||||
from calibre.ebooks.pdb.formatreader import FormatReader
|
|
||||||
from calibre.ebooks.pdb.ereader import EreaderError
|
|
||||||
from calibre.ebooks.pml.pmlconverter import pml_to_html, \
|
|
||||||
footnote_sidebar_to_html
|
|
||||||
from calibre.ebooks.mobi.palmdoc import decompress_doc
|
|
||||||
from calibre.ebooks.metadata.opf2 import OPFCreator
|
from calibre.ebooks.metadata.opf2 import OPFCreator
|
||||||
|
from calibre.ebooks.compression.palmdoc import decompress_doc
|
||||||
|
from calibre.ebooks.pdb.ereader import EreaderError
|
||||||
|
from calibre.ebooks.pdb.formatreader import FormatReader
|
||||||
|
from calibre.ebooks.pml.pmlconverter import footnote_sidebar_to_html
|
||||||
|
from calibre.ebooks.pml.pmlconverter import pml_to_html
|
||||||
|
|
||||||
class HeaderRecord(object):
|
class HeaderRecord(object):
|
||||||
'''
|
'''
|
||||||
|
@ -8,9 +8,11 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2009, John Schember <john@nachtimwald.com>'
|
__copyright__ = '2009, John Schember <john@nachtimwald.com>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import struct, zlib
|
import struct
|
||||||
|
import zlib
|
||||||
|
|
||||||
import Image, cStringIO
|
import Image
|
||||||
|
import cStringIO
|
||||||
|
|
||||||
from calibre.ebooks.pdb.formatwriter import FormatWriter
|
from calibre.ebooks.pdb.formatwriter import FormatWriter
|
||||||
from calibre.ebooks.oeb.base import OEB_IMAGES
|
from calibre.ebooks.oeb.base import OEB_IMAGES
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import with_statement
|
|
||||||
'''
|
'''
|
||||||
Read the header data from a pdb file.
|
Read the header data from a pdb file.
|
||||||
'''
|
'''
|
||||||
@ -8,7 +7,9 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2009, John Schember <john@nachtimwald.com>'
|
__copyright__ = '2009, John Schember <john@nachtimwald.com>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import re, struct, time
|
import re
|
||||||
|
import struct
|
||||||
|
import time
|
||||||
|
|
||||||
class PdbHeaderReader(object):
|
class PdbHeaderReader(object):
|
||||||
|
|
||||||
|
@ -8,11 +8,13 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2009, John Schember <john@nachtimwald.com>'
|
__copyright__ = '2009, John Schember <john@nachtimwald.com>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import os, struct, zlib
|
import os
|
||||||
|
import struct
|
||||||
|
|
||||||
|
from calibre.ebooks.compression.palmdoc import decompress_doc
|
||||||
from calibre.ebooks.pdb.formatreader import FormatReader
|
from calibre.ebooks.pdb.formatreader import FormatReader
|
||||||
from calibre.ebooks.mobi.palmdoc import decompress_doc
|
from calibre.ebooks.txt.processor import opf_writer
|
||||||
from calibre.ebooks.txt.processor import txt_to_markdown, opf_writer
|
from calibre.ebooks.txt.processor import txt_to_markdown
|
||||||
|
|
||||||
class HeaderRecord(object):
|
class HeaderRecord(object):
|
||||||
'''
|
'''
|
||||||
|
@ -10,10 +10,11 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
|
from calibre.ebooks.compression.palmdoc import compress_doc
|
||||||
from calibre.ebooks.pdb.formatwriter import FormatWriter
|
from calibre.ebooks.pdb.formatwriter import FormatWriter
|
||||||
from calibre.ebooks.txt.writer import TxtWriter, TxtNewlines
|
|
||||||
from calibre.ebooks.mobi.palmdoc import compress_doc
|
|
||||||
from calibre.ebooks.pdb.header import PdbHeaderBuilder
|
from calibre.ebooks.pdb.header import PdbHeaderBuilder
|
||||||
|
from calibre.ebooks.txt.writer import TxtNewlines
|
||||||
|
from calibre.ebooks.txt.writer import TxtWriter
|
||||||
|
|
||||||
MAX_RECORD_SIZE = 4096
|
MAX_RECORD_SIZE = 4096
|
||||||
|
|
||||||
|
@ -8,7 +8,8 @@ __docformat__ = 'restructuredtext en'
|
|||||||
Transform OEB content into PML markup
|
Transform OEB content into PML markup
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import os, re
|
import os
|
||||||
|
import re
|
||||||
|
|
||||||
from calibre.ebooks.oeb.base import XHTML, XHTML_NS, barename, namespace
|
from calibre.ebooks.oeb.base import XHTML, XHTML_NS, barename, namespace
|
||||||
from calibre.ebooks.oeb.stylizer import Stylizer
|
from calibre.ebooks.oeb.stylizer import Stylizer
|
||||||
@ -40,6 +41,31 @@ STYLES = [
|
|||||||
('text-align', {'right' : 'r', 'center' : 'c'}),
|
('text-align', {'right' : 'r', 'center' : 'c'}),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
BLOCK_TAGS = [
|
||||||
|
'p',
|
||||||
|
]
|
||||||
|
|
||||||
|
BLOCK_STYLES = [
|
||||||
|
'block',
|
||||||
|
]
|
||||||
|
|
||||||
|
LINK_TAGS = [
|
||||||
|
'a',
|
||||||
|
]
|
||||||
|
|
||||||
|
SEPARATE_TAGS = [
|
||||||
|
'h1',
|
||||||
|
'h2',
|
||||||
|
'h3',
|
||||||
|
'h4',
|
||||||
|
'h5',
|
||||||
|
'h6',
|
||||||
|
'p',
|
||||||
|
'div',
|
||||||
|
'li',
|
||||||
|
'tr',
|
||||||
|
]
|
||||||
|
|
||||||
class PMLMLizer(object):
|
class PMLMLizer(object):
|
||||||
def __init__(self, ignore_tables=False):
|
def __init__(self, ignore_tables=False):
|
||||||
self.ignore_tables = ignore_tables
|
self.ignore_tables = ignore_tables
|
||||||
@ -104,7 +130,7 @@ class PMLMLizer(object):
|
|||||||
tag_count = 0
|
tag_count = 0
|
||||||
|
|
||||||
# Are we in a paragraph block?
|
# Are we in a paragraph block?
|
||||||
if tag == 'p' or style['display'] in ('block'):
|
if tag in BLOCK_TAGS or style['display'] in BLOCK_STYLES:
|
||||||
if 'block' not in tag_stack:
|
if 'block' not in tag_stack:
|
||||||
tag_count += 1
|
tag_count += 1
|
||||||
tag_stack.append('block')
|
tag_stack.append('block')
|
||||||
@ -136,7 +162,7 @@ class PMLMLizer(object):
|
|||||||
|
|
||||||
# Special processing of tags that require an argument.
|
# Special processing of tags that require an argument.
|
||||||
# Anchors links
|
# Anchors links
|
||||||
if tag == 'a' and 'q' not in tag_stack:
|
if tag in LINK_TAGS and 'q' not in tag_stack:
|
||||||
href = elem.get('href')
|
href = elem.get('href')
|
||||||
if href and '://' not in href:
|
if href and '://' not in href:
|
||||||
if '#' in href:
|
if '#' in href:
|
||||||
@ -168,7 +194,7 @@ class PMLMLizer(object):
|
|||||||
for i in range(0, tag_count):
|
for i in range(0, tag_count):
|
||||||
close_tag_list.insert(0, tag_stack.pop())
|
close_tag_list.insert(0, tag_stack.pop())
|
||||||
text += self.close_tags(close_tag_list)
|
text += self.close_tags(close_tag_list)
|
||||||
if tag in ('h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'div', 'li', 'tr'):
|
if tag in SEPARATE_TAGS:
|
||||||
text += os.linesep + os.linesep
|
text += os.linesep + os.linesep
|
||||||
|
|
||||||
if 'block' not in tag_stack:
|
if 'block' not in tag_stack:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user