• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python formatter.Formatter类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pygments.formatter.Formatter的典型用法代码示例。如果您正苦于以下问题:Python Formatter类的具体用法?Python Formatter怎么用?Python Formatter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Formatter类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: __init__

    def __init__(self, **options):
        Formatter.__init__(self, **options)

        # create a dict of (start, end) tuples that wrap the
        # value of a token so that we can use it in the format
        # method later
        self.styles = {}

        # we iterate over the `_styles` attribute of a style item
        # that contains the parsed style values.
        for token, style in self.style:
            start = end = ''
            if style['color']:
                sty = str(style['color'])
                if sty == "000000": start, end = '<cstyle:py_decodes>','<cstyle:>'
                if sty == "000001": start, end = '<cstyle:py_comment>','<cstyle:>'
                elif sty == "000002": start, end = '<cstyle:py_keyword>','<cstyle:>'
                elif sty == "000003": start, end = '<cstyle:py_name>','<cstyle:>'
                elif sty == "000004": start, end = '<cstyle:py_name_func>','<cstyle:>'
                elif sty == "000005": start, end = '<cstyle:py_name_class>','<cstyle:>'
                
                elif sty == "100001": start, end = '<cstyle:py_number>','<cstyle:>'   
                elif sty == "100002": start, end = '<cstyle:py_builtin>','<cstyle:>'   
                elif sty == "100003": start, end = '<cstyle:py_builtin>','<cstyle:>'  
                elif sty == "100004": start, end = '<cstyle:py_operator>','<cstyle:>'  
                
                elif sty == "999999": start, end = '<cstyle:py_string>','<cstyle:>'
                #else : start, end = '<cstyle:py_default>','<cstyle:>'
                
            self.styles[token] = (start, end)
开发者ID:cesandoval,项目名称:decoding_designscript,代码行数:30,代码来源:dc_pygments_extensions.py


示例2: __init__

 def __init__(self, **options):
     Formatter.__init__(self, **options)
     self.styles = {}
     for token, style in self.style:
         self.styles[token] = {}
         if style["color"]:
             self.styles[token]["color"] = Colors.rgb(*hex2rgb(style["color"]))
开发者ID:skykooler,项目名称:Lightningbeam,代码行数:7,代码来源:codeeditor.py


示例3: __init__

    def __init__(self, **options):
        Formatter.__init__(self, **options)
        #XXX distinct colors must fit, actually
        if curses.can_change_color() and len(self.style) <= curses.COLORS:

            # cache of registered RGB colors
            colors = []
            def init_color(rgb):
                r, g, b = int(rgb[:2], 16), int(rgb[2:4], 16), int(rgb[4:], 16)
                curses.init_color(len(colors) + 1,
                    r * 1000 / 255, g * 1000 / 255, b * 1000 / 255)
                colors.append(rgb)
            pairs = []
            self.pairs = {}
            self.bolds = set()
            for token, style in self.style:
                #XXX bg
                fg = style['color'] or 'ffffff'
                bg = style['bgcolor']
                if fg not in colors:
                    init_color(fg)

                if style['bold']:
                    self.bolds.add(token)

                pair = (fg, bg)
                sys.stderr.write("%r gets %r\n" % (token, pair))
                if pair not in pairs:
                    curses.init_pair(len(pairs) + 1,
                        colors.index(fg)+1, -1)
                    pairs.append(pair)

                self.pairs[token] = pairs.index(pair)
开发者ID:lehmannro,项目名称:faketerm,代码行数:33,代码来源:faketerm.py


示例4: __init__

  def __init__(self, **options):
        Formatter.__init__(self, **options)
        
        if "fonts" in options:
          self.fonts = ",".join(options["fonts"])
        else:
		  self.fonts = ",".join(['consolas', 'lucida console', 'courier', 'monospace'])

        # create a dict of (start, end) tuples that wrap the
        # value of a token so that we can use it in the format
        # method later
        self.styles = {}

        # we iterate over the `_styles` attribute of a style item
        # that contains the parsed style values.
        for token, style in self.style:
            start = end = ''
            # a style item is a tuple in the following form:
            # colors are readily specified in hex: 'RRGGBB'
            if style['color']:
                start += '<span style="color:#%s">' % style['color']
                end = '</span>' + end
            if style['bold']:
                start += '<b>'
                end = '</b>' + end
            if style['italic']:
                start += '<i>'
                end = '</i>' + end
            if style['underline']:
                start += '<u>'
                end = '</u>' + end
            self.styles[token] = (start, end)
