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


Python code_analyzer.Lexer方法代码示例

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


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

示例1: run

# 需要导入模块: from docutils.utils import code_analyzer [as 别名]
# 或者: from docutils.utils.code_analyzer import Lexer [as 别名]
def run(self):
        self.assert_has_content()
        if self.arguments:
            language = self.arguments[0]
        else:
            language = ''
        set_classes(self.options)
        classes = ['code']
        if language:
            classes.append(language)
        if 'classes' in self.options:
            classes.extend(self.options['classes'])

        # set up lexical analyzer
        try:
            tokens = Lexer(u'\n'.join(self.content), language,
                           self.state.document.settings.syntax_highlight)
        except LexerError, error:
            raise self.warning(error) 
开发者ID:skarlekar,项目名称:faces,代码行数:21,代码来源:body.py

示例2: code_role

# 需要导入模块: from docutils.utils import code_analyzer [as 别名]
# 或者: from docutils.utils.code_analyzer import Lexer [as 别名]
def code_role(role, rawtext, text, lineno, inliner, options={}, content=[]):
    set_classes(options)
    language = options.get('language', '')
    classes = ['code']
    if 'classes' in options:
        classes.extend(options['classes'])
    if language and language not in classes:
        classes.append(language)
    try:
        tokens = Lexer(utils.unescape(text, 1), language,
                       inliner.document.settings.syntax_highlight)
    except LexerError as error:
        msg = inliner.reporter.warning(error)
        prb = inliner.problematic(rawtext, rawtext, msg)
        return [prb], [msg]

    node = nodes.literal(rawtext, '', classes=classes)

    # analyse content and add nodes for every token
    for classes, value in tokens:
        # print (classes, value)
        if classes:
            node += nodes.inline(value, value, classes=classes)
        else:
            # insert as Text to decrease the verbosity of the output
            node += nodes.Text(value, value)

    return [node], [] 
开发者ID:skarlekar,项目名称:faces,代码行数:30,代码来源:roles.py

示例3: code_role

# 需要导入模块: from docutils.utils import code_analyzer [as 别名]
# 或者: from docutils.utils.code_analyzer import Lexer [as 别名]
def code_role(role, rawtext, text, lineno, inliner, options={}, content=[]):
    set_classes(options)
    language = options.get('language', '')
    classes = ['code']
    if 'classes' in options:
        classes.extend(options['classes'])
    if language and language not in classes:
        classes.append(language)
    try:
        tokens = Lexer(utils.unescape(text, 1), language,
                       inliner.document.settings.syntax_highlight)
    except LexerError, error:
        msg = inliner.reporter.warning(error)
        prb = inliner.problematic(rawtext, rawtext, msg)
        return [prb], [msg] 
开发者ID:skarlekar,项目名称:faces,代码行数:17,代码来源:roles.py

示例4: code_role

# 需要导入模块: from docutils.utils import code_analyzer [as 别名]
# 或者: from docutils.utils.code_analyzer import Lexer [as 别名]
def code_role(role, rawtext, text, lineno, inliner, options={}, content=[]):
    set_classes(options)
    language = options.get('language', '')
    classes = ['code']
    if 'classes' in options:
        classes.extend(options['classes'])
    if language and language not in classes:
        classes.append(language)
    try:
        tokens = Lexer(utils.unescape(text, True), language,
                       inliner.document.settings.syntax_highlight)
    except LexerError, error:
        msg = inliner.reporter.warning(error)
        prb = inliner.problematic(rawtext, rawtext, msg)
        return [prb], [msg] 
开发者ID:aws-samples,项目名称:aws-builders-fair-projects,代码行数:17,代码来源:roles.py

示例5: run

# 需要导入模块: from docutils.utils import code_analyzer [as 别名]
# 或者: from docutils.utils.code_analyzer import Lexer [as 别名]
def run(self):
        self.assert_has_content()
        if self.arguments:
            language = self.arguments[0]
        else:
            language = ''
        set_classes(self.options)
        classes = ['code']
        if language:
            classes.append(language)
        if 'classes' in self.options:
            classes.extend(self.options['classes'])

        # set up lexical analyzer
        try:
            tokens = Lexer('\n'.join(self.content), language,
                           self.state.document.settings.syntax_highlight)
        except LexerError as error:
            raise self.warning(error)

        if 'number-lines' in self.options:
            # optional argument `startline`, defaults to 1
            try:
                startline = int(self.options['number-lines'] or 1)
            except ValueError:
                raise self.error(':number-lines: with non-integer start value')
            endline = startline + len(self.content)
            # add linenumber filter:
            tokens = NumberLines(tokens, startline, endline)

        node = nodes.literal_block('\n'.join(self.content), classes=classes)
        self.add_name(node)
        # if called from "include", set the source
        if 'source' in self.options:
            node.attributes['source'] = self.options['source']
        # analyze content and add nodes for every token
        for classes, value in tokens:
            # print (classes, value)
            if classes:
                node += nodes.inline(value, value, classes=classes)
            else:
                # insert as Text to decrease the verbosity of the output
                node += nodes.Text(value, value)

        return [node] 
开发者ID:skarlekar,项目名称:faces,代码行数:47,代码来源:body.py


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