class_docstr: Build an EncodingVisualizer
  
  Args:
  
       tokenizer (:class:`~tokenizers.Tokenizer`):
          A tokenizer instance
  
       default_to_notebook (:obj:`bool`):
          Whether to render html output in a notebook by default
  
       annotation_converter (:obj:`Callable`, `optional`):
          An optional (lambda) function that takes an annotation in any format and returns
          an Annotation object
docstr: Converts a list of "consecutive chars" into a single HTML element.
  Chars are consecutive if they fall under the same word, token and annotation.
  The CharState class is a named tuple with a "partition_key" method that makes it easy to
  compare if two chars are consecutive.
  
  Args:
      consecutive_chars_list (:obj:`List[CharState]`):
          A list of CharStates that have been grouped together
  
      text (:obj:`str`):
          The original text being processed
  
      encoding (:class:`~tokenizers.Encoding`):
          The encoding returned from the tokenizer
  
  Returns:
      :obj:`str`: The HTML span for a set of consecutive chars
docstr_tok: ["Converts","a","list","of","``","consecutive","chars","''","into","a","single","HTML","element",".","Chars","are","consecutive","if","they","fall","under","the","same","word",",","token","and","annotation",".","The","CharState","class","is","a","named","tuple","with","a","``","partition_key","''","method","that","makes","it","easy","to","compare","if","two","chars","are","consecutive",".","Args",":","consecutive_chars_list","(",":","obj",":","`","List","[","CharState","]","`",")",":","A","list","of","CharStates","that","have","been","grouped","together","text","(",":","obj",":","`","str","`",")",":","The","original","text","being","processed","encoding","(",":","class",":","`","~tokenizers.Encoding","`",")",":","The","encoding","returned","from","the","tokenizer","Returns",":",":","obj",":","`","str","`",":","The","HTML","span","for","a","set","of","consecutive","chars"]
code: def consecutive_chars_to_html(
      consecutive_chars_list: List[CharState],
      text: str,
      encoding: Encoding,
  ):
      """
      Converts a list of "consecutive chars" into a single HTML element.
      Chars are consecutive if they fall under the same word, token and annotation.
      The CharState class is a named tuple with a "partition_key" method that makes it easy to
      compare if two chars are consecutive.
  
      Args:
          consecutive_chars_list (:obj:`List[CharState]`):
              A list of CharStates that have been grouped together
  
          text (:obj:`str`):
              The original text being processed
  
          encoding (:class:`~tokenizers.Encoding`):
              The encoding returned from the tokenizer
  
      Returns:
          :obj:`str`: The HTML span for a set of consecutive chars
      """
      first = consecutive_chars_list[0]
      if first.char_ix is None:
          # its a special token
          stoken = encoding.tokens[first.token_ix]
          # special tokens are represented as empty spans. We use the data attribute and css
          # magic to display it
          return f'<span class="special-token" data-stoken={stoken}></span>'
      # We're not in a special token so this group has a start and end.
      last = consecutive_chars_list[-1]
      start = first.char_ix
      end = last.char_ix + 1
      span_text = text[start:end]
      css_classes = (
          []
      )  # What css classes will we apply on the resulting span
      data_items = (
          {}
      )  # What data attributes will we apply on the result span
      if first.token_ix is not None:
          # We can either be in a token or not (e.g. in white space)
          css_classes.append("token")
          if first.is_multitoken:
              css_classes.append("multi-token")
          if first.token_ix % 2:
              # We use this to color alternating tokens.
              # A token might be split by an annotation that ends in the middle of it, so this
              # lets us visually indicate a consecutive token despite its possible splitting in
              # the html markup
              css_classes.append("odd-token")
          else:
              # Like above, but a different color so we can see the tokens alternate
              css_classes.append("even-token")
          if (
              EncodingVisualizer.unk_token_regex.search(
                  encoding.tokens[first.token_ix]
              )
              is not None
          ):
              # This is a special token that is in the text. probably UNK
              css_classes.append("special-token")
              # TODO is this the right name for the data attribute ?
              data_items["stok"] = encoding.tokens[first.token_ix]
      else:
          # In this case we are looking at a group/single char that is not tokenized.
          # e.g. white space
          css_classes.append("non-token")
      css = f'''class="{' '.join(css_classes)}"'''
      data = ""
      for key, val in data_items.items():
          data += f' data-{key}="{val}"'
      return f"<span {css} {data} >{span_text}</span>"
  
imports: import itertools
  import os
  import re
  from string import Template
  from typing import Any, Callable, Dict, List, NamedTuple, Optional, Tuple
  from tokenizers import Encoding, Tokenizer
label_desc: Use image node_id 4 for calling the EncodingVisualizer obj's underlying member method code with example usage: obj.consecutive_chars_to_html(consecutive_chars_list, text, encoding) and returns: str, css, str, data, str, span_text, str, str, stoken, str