 
         startIndex = match[0].length
 
-      if hasTrailingWhitespace and match = TrailingWhitespaceRegex.exec(html)
+      if hasTrailingWhitespace and match = TrailingWhitespaceRegex.exec(@value)
         classes = 'trailing-whitespace'
         classes += ' indent-guide' if hasIndentGuide and not hasLeadingWhitespace
         classes += ' invisible-character' if invisibles.space


      if @value.length > maxTokenLength
        while startIndex < endIndex
          fragments.push "<span>" + @escapeString(html, startIndex, startIndex + maxTokenLength) + "</span>"
          startIndex += maxTokenLength
      else
        fragments.push @escapeString(html, startIndex, endIndex)

      fragments.push trailingHtml

    fragments.join('')

  escapeString: (str, startIndex, endIndex) ->
    strLength = str.length


  getValueAsHtml: ({invisibles, hasLeadingWhitespace, hasTrailingWhitespace, hasIndentGuide})->
    invisibles ?= {}
    if @isHardTab
      classes = 'hard-tab'
      classes += ' indent-guide' if hasIndentGuide
      classes += ' invisible-character' if invisibles.tab
      html = @value.replace StartCharacterRegex, (match) =>
        match = invisibles.tab ? match
        "<span class='#{classes}'>#{@escapeString(match)}</span>"
    else
      startIndex = 0
      endIndex = @value.length

      leadingHtml = ''
      trailingHtml = ''

      if hasLeadingWhitespace and match = LeadingWhitespaceRegex.exec(@value)
        classes = 'leading-whitespace'
        classes += ' indent-guide' if hasIndentGuide
        classes += ' invisible-character' if invisibles.space
