Esempio n. 1
0
    def __init__(self, **options):
        Formatter.__init__(self, **options)
        self._code = get_bool_opt(options, 'codetag', False)
        self._mono = get_bool_opt(options, 'monofont', False)

        self.styles = {}
        self._make_styles()
Esempio n. 2
0
    def __init__(self, **options):
        Formatter.__init__(self, **options)
        self._code = get_bool_opt(options, 'codetag', False)
        self._mono = get_bool_opt(options, 'monofont', False)

        self.styles = {}
        self._make_styles()
Esempio n. 3
0
    def __init__(self, **options):
        Formatter.__init__(self, **options)

        self.xterm_colors = []
        self.best_match = {}
        self.style_string = {}

        self.usebold = 'nobold' not in options
        self.useunderline = 'nounderline' not in options

        self._build_color_table()  # build an RGB-to-256 color conversion table
        self._setup_styles()  # convert selected style's colors to term. colors
Esempio n. 4
0
    def __init__(self, **options):
        Formatter.__init__(self, **options)
        self.docclass = options.get('docclass', 'article')
        self.preamble = options.get('preamble', '')
        self.linenos = get_bool_opt(options, 'linenos', False)
        self.linenostart = abs(get_int_opt(options, 'linenostart', 1))
        self.linenostep = abs(get_int_opt(options, 'linenostep', 1))
        self.verboptions = options.get('verboptions', '')
        self.nobackground = get_bool_opt(options, 'nobackground', False)
        self.commandprefix = options.get('commandprefix', 'PY')

        self._create_stylesheet()
Esempio n. 5
0
    def __init__(self, **options):
        Formatter.__init__(self, **options)

        self.xterm_colors = []
        self.best_match = {}
        self.style_string = {}

        self.usebold = 'nobold' not in options
        self.useunderline = 'nounderline' not in options

        self._build_color_table() # build an RGB-to-256 color conversion table
        self._setup_styles() # convert selected style's colors to term. colors
Esempio n. 6
0
    def __init__(self, **options):
        Formatter.__init__(self, **options)
        self.docclass = options.get('docclass', 'article')
        self.preamble = options.get('preamble', '')
        self.linenos = get_bool_opt(options, 'linenos', False)
        self.linenostart = abs(get_int_opt(options, 'linenostart', 1))
        self.linenostep = abs(get_int_opt(options, 'linenostep', 1))
        self.verboptions = options.get('verboptions', '')
        self.nobackground = get_bool_opt(options, 'nobackground', False)
        self.commandprefix = options.get('commandprefix', 'PY')

        self._create_stylesheet()
Esempio n. 7
0
    def __init__(self, **options):
        """
        Additional options accepted:

        ``fontface``
            Name of the font used. Could for example be ``'Courier New'``
            to further specify the default which is ``'\fmodern'``. The RTF
            specification claims that ``\fmodern`` are "Fixed-pitch serif
            and sans serif fonts". Hope every RTF implementation thinks
            the same about modern...
        """
        Formatter.__init__(self, **options)
        self.fontface = options.get('fontface') or ''
Esempio n. 8
0
File: rtf.py Progetto: Mekyi/crunchy
    def __init__(self, **options):
        """
        Additional options accepted:

        ``fontface``
            Name of the font used. Could for example be ``'Courier New'``
            to further specify the default which is ``'\fmodern'``. The RTF
            specification claims that ``\fmodern`` are "Fixed-pitch serif
            and sans serif fonts". Hope every RTF implementation thinks
            the same about modern...
        """
        Formatter.__init__(self, **options)
        self.fontface = options.get('fontface') or ''
Esempio n. 9
0
 def format(self, tokensource, outfile):
     # hack: if the output is a terminal and has an encoding set,
     # use that to avoid unicode encode problems
     if not self.encoding and hasattr(outfile, "encoding") and \
        hasattr(outfile, "isatty") and outfile.isatty():
         self.encoding = outfile.encoding
     return Formatter.format(self, tokensource, outfile)
Esempio n. 10
0
 def format(self, tokensource, outfile):
     # hack: if the output is a terminal and has an encoding set,
     # use that to avoid unicode encode problems
     if not self.encoding and hasattr(outfile, "encoding") and \
        hasattr(outfile, "isatty") and outfile.isatty():
         self.encoding = outfile.encoding
     return Formatter.format(self, tokensource, outfile)
Esempio n. 11
0
 def __init__(self, **options):
     Formatter.__init__(self, **options)
     if self.encoding:
         raise OptionError('the raw formatter does not support the '
                           'encoding option')
     self.encoding = 'ascii'  # let pygments3.format() do the right thing
     self.compress = get_choice_opt(options, 'compress',
                                    ['', 'none', 'gz', 'bz2'], '')
     self.error_color = options.get('error_color', None)
     if self.error_color is True:
         self.error_color = 'red'
     if self.error_color is not None:
         try:
             colorize(self.error_color, '')
         except KeyError:
             raise ValueError("Invalid color %r specified" %
                              self.error_color)
