(self, formatted_code, language)
return '<div%s>%s%s</div>' % (wrapclasses and ' class="%s"' % ' '.join(wrapclasses),
                                      local_toolsbar, formatted_code)
用于添加toolbar
        :param formatted_code: 已被highlight处理过的代码
        :param language: 语言
        :return:
用于添加toolbar
        :param formatted_code: 已被highlight处理过的代码
        :param language: 语言
        :return:
用于添加toolbar : param formatted_code : 已被highlight处理过的代码 : param language : 语言 : return :
def fence_toolbar_format(self, formatted_code, language):
        """
        用于添加toolbar
        :param formatted_code: 已被highlight处理过的代码
        :param language: 语言
        :return:
        """
        if len(formatted_code) == 0:
            return formatted_code

        # 先判断局部工具栏
        local_toolsbar = self._get_opt_checked_if_multitype(self.toolsbar, False)

        # if False, no toolsbar for this sinppet
        if not local_toolsbar:
            return formatted_code

        # code fold and linefeed
        wrapclasses = []
        if not self.noclasses and self.parse_linefeed(self.linefeed):
            wrapclasses.append('linefeed')
        if not self.noclasses and self.parse_folded(self.folded):
            wrapclasses.append('folded')
        if not self.noclasses and self.parse_shownum(self.shownum):
            wrapclasses.append('shownum')

        # if global, use global toolsbar
        if 'global' in local_toolsbar:
            title = ''
            if 'title' in local_toolsbar and isinstance(local_toolsbar, (dict,)):
                title = local_toolsbar['title']
            elif isinstance(language, (str,)) and len(str(language)) > 0:
                # refresh language identifier
                title = language.capitalize()
            pattern = re.compile(r'(<span[^>]*>).*?(</span>)', re.S | re.M)
            self.global_toolsbar = pattern.sub(r'\1' + title + r'\2', self.global_toolsbar)
            if not self.noclasses:
                wrapclasses.append('with-global-toolsbar')
            return '<div%s>%s%s</div>' % (wrapclasses and ' class="%s"' % ' '.join(wrapclasses),
                                          self.global_toolsbar, formatted_code)

        # or use local globar only for this sinppet
        local_toolsbar = self._build_toolsbar(local_toolsbar, language)
        if not self.noclasses:
            wrapclasses.append('with-local-toolsbar')
        return '<div%s>%s%s</div>' % (wrapclasses and ' class="%s"' % ' '.join(wrapclasses),
                                      local_toolsbar, formatted_code)
def fence_toolbar_format ( self , formatted_code , language ) : if len ( formatted_code ) == 0 : return formatted_code # 先判断局部工具栏 local_toolsbar = self . _get_opt_checked_if_multitype ( self . toolsbar , False ) # if False, no toolsbar for this sinppet if not local_toolsbar : return formatted_code # code fold and linefeed wrapclasses = [ ] if not self . noclasses and self . parse_linefeed ( self . linefeed ) : wrapclasses . append ( 'linefeed' ) if not self . noclasses and self . parse_folded ( self . folded ) : wrapclasses . append ( 'folded' ) if not self . noclasses and self . parse_shownum ( self . shownum ) : wrapclasses . append ( 'shownum' ) # if global, use global toolsbar if 'global' in local_toolsbar : title = '' if 'title' in local_toolsbar and isinstance ( local_toolsbar , ( dict , ) ) : title = local_toolsbar [ 'title' ] elif isinstance ( language , ( str , ) ) and len ( str ( language ) ) > 0 : # refresh language identifier title = language . capitalize ( ) pattern = re . compile ( r'(<span[^>]*>).*?(</span>)' , re . S | re . M ) self . global_toolsbar = pattern . sub ( r'\1' + title + r'\2' , self . global_toolsbar ) if not self . noclasses : wrapclasses . append ( 'with-global-toolsbar' ) return '<div%s>%s%s</div>' % ( wrapclasses and ' class="%s"' % ' ' . join ( wrapclasses ) , self . global_toolsbar , formatted_code ) # or use local globar only for this sinppet local_toolsbar = self . _build_toolsbar ( local_toolsbar , language ) if not self . noclasses : wrapclasses . append ( 'with-local-toolsbar' ) return '<div%s>%s%s</div>' % ( wrapclasses and ' class="%s"' % ' ' . join ( wrapclasses ) , local_toolsbar , formatted_code )