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


Python STANDARD_TYPES.get方法代码示例

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


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

示例1: _get_ttype_name

# 需要导入模块: from pygments.token import STANDARD_TYPES [as 别名]
# 或者: from pygments.token.STANDARD_TYPES import get [as 别名]
def _get_ttype_name(ttype):
    fname = STANDARD_TYPES.get(ttype)
    if fname:
        return fname
    aname = ""
    while fname is None:
        aname = ttype[-1] + aname
        ttype = ttype.parent
        fname = STANDARD_TYPES.get(ttype)
    return fname + aname
开发者ID:austinbv,项目名称:pygments,代码行数:12,代码来源:latex.py

示例2: _get_ttype_class

# 需要导入模块: from pygments.token import STANDARD_TYPES [as 别名]
# 或者: from pygments.token.STANDARD_TYPES import get [as 别名]
def _get_ttype_class(ttype):
	fname = STANDARD_TYPES.get(ttype)
	if fname:
		return fname
	aname = ''
	while fname is None:
		aname = '-' + ttype[-1] + aname
		ttype = ttype.parent
		fname = STANDARD_TYPES.get(ttype)
	return fname + aname
开发者ID:mitakalab,项目名称:pygments.rb,代码行数:12,代码来源:mitakalab.py

示例3: _output_token

# 需要导入模块: from pygments.token import STANDARD_TYPES [as 别名]
# 或者: from pygments.token.STANDARD_TYPES import get [as 别名]
    def _output_token(self, ttype, value, pos, outfile):
        # Manually split things like the "os.path" in "import os.path" into separate tokens so we can annotate them separately
        if ttype == Token.Name.Namespace and '.' in value:
            names = value.split('.')
            r, c = pos
            for i, n in enumerate(names):
                if i:
                    self._output_token(Token.Text, u'.', (r, c), outfile)
                    c += 1
                self._output_token(Token.Name.Namespace, n, (r, c), outfile)
                c += len(n)
            return

        if ttype == Token.Text and pos[1] > 0:
            if '\n' in value:
                outfile.write('</span>')
                self.current_errors = []

        id_str = ' id="%d_%d"' % pos

        cls_str = ''
        cls = STANDARD_TYPES.get(ttype)
        classes = []
        if cls:
            classes.append(cls)
        type_idx = ''
        if ttype in Token.Name:
            classes.append("anno")
            classes.append("usedef-" + value.encode("base64").replace('=', '').replace('\n', ''))

            # print pos, ttype
            node = self.pos_nodes.get(pos, None)
            u = self.node_types.get(node, None)
            if u:
                type_idx = ' type_idx="%s"' % ','.join(str(self._get_type_idx(t)) for t in u.types())
            else:
                print "missed", pos, node
        if classes:
            cls_str = ' class="%s"' % ' '.join(classes)

        outfile.write('<span%s%s%s>' % (cls_str, id_str, type_idx))

        translated_val = value.translate(self._html_escape_table)
        outfile.write(translated_val.encode("utf8"))

        outfile.write('</span>')
开发者ID:kmod,项目名称:icbd,代码行数:48,代码来源:browser.py

示例4: format

# 需要导入模块: from pygments.token import STANDARD_TYPES [as 别名]
# 或者: from pygments.token.STANDARD_TYPES import get [as 别名]
 def format(self, tokenstream, outfile):
     row = 1
     column = 1
     for (token_type, text) in tokenstream:
         parts = text.split("\n")
         new_row = row + len(parts) - 1
         if len(parts) > 1:
             new_column = len(parts[-1])
         else:
             new_column = column + len(parts[-1]) - 1
         if token_type is not Token.Text:
             self._annotation_list.append(Annotation(
                 row,
                 column,
                 new_row,
                 new_column,
                 {
                     "type": "style",
                     "what": STANDARD_TYPES.get(token_type, ""),
                 }
             ))
         row = new_row
         column = new_column + 1
开发者ID:rickardlindberg,项目名称:codereader,代码行数:25,代码来源:syntax_highlight.py

示例5: line_out

