parameters: (self, toolsbar, language)
docstring: build toolsbar div according to a toolsbar dict
          :param toolsbar: a dict special toolsbar, like this:
                  {
                      "title": "A Special Title",
                      "copy": {
                          "class": "copy_class",
                          "id": "button-copy",
                          "title": "Copy",
                          "icon": "i-icon-copy",
                          "event": "onclick='copyCode(this)'"
                      },
                      "wrap": {
                          "class": "wrap_class",
                          "id": "button-wrap",
                          "title": "Wrap",
                          "icon": "i-icon-wrap",
                          "event": "onclick='wrapCode(this)'"
                      },
                      "fold": {
                          "class": "fold_class",
                          "id": "button-fold",
                          "title": "fold",
                          "icon": "i-icon-fold",
                          "event": "onclick='foldCode(this)'"
                      }
                  }
          :return: a toolsbar div block if success or a empty str if failed
docstring_summary: build toolsbar div according to a toolsbar dict
          :param toolsbar: a dict special toolsbar, like this:
                  {
                      "title": "A Special Title",
                      "copy": {
                          "class": "copy_class",
                          "id": "button-copy",
                          "title": "Copy",
                          "icon": "i-icon-copy",
                          "event": "onclick='copyCode(this)'"
                      },
                      "wrap": {
                          "class": "wrap_class",
                          "id": "button-wrap",
                          "title": "Wrap",
                          "icon": "i-icon-wrap",
                          "event": "onclick='wrapCode(this)'"
                      },
                      "fold": {
                          "class": "fold_class",
                          "id": "button-fold",
                          "title": "fold",
                          "icon": "i-icon-fold",
                          "event": "onclick='foldCode(this)'"
                      }
                  }
          :return: a toolsbar div block if success or a empty str if failed
docstring_tokens: build toolsbar div according to a toolsbar dict : param toolsbar : a dict special toolsbar like this : { title : A Special Title copy : { class : copy_class id : button - copy title : Copy icon : i - icon - copy event : onclick = copyCode ( this ) } wrap : { class : wrap_class id : button - wrap title : Wrap icon : i - icon - wrap event : onclick = wrapCode ( this ) } fold : { class : fold_class id : button - fold title : fold icon : i - icon - fold event : onclick = foldCode ( this ) } } : return : a toolsbar div block if success or a empty str if failed
function: def _build_toolsbar(self, toolsbar, language):
          """
          build toolsbar div according to a toolsbar dict
          :param toolsbar: a dict special toolsbar, like this:
                  {
                      "title": "A Special Title",
                      "copy": {
                          "class": "copy_class",
                          "id": "button-copy",
                          "title": "Copy",
                          "icon": "i-icon-copy",
                          "event": "onclick='copyCode(this)'"
                      },
                      "wrap": {
                          "class": "wrap_class",
                          "id": "button-wrap",
                          "title": "Wrap",
                          "icon": "i-icon-wrap",
                          "event": "onclick='wrapCode(this)'"
                      },
                      "fold": {
                          "class": "fold_class",
                          "id": "button-fold",
                          "title": "fold",
                          "icon": "i-icon-fold",
                          "event": "onclick='foldCode(this)'"
                      }
                  }
          :return: a toolsbar div block if success or a empty str if failed
          """
          if isinstance(toolsbar, (dict,)) and len(toolsbar.keys()) > 0:
              # 外层div
              toolsbardiv = '<div'
              divstyles = []
              if self.noclasses:
                  divstyles.append('display: flex')
                  divstyles.append('justify-content: flex-end')
                  divstyles.append('height: 20px')
                  divstyles.append('border: 1px solid #ccc')
                  divstyles.append('background: #eee')
                  divstyles.append('padding:2px')
                  toolsbardiv = toolsbardiv + (divstyles and ' style="%s"' % ';'.join(divstyles)) + '>'
              else:
                  toolsbardiv = toolsbardiv + (self.toolsbarclass and ' class="%s"' % self.toolsbarclass) + '>'
  
              # 标题标签
              titleSpan = '<span'
              spanstyles = []
              if self.noclasses:
                  spanstyles.append('flex-grow: 1')
                  spanstyles.append('color: #666')
                  spanstyles.append('font-size: 13px')
                  spanstyles.append('padding-left: 4px')
                  titleSpan = titleSpan + (spanstyles and ' style="%s"' % ';'.join(spanstyles)) + '>'
              else:
                  titleSpan = titleSpan + ' class="language">'
  
              # 标题
              title = ''
              if 'title' in toolsbar.keys():
                  title = toolsbar['title']
              elif isinstance(language, (str,)) and len(str(language)) > 0:
                  title = language.capitalize()
              titleSpan = titleSpan + title + '</span>'
  
              buttons = []
              # 每个按钮
              # <button class="copy" id="copy" value="复制" type="button" title="复制" onclick="copyCode(this)">换行</button>
              for name, tool in toolsbar.items():
                  if name == 'title':
                      continue
                  clazz = tool['class'] if 'class' in tool else ''
                  iD = tool['id'] if 'id' in tool else ''
                  title = tool['title'] if 'title' in tool else ''
                  text = tool['text'] if 'text' in tool else ''
                  icon = tool['icon'] if 'icon' in tool else ''
                  event = tool['event'] if 'event' in tool else ''
  
                  button = '<button'
                  # clazz
                  buttonstyles = []
                  if self.noclasses:
                      buttonstyles.append('border: 1px solid #ccc')
                      buttonstyles.append('margin-left: 1px')
                      buttonstyles.append('outline: none')
                      button = button + (buttonstyles and ' style="%s"' % ';'.join(buttonstyles))
                  else:
                      button = button + (clazz and ' class="%s"' % clazz)
                  # id
                  button = button + (iD and ' id="%s"' % iD)
                  # value
                  button = button + (title and ' value="%s"' % title)
                  # title
                  button = button + (title and ' title="%s"' % title)
                  # onclick
                  button = button + (title and ' %s' % event)
                  # type
                  button = button + 'type="button">'
                  # text
                  button = button + text + '</button>'
                  buttons.append(button)
              buttons = ''.join(buttons)
              return toolsbardiv + titleSpan + buttons + '</div>'
          else:
              return ''