开发者ID:Khaos,项目名称:pygments.wlwriter,代码行数:32,代码来源:devhawk_formatter.py


示例5: __init__

 def __init__(self, **options):
     """Extra arguments:
     
     usebold: if false, bold will be ignored and always off
             default: True
     usebg: if false, background color will always be 'default'
             default: True
     defaultfg: the default color to use for the foreground, used
         if the style does not specify.
         This is in curses format, e.g. curses.COLOR_BLACK.
         Use -1 for the terminal default, -2 for the pygments style default.
         default: -1 (terminal default)
     defaultbg: the default color to use for the background, used in blank
         space, and behind normal text when usebg = False or when
         the style does not specify a foreground color.
         This is in curses format, e.g. curses.COLOR_BLACK.
         Use -1 for the terminal default, -2 for the pygments style default.
         default: -1 (terminal default)
     colors: number of colors to use (-1 for auto, 16, 88, or 256)
             default: -1 (automatic)"""
     Formatter.__init__(self, **options)
     self.usebold = options.get('usebold',True)
     self.usebg = options.get('usebg', True)
     self.defaultbg = options.get('defaultbg', -1)
     self.defaultfg = options.get('defaultfg', -1)
     self.colors = options.get('colors', -1)
     self.style_attrs = {}
     self._tokentocolorpair = {}
     self._setup = False
开发者ID:wackywendell,项目名称:ipycurses,代码行数:29,代码来源:cursespygments.py


示例6: __init__

 def __init__(self, **options):
     """Initialize the style types."""
     Formatter.__init__(self, **options)
     self.styles = {}
     for token, style in self.style:
         start = ''
         end = ''
         newline_end = '\n'
         newline_start = ''
         if style['color']:
             start += newline_start + '<STATviewcolor=#%s>' % style['color'] + '\n'
             newline_start = ''
         if style['bold']:
             start += newline_start + '<STATviewb>\n'
             newline_start = ''
         if style['italic']:
             start += newline_start + '<STATviewi>\n'
             newline_start = ''
         if style['underline']:
             start += newline_start + '<STATviewu>\n'
             newline_start = ''
         if style['underline']:
             end = newline_end + end + '</STATviewu>\n'
             newline_end = ''
         if style['italic']:
             end = newline_end + end + '</STATviewi>\n'
             newline_end = ''
         if style['bold']:
             end = newline_end + end + '</STATviewb>\n'
             newline_end = ''
         if style['color']:
             end = newline_end + end + '</STATviewcolor>\n'
             newline_end = ''
         self.styles[token] = (start, end)
开发者ID:SteveXiSong,项目名称:STAT,代码行数:34,代码来源:STAThelper.py


示例7: __init__

    def __init__(self, **options):
        Formatter.__init__(self, **options)
        self.token_map = {}
        self.styles = []

        for token, style in self.style:
            #debug("formatter: {} {}".format(token, style))

            try:
                s = {}
                if style['color']:
                    c, b = extract_color(style['color'])
                    #debug("fg color: c='{}' b='{}'".format(c, b))
                    s['fg_color'] = c
                    s['fg_bright'] = b
                if style['bold']:
                    s['bold'] = bool(style['bold'])
                if style['underline']:
                    s['underline'] = bool(style['underline'])
                if style['bgcolor']:
                    c, b = extract_color(style['bgcolor'])
                    debug("bg color: c='{}' b='{}'".format(c, b))
                    s['bg_color'] = c
                    s['bg_bright'] = b

                i = self.add_style(s) if len(s) != 0 else -1
                self.token_map[token] = i

                #debug("token_map: {}".format(self.token_map))

            except Exception as ex:
                ## use default formatting
                debug("error: style formatted wrong for {}: {}. Skipping...".format(token, ex))
                self.token_map[token] = -1
开发者ID:ajbonkoski,项目名称:pye,代码行数:34,代码来源:syntax_highlighter.py


示例8: __init__

  def __init__(self, **options):
    Formatter.__init__(self, **options)

    self.styles = {}

    for token, style in self.style:
      start_tag = close_tag = ''

      if style['color']:
        start_tag += '<span fgcolor="#%s">' % style['color']
        close_tag = '</span>' + close_tag

      if style['bold']:
        start_tag += '<b>'
        close_tag = '</b>' + close_tag

      if style['italic']:
        start_tag += '<i>'
        close_tag = '</i>' + close_tag

      if style['underline']:
        start_tag += '<u>'
        close_tag = '</u>' + close_tag

      self.styles[token] = (start_tag, close_tag)