Esempio n. 12
0
 def __init__(self, **options):
     Formatter.__init__(self, **options)
     if self.encoding:
         raise OptionError('the raw formatter does not support the '
                           'encoding option')
     self.encoding = 'ascii'  # let pygments3.format() do the right thing
     self.compress = get_choice_opt(options, 'compress',
                                    ['', 'none', 'gz', 'bz2'], '')
     self.error_color = options.get('error_color', None)
     if self.error_color is True:
         self.error_color = 'red'
     if self.error_color is not None:
         try:
             colorize(self.error_color, '')
         except KeyError:
             raise ValueError("Invalid color %r specified" %
                              self.error_color)
Esempio n. 13
0
 def __init__(self, **options):
     # XXX outencoding
     Formatter.__init__(self, **options)
     self.nowrap = get_bool_opt(options, 'nowrap', False)
     self.fontfamily = options.get('fontfamily', 'monospace')
     self.fontsize = options.get('fontsize', '14px')
     self.xoffset = get_int_opt(options, 'xoffset', 0)
     fs = self.fontsize.strip()
     if fs.endswith('px'): fs = fs[:-2].strip()
     try:
         int_fs = int(fs)
     except:
         int_fs = 20
     self.yoffset = get_int_opt(options, 'yoffset', int_fs)
     self.ystep = get_int_opt(options, 'ystep', int_fs + 5)
     self.spacehack = get_bool_opt(options, 'spacehack', True)
     self._stylecache = {}
Esempio n. 14
0
File: svg.py Progetto: Mekyi/crunchy
 def __init__(self, **options):
     # XXX outencoding
     Formatter.__init__(self, **options)
     self.nowrap = get_bool_opt(options, 'nowrap', False)
     self.fontfamily = options.get('fontfamily', 'monospace')
     self.fontsize = options.get('fontsize', '14px')
     self.xoffset = get_int_opt(options, 'xoffset', 0)
     fs = self.fontsize.strip()
     if fs.endswith('px'): fs = fs[:-2].strip()
     try:
         int_fs = int(fs)
     except:
         int_fs = 20
     self.yoffset = get_int_opt(options, 'yoffset', int_fs)
     self.ystep = get_int_opt(options, 'ystep', int_fs + 5)
     self.spacehack = get_bool_opt(options, 'spacehack', True)
     self._stylecache = {}
Esempio n. 15
0
 def __init__(self, **options):
     """
     See the class docstring for explanation of options.
     """
     if not pil_available:
         raise PilNotAvailable(
             'Python Imaging Library is required for this formatter')
     Formatter.__init__(self, **options)
     # Read the style
     self.styles = dict(self.style)
     if self.style.background_color is None:
         self.background_color = '#fff'
     else:
         self.background_color = self.style.background_color
     # Image options
     self.image_format = get_choice_opt(options,
                                        'image_format',
                                        ['png', 'jpeg', 'gif', 'bmp'],
                                        self.default_image_format,
                                        normcase=True)
     self.image_pad = get_int_opt(options, 'image_pad', 10)
     self.line_pad = get_int_opt(options, 'line_pad', 2)
     # The fonts
     fontsize = get_int_opt(options, 'font_size', 14)
     self.fonts = FontManager(options.get('font_name', ''), fontsize)
     self.fontw, self.fonth = self.fonts.get_char_size()
     # Line number options
     self.line_number_fg = options.get('line_number_fg', '#886')
     self.line_number_bg = options.get('line_number_bg', '#eed')
     self.line_number_chars = get_int_opt(options, 'line_number_chars', 2)
     self.line_number_bold = get_bool_opt(options, 'line_number_bold',
                                          False)
     self.line_number_italic = get_bool_opt(options, 'line_number_italic',
                                            False)
     self.line_number_pad = get_int_opt(options, 'line_number_pad', 6)
     self.line_numbers = get_bool_opt(options, 'line_numbers', True)
     self.line_number_separator = get_bool_opt(options,
                                               'line_number_separator',
                                               True)
     self.line_number_step = get_int_opt(options, 'line_number_step', 1)
     if self.line_numbers:
         self.line_number_width = (self.fontw * self.line_number_chars +
                                   self.line_number_pad * 2)
     else:
         self.line_number_width = 0
     self.drawables = []
