highlighter.js
function highlightSections (sections, lang) {
  if (!supported(lang)) {
    return sections
  }

  // Keep track of the most recent stacks.
  var additionStack
  var deletionStack

  sections
    .forEach(function (section) {
      var type = section.type

      // Reset the stacks for metadata types.
      if (type === 'header' || type === 'chunk') {
        additionStack = deletionStack = null

        return
      }

      var value = section.lines.join(SEPARATOR)
      var stack = type === 'deletion' ? deletionStack : additionStack
      var highlight = hljs.highlight(lang, value, false, stack)

      // Set the top of each stack, depending on context.
      if (type === 'addition') {
        additionStack = highlight.top
      } else if (type === 'deletion') {
        deletionStack = highlight.top
      } else {
        additionStack = deletionStack = highlight.top
      }

      section.lines = highlight.value.split(SEPARATOR)
    })

  return sections
}
function highlightSections (sections, lang) {
  if (!supported(lang)) {
    return sections
  }

  // Keep track of the most recent stacks.
  var additionStack
  var deletionStack

  sections
    .forEach(function (section) {
      var type = section.type

      // Reset the stacks for metadata types.
      if (type === 'header' || type === 'chunk') {
        additionStack = deletionStack = null

        return
      }

      var value = section.lines.join(SEPARATOR)
      var stack = type === 'deletion' ? deletionStack : additionStack
      var highlight = hljs.highlight(lang, value, false, stack)

      // Set the top of each stack, depending on context.
      if (type === 'addition') {
        additionStack = highlight.top
      } else if (type === 'deletion') {
        deletionStack = highlight.top
      } else {
        additionStack = deletionStack = highlight.top
      }

      section.lines = highlight.value.split(SEPARATOR)
    })

  return sections
}
function highlightSections ( sections , lang ) { if ( ! supported ( lang ) ) { return sections } // Keep track of the most recent stacks. var additionStack var deletionStack sections . forEach ( function ( section ) { var type = section . type // Reset the stacks for metadata types. if ( type === 'header' || type === 'chunk' ) { additionStack = deletionStack = null return } var value = section . lines . join ( SEPARATOR ) var stack = type === 'deletion' ? deletionStack : additionStack var highlight = hljs . highlight ( lang , value , false , stack ) // Set the top of each stack, depending on context. if ( type === 'addition' ) { additionStack = highlight . top } else if ( type === 'deletion' ) { deletionStack = highlight . top } else { additionStack = deletionStack = highlight . top } section . lines = highlight . value . split ( SEPARATOR ) } ) return sections }
Add syntax highlighting to all sections.

@param  {Array}  sections
@param  {String} lang
@return {Array}
Add syntax highlighting to all sections .