开发者ID:behdad,项目名称:slippy,代码行数:25,代码来源:pangopygments.py


示例9: __init__

 def __init__(self, **options):
     Formatter.__init__(self, **options)
     self.lineseparator = options.get("lineseparator", "\n")
     self.tabwidth = get_int_opt(options, "tabwidth", 4)
     self.escapetable = _escape_html_table
     self.escapetable[ord("\t")] = "&nbsp;" * self.tabwidth
     self.noclasses = get_bool_opt(options, "noclasses", False)
     self.classprefix = options.get("classprefix", "")
     self.cssclass = options.get("cssclass", "highlight")
     self.stylebg = get_bool_opt(options, "stylebg", True)
     self.stylebgalternating = get_bool_opt(options, "stylebgalternating", True)
     self.fontfamily = options.get("fontfamily", "Courier")
     self.fontsize = options.get("fontsize", "1.2em")
     self._create_stylesheet()
     self.linecolwidth = options.get("linecolwidth", 3)
     self.tablewidth = options.get("tablewidth", "100%")
     self.showtitles = get_bool_opt(options, "showtitles", False)
     self.titles = []
     self.additionalstyles = options.get(
         "additionalstyles",
         (
             AspectStyle(name=CSSCLASS_LINENO, styles=dict(bgcolor="eeeeee", borderright="eeaaaa")),
             AspectStyle(name="bgcoloreven", styles=dict(bgcolor="fafafa")),
             AspectStyle(name="bgcoloreven2", styles=dict(bgcolor="fdfdfd")),
             AspectStyle(name="bgcolorodd", styles=dict(bgcolor="f5f5f5")),
             AspectStyle(name="bgcolorodd2", styles=dict(bgcolor="f8f8f8")),
             AspectStyle(name=CSSCLASS_TD_TITLE, styles=dict(bgcolor="eeaaaa", paddingleft="15px")),
         ),
     )
     self._create_additional_styles()
开发者ID:gixxi,项目名称:comparareetpendere,代码行数:30,代码来源:__init__.py


示例10: __init__

    def __init__(self):
        Formatter.__init__(self)
        self.data = []

        # Create a dictionary of text styles, indexed
        # by pygments token names, containing QTextCharFormat
        # instances according to pygments' description
        # of each style

        self.styles = {}
        for token, style in self.style:
            qtf = QtGui.QTextCharFormat()

            if style['color']:
                qtf.setForeground(hex2QColor(style['color']))
            if style['bgcolor']:
                qtf.setBackground(hex2QColor(style['bgcolor']))
            if style['bold']:
                qtf.setFontWeight(QtGui.QFont.Bold)
            if style['italic']:
                qtf.setFontItalic(True)
            if style['underline']:
                qtf.setFontUnderline(True)
            self.styles[str(token)] = qtf
        # missing token
        self.styles['Token.Literal.String.Name'] = self.styles['Token.Literal.String']
开发者ID:LionelR,项目名称:pgleon,代码行数:26,代码来源:editor.py


示例11: __init__

 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 COMMAND_COLORS
     self.linenos = options.get('linenos', False)
     self._lineno = 0
开发者ID:joaobarbosa,项目名称:orator,代码行数:7,代码来源:command_formatter.py


示例12: __init__

    def __init__(self, **options):
        Formatter.__init__(self, **options)
        self.nowrap = get_bool_opt(options, 'nowrap', False)
        self.noclasses = get_bool_opt(options, 'noclasses', False)
        self.classprefix = options.get('classprefix', '')
        self.cssclass = options.get('cssclass', 'highlight')
        self.cssstyles = options.get('cssstyles', '')
        self.prestyles = options.get('prestyles', '')
        self.cssfile = options.get('cssfile', '')
        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.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()
开发者ID:B-Rich,项目名称:crashkit,代码行数:32,代码来源:html.py