# 需要导入模块: from pygments.token import STANDARD_TYPES [as 别名]
# 或者: from pygments.token.STANDARD_TYPES import get [as 别名]
def line_out(out, line, side=None):
	if len(line) >= 4:
		dtype, num, chunks, syntax_chunks = line
	else:
		dtype, num, chunks = line
		syntax_chunks = None
	if not chunks:
		ltype = "nil"
	elif dtype == -1:
		ltype = "old"
	elif dtype == 1:
		ltype = "new"
	else:
		ltype = "same"

	if side:
		side = "%s " % side
	else:
		side = ""

	errors = []

	out.extend('<td class="%s%s num">' % (side, ltype))
	if num is not None:
		out.extend(smart_str(escape(num)))
	out.extend('</td>')
	out.extend('<td class="%s%s line">' % (side, ltype))
	if chunks:
		for ddt, text in chunks:
			if ddt == -1:
				out.extend('<del>')
			elif ddt == 1:
				out.extend('<ins>')
			if syntax_chunks:
				syntax_chunks = list(syntax_chunks)
				while len(text) > 0:
					if len(syntax_chunks) <= 0:
						error = "Chunk overflow error '%s' does not have a syntax chunk" % smart_str(text)
						print error
						errors.append(error)
						out.extend(line_to_html(text))
						text = ''
						continue
					syntax_type, syntax_text = syntax_chunks.pop(0)
					if len(syntax_text) > len(text):
						# If the syntax chunk is larger than the diff chunk then prepend a new syntax chunk with the remainder
						syntax_chunks.insert(0, (syntax_type, syntax_text[len(text):]))
						syntax_text = syntax_text[:len(text)]
					subchunk_text = text[:len(syntax_text)]
					text = text[len(syntax_text):] # Trim the initial text off the chunk text
					if syntax_text == subchunk_text:
						cls = ''
						fname = STANDARD_TYPES.get(syntax_type)
						if fname:
							cls = fname
						else:
							aname = ''
							while fname is None:
								aname = '-' + syntax_type[-1] + aname
								syntax_type = syntax_type.parent
								fname = STANDARD_TYPES.get(syntax_type)
							cls = fname + aname

						if cls:
							out.extend('<span class="%s">' % " ".join(cls))
							out.extend(line_to_html(subchunk_text))
							out.extend('</span>')
						else:
							out.extend(line_to_html(subchunk_text))
					else:
						# Chunk mismatch (code error)
						error = "Chunk mismatch error '%s' does not match '%s'" % (smart_str(syntax_text), smart_str(subchunk_text))
						print error
						errors.append(error)
						out.extend(line_to_html(subchunk_text))

			else:
				out.extend(line_to_html(text))
			if ddt == -1:
				out.extend('</del>')
			elif ddt == 1:
				out.extend('</ins>')
	for error in errors:
		out.extend('<br>')
		out.extend('<span class="error differror">')
		out.extend(smart_str(escape(error)))
		out.extend('</span>')
	out.extend('</td>')
开发者ID:dantman,项目名称:gareth,代码行数:90,代码来源:__init__.py

示例6: _append

# 需要导入模块: from pygments.token import STANDARD_TYPES [as 别名]
# 或者: from pygments.token.STANDARD_TYPES import get [as 别名]
 def _append(self, type, value, element):
     class_ = STANDARD_TYPES.get(type)
     if class_:
         value = moin_page.span(attrib={moin_page.class_: class_}, children=(value, ))
     element.append(value)
开发者ID:YelaSeamless,项目名称:moin-2.0,代码行数:7,代码来源:pygments_in.py

示例7: _output_token

# 需要导入模块: from pygments.token import STANDARD_TYPES [as 别名]
# 或者: from pygments.token.STANDARD_TYPES import get [as 别名]
    def _output_token(self, ttype, value, pos, outfile):
        # Manually split things like the "os.path" in "import os.path" into separate tokens so we can annotate them separately
        if ttype == Token.Name.Namespace and '.' in value:
            names = value.split('.')
            r, c = pos
            for i, n in enumerate(names):
                if i:
                    self._output_token(Token.Text, u'.', (r, c), outfile)
                    c += 1
                self._output_token(Token.Name.Namespace, n, (r, c), outfile)
                c += len(n)
            return

        outfile.write('<span class="error">' * self._num_errors_start(pos))

        outfile.write('</span>' * self._num_errors_end(pos))

        if ttype == Token.Text and pos[1] > 0:
            if '\n' in value:
                outfile.write('</span>')
                self.current_errors = []

        id_str = ''
        if self._have_type_info_for_pos(pos):
            id_str = ' id="%d_%d"' % pos

        def output_preview(should_slide=False):
            slide_class = ' slide' if should_slide else ''
            outfile.write('<span class="anno_preview%s" id="col_%d"></span>' % (slide_class, pos[0]))
            self._output_errors_for_line(pos[0], outfile)

        # This currently outputs errors and annotations before comments
        if ttype == Token.Comment and pos[1] > 0:
            self.comments.add(pos[0])
            output_preview(True)
        elif ttype == Token.Text and pos[1] > 0 and pos[0] not in self.comments:
            try:
                value.index('\n')
                should_slide = len(self._errors_for_line(pos[0])) > 0
                output_preview(should_slide)
            except ValueError:
                pass
            
        cls_str = ''
        cls = STANDARD_TYPES.get(ttype)
        if cls or id_str:
            cls_str = ' class="'
            if id_str:
                cls_str += 'anno '
            if cls:
                cls_str += cls
            cls_str += '"'

        if pos in self.links:
            outfile.write("<a href='%s'>" % self.links[pos])

        if cls_str or id_str:
            outfile.write('<span%s%s>' % (cls_str, id_str))

        translated_val = value.translate(self._html_escape_table)
        outfile.write(translated_val.encode("utf8"))

        if cls:
            outfile.write('</span>')

        if pos in self.links:
            outfile.write("</a>")
开发者ID:kmod,项目名称:icbd,代码行数:69,代码来源:annotate.py


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