当前位置: 首页>>代码示例>>Python>>正文


Python token.STANDARD_TYPES属性代码示例

本文整理汇总了Python中pygments.token.STANDARD_TYPES属性的典型用法代码示例。如果您正苦于以下问题:Python token.STANDARD_TYPES属性的具体用法?Python token.STANDARD_TYPES怎么用?Python token.STANDARD_TYPES使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在pygments.token的用法示例。


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

示例1: __new__

# 需要导入模块: from pygments import token [as 别名]
# 或者: from pygments.token import STANDARD_TYPES [as 别名]
def __new__(mcs, name, bases, dct):
        obj = type.__new__(mcs, name, bases, dct)
        for token in STANDARD_TYPES:
            if token not in obj.styles:
                obj.styles[token] = ''

        def colorformat(text):
            if text[0:1] == '#':
                col = text[1:]
                if len(col) == 6:
                    return col
                elif len(col) == 3:
                    return col[0]*2 + col[1]*2 + col[2]*2
            elif text == '':
                return ''
            assert False, "wrong color format %r" % text

        _styles = obj._styles = {}

        for ttype in obj.styles:
            for token in ttype.split():
                if token in _styles:
                    continue
                ndef = _styles.get(token.parent, None)
                styledefs = obj.styles.get(token, '').split()
                if  not ndef or token is None:
                    ndef = ['', 0, 0, 0, '', '', 0, 0, 0]
                elif 'noinherit' in styledefs and token is not Token:
                    ndef = _styles[Token][:]
                else:
                    ndef = ndef[:]
                _styles[token] = ndef
                for styledef in obj.styles.get(token, '').split():
                    if styledef == 'noinherit':
                        pass
                    elif styledef == 'bold':
                        ndef[1] = 1
                    elif styledef == 'nobold':
                        ndef[1] = 0
                    elif styledef == 'italic':
                        ndef[2] = 1
                    elif styledef == 'noitalic':
                        ndef[2] = 0
                    elif styledef == 'underline':
                        ndef[3] = 1
                    elif styledef == 'nounderline':
                        ndef[3] = 0
                    elif styledef[:3] == 'bg:':
                        ndef[4] = colorformat(styledef[3:])
                    elif styledef[:7] == 'border:':
                        ndef[5] = colorformat(styledef[7:])
                    elif styledef == 'roman':
                        ndef[6] = 1
                    elif styledef == 'sans':
                        ndef[7] = 1
                    elif styledef == 'mono':
                        ndef[8] = 1
                    else:
                        ndef[0] = colorformat(styledef)

        return obj 
开发者ID:joxeankoret,项目名称:pigaios,代码行数:63,代码来源:style.py

示例2: css2rl

# 需要导入模块: from pygments import token [as 别名]
# 或者: from pygments.token import STANDARD_TYPES [as 别名]
def css2rl(css):
    dstyles = {}
    # First create a dumb stylesheet
    for key in STANDARD_TYPES:
        dstyles["pygments-" + STANDARD_TYPES[key]] = {'parent': 'code'}
    seenclassnames = set()
    styles = []
    for line in css.splitlines():
        line = line.strip()
        sname = "pygments-" + line.split(' ')[0][1:]
        seenclassnames.add(sname)
        style = dstyles.get(sname, {'parent': 'code'})
        options = line.split('{')[1].split('}')[0].split(';')
        for option in options:
            option = option.strip()
            option, argument = option.split(':')
            option = option.strip()
            argument = argument.strip()
            if option == 'color':
                style['textColor'] = argument.strip()
            if option == 'background-color':
                style['backColor'] = argument.strip()

            # These two can come in any order
            if option == 'font-weight' and argument == 'bold':
                if 'fontName' in style and style['fontName'] == 'stdMonoItalic':
                    style['fontName'] = 'stdMonoBoldItalic'
                else:
                    style['fontName'] = 'stdMonoBold'
            if option == 'font-style' and argument == 'italic':
                if 'fontName' in style and style['fontName'] == 'stdBold':
                    style['fontName'] = 'stdMonoBoldItalic'
                else:
                    style['fontName'] = 'stdMonoItalic'
        if style.get('textColor', None) is None:
            style['textColor'] = 'black'
        styles.append([sname, style])

    # Now add default styles for all unseen class names
    for sname in classnames - seenclassnames:
        style = dstyles.get(sname, {'parent': 'code'})
        style['textColor'] = 'black'
        styles.append([sname, style])

    return dumpstyle.dumps({'styles': styles}) 
开发者ID:rst2pdf,项目名称:rst2pdf,代码行数:47,代码来源:pygments2style.py


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