function_tokens: def _build_toolsbar ( self , toolsbar , language ) : if isinstance ( toolsbar , ( dict , ) ) and len ( toolsbar . keys ( ) ) > 0 : # 外层div toolsbardiv = '<div' divstyles = [ ] if self . noclasses : divstyles . append ( 'display: flex' ) divstyles . append ( 'justify-content: flex-end' ) divstyles . append ( 'height: 20px' ) divstyles . append ( 'border: 1px solid #ccc' ) divstyles . append ( 'background: #eee' ) divstyles . append ( 'padding:2px' ) toolsbardiv = toolsbardiv + ( divstyles and ' style="%s"' % ';' . join ( divstyles ) ) + '>' else : toolsbardiv = toolsbardiv + ( self . toolsbarclass and ' class="%s"' % self . toolsbarclass ) + '>' # 标题标签 titleSpan = '<span' spanstyles = [ ] if self . noclasses : spanstyles . append ( 'flex-grow: 1' ) spanstyles . append ( 'color: #666' ) spanstyles . append ( 'font-size: 13px' ) spanstyles . append ( 'padding-left: 4px' ) titleSpan = titleSpan + ( spanstyles and ' style="%s"' % ';' . join ( spanstyles ) ) + '>' else : titleSpan = titleSpan + ' class="language">' # 标题 title = '' if 'title' in toolsbar . keys ( ) : title = toolsbar [ 'title' ] elif isinstance ( language , ( str , ) ) and len ( str ( language ) ) > 0 : title = language . capitalize ( ) titleSpan = titleSpan + title + '</span>' buttons = [ ] # 每个按钮 # <button class="copy" id="copy" value="复制" type="button" title="复制" onclick="copyCode(this)">换行</button> for name , tool in toolsbar . items ( ) : if name == 'title' : continue clazz = tool [ 'class' ] if 'class' in tool else '' iD = tool [ 'id' ] if 'id' in tool else '' title = tool [ 'title' ] if 'title' in tool else '' text = tool [ 'text' ] if 'text' in tool else '' icon = tool [ 'icon' ] if 'icon' in tool else '' event = tool [ 'event' ] if 'event' in tool else '' button = '<button' # clazz buttonstyles = [ ] if self . noclasses : buttonstyles . append ( 'border: 1px solid #ccc' ) buttonstyles . append ( 'margin-left: 1px' ) buttonstyles . append ( 'outline: none' ) button = button + ( buttonstyles and ' style="%s"' % ';' . join ( buttonstyles ) ) else : button = button + ( clazz and ' class="%s"' % clazz ) # id button = button + ( iD and ' id="%s"' % iD ) # value button = button + ( title and ' value="%s"' % title ) # title button = button + ( title and ' title="%s"' % title ) # onclick button = button + ( title and ' %s' % event ) # type button = button + 'type="button">' # text button = button + text + '</button>' buttons . append ( button ) buttons = '' . join ( buttons ) return toolsbardiv + titleSpan + buttons + '</div>' else : return ''