highlighter.js
function diff (code, lang) {
  var sections = []

  code.split(/\r?\n/g).forEach(function (line) {
    var type

    if (CHUNK_REGEXP.test(line)) {
      type = 'chunk'
    } else if (HEADER_REGEXP.test(line)) {
      type = 'header'
    } else {
      type = PATCH_TYPES[line[0]] || 'null'
      line = line.replace(/^[+\-! ]/, '')
    }

    // Merge data with the previous section where possible.
    var previous = sections[sections.length - 1]

    if (!previous || previous.type !== type) {
      sections.push({
        type: type,
        lines: [line]
      })

      return
    }

    previous.lines.push(line)
  })

  return highlightSections(sections, lang)
    .map(function (section) {
      var type = section.type
      var value = section.lines.join(SEPARATOR)

      return '<span class="diff-' + type + '">' + value + '</span>'
    })
    .join(SEPARATOR)
}
function diff (code, lang) {
  var sections = []

  code.split(/\r?\n/g).forEach(function (line) {
    var type

    if (CHUNK_REGEXP.test(line)) {
      type = 'chunk'
    } else if (HEADER_REGEXP.test(line)) {
      type = 'header'
    } else {
      type = PATCH_TYPES[line[0]] || 'null'
      line = line.replace(/^[+\-! ]/, '')
    }

    // Merge data with the previous section where possible.
    var previous = sections[sections.length - 1]

    if (!previous || previous.type !== type) {
      sections.push({
        type: type,
        lines: [line]
      })

      return
    }

    previous.lines.push(line)
  })

  return highlightSections(sections, lang)
    .map(function (section) {
      var type = section.type
      var value = section.lines.join(SEPARATOR)

      return '<span class="diff-' + type + '">' + value + '</span>'
    })
    .join(SEPARATOR)
}
function diff ( code , lang ) { var sections = [ ] code . split ( / \r?\n / g ) . forEach ( function ( line ) { var type if ( CHUNK_REGEXP . test ( line ) ) { type = 'chunk' } else if ( HEADER_REGEXP . test ( line ) ) { type = 'header' } else { type = PATCH_TYPES [ line [ 0 ] ] || 'null' line = line . replace ( / ^[+\-! ] / , '' ) } // Merge data with the previous section where possible. var previous = sections [ sections . length - 1 ] if ( ! previous || previous . type !== type ) { sections . push ( { type : type , lines : [ line ] } ) return } previous . lines . push ( line ) } ) return highlightSections ( sections , lang ) . map ( function ( section ) { var type = section . type var value = section . lines . join ( SEPARATOR ) return '<span class="diff-' + type + '">' + value + '</span>' } ) . join ( SEPARATOR ) }
Add diff syntax highlighting to code.

@param  {String} code
@param  {String} lang
@return {String}
Add diff syntax highlighting to code .