docs: function highlight(language_name, value) {
      if (!compileModes.called) {
        compileModes();
        compileModes.called = true;
      }
  
      function subMode(lexem, mode) {
        for (var i = 0; i < mode.contains.length; i++) {
          if (mode.contains[i].beginRe.test(lexem)) {
            return mode.contains[i];
          }
        }
      }
  
      function endOfMode(mode_index, lexem) {
        if (modes[mode_index].end && modes[mode_index].endRe.test(lexem))
          return 1;
        if (modes[mode_index].endsWithParent) {
          var level = endOfMode(mode_index - 1, lexem);
          return level ? level + 1 : 0;
        }
        return 0;
      }
  
      function isIllegal(lexem, mode) {
        return mode.illegalRe && mode.illegalRe.test(lexem);
      }
  
      function compileTerminators(mode, language) {
        var terminators = [];
  
        for (var i = 0; i < mode.contains.length; i++) {
          terminators.push(mode.contains[i].begin);
        }
  
        var index = modes.length - 1;
        do {
          if (modes[index].end) {
            terminators.push(modes[index].end);
          }
          index--;
        } while (modes[index + 1].endsWithParent);
  
        if (mode.illegal) {
          terminators.push(mode.illegal);
        }
  
        return langRe(language, '(' + terminators.join('|') + ')', true);
      }
  
      function eatModeChunk(value, index) {
        var mode = modes[modes.length - 1];
        if (!mode.terminators) {
          mode.terminators = compileTerminators(mode, language);
        }
        mode.terminators.lastIndex = index;
        var match = mode.terminators.exec(value);
        if (match)
          return [value.substr(index, match.index - index), match[0], false];
        else
          return [value.substr(index), '', true];
      }
  
      function keywordMatch(mode, match) {
        var match_str = language.case_insensitive ? match[0].toLowerCase() : match[0]
        for (var className in mode.keywordGroups) {
          if (!mode.keywordGroups.hasOwnProperty(className))
            continue;
          var value = mode.keywordGroups[className].hasOwnProperty(match_str);
          if (value)
            return [className, value];
        }
        return false;
      }
  
      function processKeywords(buffer, mode) {
        if (!mode.keywords)
          return escape(buffer);
        var result = '';
        var last_index = 0;
        mode.lexemsRe.lastIndex = 0;
        var match = mode.lexemsRe.exec(buffer);
        while (match) {
          result += escape(buffer.substr(last_index, match.index - last_index));
          var keyword_match = keywordMatch(mode, match);
          if (keyword_match) {
            keyword_count += keyword_match[1];
            result += '<span class="'+ keyword_match[0] +'">' + escape(match[0]) + '</span>';
          } else {
            result += escape(match[0]);
          }
          last_index = mode.lexemsRe.lastIndex;
          match = mode.lexemsRe.exec(buffer);
        }
        result += escape(buffer.substr(last_index, buffer.length - last_index));
        return result;
      }
  
      function processBuffer(buffer, mode) {
        if (mode.subLanguage && languages[mode.subLanguage]) {
          var result = highlight(mode.subLanguage, buffer);
          keyword_count += result.keyword_count;
          return result.value;
        } else {
          return processKeywords(buffer, mode);
        }
      }
  
      function startNewMode(mode, lexem) {
        var markup = mode.className?'<span class="' + mode.className + '">':'';
        if (mode.returnBegin) {
          result += markup;
          mode.buffer = '';
        } else if (mode.excludeBegin) {
          result += escape(lexem) + markup;
          mode.buffer = '';
        } else {
          result += markup;
          mode.buffer = lexem;
        }
        modes.push(mode);
        relevance += mode.relevance;
      }
  
      function processModeInfo(buffer, lexem, end) {
        var current_mode = modes[modes.length - 1];
        if (end) {
          result += processBuffer(current_mode.buffer + buffer, current_mode);
          return false;
        }
  
        var new_mode = subMode(lexem, current_mode);
        if (new_mode) {
          result += processBuffer(current_mode.buffer + buffer, current_mode);
          startNewMode(new_mode, lexem);
          return new_mode.returnBegin;
        }
  
        var end_level = endOfMode(modes.length - 1, lexem);
        if (end_level) {
          var markup = current_mode.className?'</span>':'';
          if (current_mode.returnEnd) {
            result += processBuffer(current_mode.buffer + buffer, current_mode) + markup;
          } else if (current_mode.excludeEnd) {
            result += processBuffer(current_mode.buffer + buffer, current_mode) + markup + escape(lexem);
          } else {
            result += processBuffer(current_mode.buffer + buffer + lexem, current_mode) + markup;
          }
          while (end_level > 1) {
            markup = modes[modes.length - 2].className?'</span>':'';
            result += markup;
            end_level--;
            modes.length--;
          }
          var last_ended_mode = modes[modes.length - 1];
          modes.length--;
          modes[modes.length - 1].buffer = '';
          if (last_ended_mode.starts) {
            startNewMode(last_ended_mode.starts, '');
          }
          return current_mode.returnEnd;
        }
  
        if (isIllegal(lexem, current_mode))
          throw 'Illegal';
      }
  
      var language = languages[language_name];
      var modes = [language.defaultMode];
      var relevance = 0;
      var keyword_count = 0;
      var result = '';
      try {
        var index = 0;
        language.defaultMode.buffer = '';
        do {
          var mode_info = eatModeChunk(value, index);
          var return_lexem = processModeInfo(mode_info[0], mode_info[1], mode_info[2]);
          index += mode_info[0].length;
          if (!return_lexem) {
            index += mode_info[1].length;
          }
        } while (!mode_info[2]);
        if(modes.length > 1)
          throw 'Illegal';
        return {
          relevance: relevance,
          keyword_count: keyword_count,
          value: result
        }
      } catch (e) {
        if (e == 'Illegal') {
          return {
            relevance: 0,
            keyword_count: 0,
            value: escape(value)
          }
        } else {
          throw e;
        }
      }
    }