code: def _find_closing_token(self, tag, tokens, pos):
          
          embed_count = 0
          block_count = 0
          lt = len(tokens)
          while pos < lt:
              token_type, tag_name, tag_opts, token_text = tokens[pos]
              if token_type == self.TOKEN_DATA:
                  # Short-circuit for performance.
                  pos += 1
                  continue
              if tag.newline_closes and token_type in (self.TOKEN_TAG_START, self.TOKEN_TAG_END):
                  # If we're finding the closing token for a tag that is closed by newlines, but
                  # there is an embedded tag that doesn't transform newlines (i.e. a code tag
                  # that keeps newlines intact), we need to skip over that.
                  inner_tag = self.recognized_tags[tag_name][1]
                  if not inner_tag.transform_newlines:
                      if token_type == self.TOKEN_TAG_START:
                          block_count += 1
                      else:
                          block_count -= 1
              if token_type == self.TOKEN_NEWLINE and tag.newline_closes and block_count == 0:
                  # If for some crazy reason there are embedded tags that both close on newline,
                  # the first newline will automatically close all those nested tags.
                  return pos, True
              elif token_type == self.TOKEN_TAG_START and tag_name == tag.tag_name:
                  if tag.same_tag_closes:
                      return pos, False
                  if tag.render_embedded:
                      embed_count += 1
              elif token_type == self.TOKEN_TAG_END and tag_name == tag.tag_name:
                  if embed_count > 0:
                      embed_count -= 1
                  else:
                      return pos, True
              pos += 1
          return pos, True
docs: Given the current tag options, a list of tokens, and the current position
          in the token list, this function will find the position of the closing token
          associated with the specified tag. This may be a closing tag, a newline, or
          simply the end of the list (to ensure tags are closed). This function should
          return a tuple of the form (end_pos, consume), where consume should indicate
          whether the ending token should be consumed or not.