Esempio n. 16
0
File: img.py Progetto: Mekyi/crunchy
 def __init__(self, **options):
     """
     See the class docstring for explanation of options.
     """
     if not pil_available:
         raise PilNotAvailable(
             'Python Imaging Library is required for this formatter')
     Formatter.__init__(self, **options)
     # Read the style
     self.styles = dict(self.style)
     if self.style.background_color is None:
         self.background_color = '#fff'
     else:
         self.background_color = self.style.background_color
     # Image options
     self.image_format = get_choice_opt(
         options, 'image_format', ['png', 'jpeg', 'gif', 'bmp'],
         self.default_image_format, normcase=True)
     self.image_pad = get_int_opt(options, 'image_pad', 10)
     self.line_pad = get_int_opt(options, 'line_pad', 2)
     # The fonts
     fontsize = get_int_opt(options, 'font_size', 14)
     self.fonts = FontManager(options.get('font_name', ''), fontsize)
     self.fontw, self.fonth = self.fonts.get_char_size()
     # Line number options
     self.line_number_fg = options.get('line_number_fg', '#886')
     self.line_number_bg = options.get('line_number_bg', '#eed')
     self.line_number_chars = get_int_opt(options,
                                     'line_number_chars', 2)
     self.line_number_bold = get_bool_opt(options,
                                     'line_number_bold', False)
     self.line_number_italic = get_bool_opt(options,
                                     'line_number_italic', False)
     self.line_number_pad = get_int_opt(options, 'line_number_pad', 6)
     self.line_numbers = get_bool_opt(options, 'line_numbers', True)
     self.line_number_separator = get_bool_opt(options,
                                     'line_number_separator', True)
     self.line_number_step = get_int_opt(options, 'line_number_step', 1)
     if self.line_numbers:
         self.line_number_width = (self.fontw * self.line_number_chars +
                                self.line_number_pad * 2)
     else:
         self.line_number_width = 0
     self.drawables = []
Esempio n. 17
0
    def __init__(self, **options):
        Formatter.__init__(self, **options)
        self.title = self._decodeifneeded(self.title)
        self.nowrap = get_bool_opt(options, 'nowrap', False)
        self.noclasses = get_bool_opt(options, 'noclasses', False)
        self.classprefix = options.get('classprefix', '')
        self.cssclass = self._decodeifneeded(
            options.get('cssclass', 'highlight'))
        self.cssstyles = self._decodeifneeded(options.get('cssstyles', ''))
        self.prestyles = self._decodeifneeded(options.get('prestyles', ''))
        self.cssfile = self._decodeifneeded(options.get('cssfile', ''))
        self.noclobber_cssfile = get_bool_opt(options, 'noclobber_cssfile',
                                              False)

        linenos = options.get('linenos', False)
        if linenos == 'inline':
            self.linenos = 2
        elif linenos:
            # compatibility with <= 0.7
            self.linenos = 1
        else:
            self.linenos = 0
        self.linenostart = abs(get_int_opt(options, 'linenostart', 1))
        self.linenostep = abs(get_int_opt(options, 'linenostep', 1))
        self.linenospecial = abs(get_int_opt(options, 'linenospecial', 0))
        self.nobackground = get_bool_opt(options, 'nobackground', False)
        self.lineseparator = options.get('lineseparator', '\n')
        self.lineanchors = options.get('lineanchors', '')
        self.anchorlinenos = options.get('anchorlinenos', False)
        self.hl_lines = set()
        for lineno in get_list_opt(options, 'hl_lines', []):
            try:
                self.hl_lines.add(int(lineno))
            except ValueError:
                pass

        self._class_cache = {}
        self._create_stylesheet()
Esempio n. 18
0
    def __init__(self, **options):
        Formatter.__init__(self, **options)
        self.title = self._decodeifneeded(self.title)
        self.nowrap = get_bool_opt(options, 'nowrap', False)
        self.noclasses = get_bool_opt(options, 'noclasses', False)
        self.classprefix = options.get('classprefix', '')
        self.cssclass = self._decodeifneeded(options.get('cssclass', 'highlight'))
        self.cssstyles = self._decodeifneeded(options.get('cssstyles', ''))
        self.prestyles = self._decodeifneeded(options.get('prestyles', ''))
        self.cssfile = self._decodeifneeded(options.get('cssfile', ''))
        self.noclobber_cssfile = get_bool_opt(options, 'noclobber_cssfile', False)

        linenos = options.get('linenos', False)
        if linenos == 'inline':
            self.linenos = 2
        elif linenos:
            # compatibility with <= 0.7
            self.linenos = 1
        else:
            self.linenos = 0
        self.linenostart = abs(get_int_opt(options, 'linenostart', 1))
        self.linenostep = abs(get_int_opt(options, 'linenostep', 1))
        self.linenospecial = abs(get_int_opt(options, 'linenospecial', 0))
        self.nobackground = get_bool_opt(options, 'nobackground', False)
        self.lineseparator = options.get('lineseparator', '\n')
        self.lineanchors = options.get('lineanchors', '')
        self.anchorlinenos = options.get('anchorlinenos', False)
        self.hl_lines = set()
        for lineno in get_list_opt(options, 'hl_lines', []):
            try:
                self.hl_lines.add(int(lineno))
            except ValueError:
                pass

        self._class_cache = {}
        self._create_stylesheet()
Esempio n. 19
0
 def __init__(self, **options):
     Formatter.__init__(self, **options)
     self.darkbg = get_choice_opt(options, 'bg',
                                  ['light', 'dark'], 'light') == 'dark'
     self.colorscheme = options.get('colorscheme', None) or TERMINAL_COLORS
Esempio n. 20
0
 def __init__(self, **options):
     Formatter.__init__(self, **options)
     self.darkbg = get_choice_opt(options, 'bg', ['light', 'dark'],
                                  'light') == 'dark'
     self.colorscheme = options.get('colorscheme', None) or TERMINAL_COLORS