示例13: __init__

    def __init__(self, **options):
        Formatter.__init__(self, **options)

        # create a dict of (start, end) tuples that wrap the
        # value of a token so that we can use it in the format
        # method later
        self.styles = {}

        # we iterate over the `_styles` attribute of a style item
        # that contains the parsed style values.
        for token, style in self.style:
            start = end = ''
            # a style item is a tuple in the following form:
            # colors are readily specified in hex: 'RRGGBB'
            if style['color']:
                start += '<font color="#%s">' % style['color']
                end = '</font>' + end
            if style['bold']:
                start += '<b>'
                end = '</b>' + end
            if style['italic']:
                start += '<i>'
                end = '</i>' + end
            if style['underline']:
                start += '<u>'
                end = '</u>' + end
            self.styles[token] = (start, end)
开发者ID:lsfusion,项目名称:samples,代码行数:27,代码来源:main.py


示例14: __init__

    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()
开发者ID:10sr,项目名称:hue,代码行数:7,代码来源:bbcode.py


示例15: __init__

 def __init__(self, flowdocument=True, store_code_blocks=False, **options):
     Formatter.__init__(self, **options)
     self.flowdocument = flowdocument
     self.store_code_blocks = store_code_blocks
     
     self.linenos = 0
     if flowdocument:
         self.lineseparator = '\n'
     else:
         self.lineseparator = '<LineBreak />'
     self.styles = {}
     
     for token, style in self.style:
         format_string = ''
         # a style item is a tuple in the following form:
         # colors are readily specified in hex: 'RRGGBB'
         if style['color']:
             format_string = ' Foreground="#%s"' % style['color']
         if style['bold']:
             format_string += ' FontWeight="Bold"'
         if style['italic']:
             format_string += ' FontStyle="Italic"'
         if style['underline']:
             # not used ?
             pass
         self.styles[token] = format_string
开发者ID:jschementi,项目名称:pycon2010,代码行数:26,代码来源:xamlformatter.py


示例16: __init__

 def __init__(self, color_scheme, **options):
     self.f_strings = {}
     for k, v in theme_map.iteritems():
         self.f_strings[k] = '\x01%s' % (color_scheme[v],)
         if k is Parenthesis:
             # FIXME: Find a way to make this the inverse of the current
             # background colour
             self.f_strings[k] += 'I'
     Formatter.__init__(self, **options)
开发者ID:5monkeys,项目名称:bpython,代码行数:9,代码来源:formatter.py


示例17: __init__

    def __init__(self, **options):
        Formatter.__init__(self, **options)
        self.tagsfile = self._decodeifneeded(options.get('tagsfile', ''))
        self.tagurlformat = self._decodeifneeded(options.get('tagurlformat', ''))

        if self.tagsfile:
            if not ctags:
                raise RuntimeError('The "ctags" package must to be installed '
                                   'to be able to use the "tagsfile" feature.')
            self._ctags = ctags.CTags(self.tagsfile)
开发者ID:Artogn,项目名称:i2p.www,代码行数:10,代码来源:formatters.py


示例18: __init__

 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)
     self.encoding = 'latin1'  # let pygments.format() do the right thing
     # 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)
     self.line_number_start = get_int_opt(options, 'line_number_start', 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.hl_lines = []
     hl_lines_str = get_list_opt(options, 'hl_lines', [])
     for line in hl_lines_str:
         try:
             self.hl_lines.append(int(line))
         except ValueError:
             pass
     self.hl_color = options.get('hl_color',
                                 self.style.highlight_color) or '#f90'
     self.drawables = []
开发者ID:LihMeh,项目名称:outwiker,代码行数:55,代码来源:img.py


示例19: __init__

 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
     self.width = options.get('width', 80)
     self.verbatim = False
     self.in_list  = False
     self.column   = 1
     self.last_was_nl = False
     return
开发者ID:mvaled,项目名称:python3-trepan,代码行数:11,代码来源:format.py


示例20: __init__

    def __init__(self, **options):
        Formatter.__init__(self, **options)

        self.codename = options.get('codename', 'code')
        self.escapeopen = options.get('escapeopen', '/BTEX')
        self.escapeclose = options.get('escapeclose', '/ETEX')
        self.commandprefix = options.get('commandprefix', 'PYG')

        self.p = re.compile(r'(\s)')

        self._create_stylesheet()
开发者ID:jpschorr,项目名称:pygments.formatters.ConTeXt,代码行数:11,代码来源:__init__.py



注:本文中的pygments.formatter.Formatter类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python formatters.get_formatter_by_name函数代码示例发布时间:2022-05-25
下一篇:
Python filters.find_filter_class函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap