當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。