Add syntax highlighting to all sections.

@param  {Array}  sections
@param  {String} lang
@return {Array}
777252
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
}
554928
function appendDecorations(basePos, sourceCode, langHandler, out) {
    if (!sourceCode) { return; }
    var job = {
      sourceCode: sourceCode,
      basePos: basePos
    };
    langHandler(job);
    out.push.apply(out, job.decorations);
  }
930930
function markdown(text, nohl) {
    let r, codes;

    md.set({
      highlight: (str, lang) => {
        let esc = md.utils.escapeHtml;

        try {
          if (lang && lang !== 'auto' && hljs.getLanguage(lang)) {
            return '<pre class="hljs language-' + esc(lang.toLowerCase()) + '"><code>' +
                   hljs.highlight(lang, str, true).value +
                   '</code></pre>';

          } else if (!lang || lang === 'auto') {
            let result = hljs.highlightAuto(str);

            return '<pre class="hljs language-' + esc(result.language) + '"><code>' +
                   result.value +
                   '</code></pre>';
          }
        } catch (__) { /**/ }

        return '<pre class="hljs"><code>' + esc(str) + '</code></pre>';
      }
    });

    md.renderer.rules['code_block'] = function (tokens, idx /*, options, env */) {
      let esc = md.utils.escapeHtml;
      return '<pre class="hljs"><code>' + esc(tokens[idx].content) + '</code></pre>\n';
    };

    if (nohl) md.set({ highlight: null });

    r = md.render(text);

    // FIXME
    // desugar [[foo#bar]] tokens into local links
    // N.B. in order to not apply conversion in <code> blocks,
    // we first store replace code blocks with nonces
    codes = {};
    r = r.replace(/(<code>[\s\S]*?<\/code>)/g, (all, def) => {
      let nonce = Math.random().toString().substring(2);
      codes[nonce] = def;
      return `@-=@=-@${nonce}@-=@=-@`;
    });

    // convert [[link]] to links
    r = r.replace(/\[\[([\s\S]+?)\]\]/g, (all, def) => {
      def = def.split(/\s+/);
      id = def.shift();
      // invalid references don't produce links
      if (!list[id]) {
        if (options.brokenLinks === 'throw') {
          throw new Error(`Link is broken: ${all}\n${r}`);
        }
        return options.brokenLinks === 'show' ? all : id;
      }

      let obj = _.extend({ name: def.join(' ') || id }, list[id]);
      return link(obj, false, [ 'link-short' ]);
    });
    // restore code blocks, given previously stored nonces
    r = r.replace(/@-=@=-@(\d+)@-=@=-@/g, (all, nonce) => codes[nonce]);
    //
    return r;
  }
606127
function jsonSections(sections, block) {

  return sections.map(function(section) {
    // Temporary inserting of partial
    var partial = section;
    if (partial.markup() && partial.markup().toString().match(/^[^\n]+\.(html|hbs|pug)$/)) {
      partial.file = partial.markup().toString();
      partial.name = path.basename(partial.file, path.extname(partial.file));
      partial.file = path.dirname(block.filePath) + '/' + partial.file;
      partial.markupText = fs.readFileSync(partial.file, 'utf8');
      section.markup = function() {
        return partial.markupText;
      };
    }

    return {
      header: generateDescription(section.header(), {noWrapper: true}),
      description: generateDescription(section.description()),
      modifiers: jsonModifiers(section.modifiers()),
      deprecated: section.deprecated(),
      experimental: section.experimental(),
      reference: section.reference(),
      markup: section.markup() ? section.markup().toString() : null
    };
  });
}
705522
public void addTickMarkSection(final Section SECTION) {
        if (null == SECTION) return;
        tickMarkSections.add(SECTION);
        Collections.sort(tickMarkSections, new SectionComparator());
        fireUpdateEvent(REDRAW_EVENT);
    }
555417
function highlight() {
    $('pre code').each(function (i, block) {
      hljs.highlightBlock(block);
    });
    $('pre code[highlight-lines]').each(function (i, block) {
      if (block.innerHTML === "") return;
      var lines = block.innerHTML.split('\n');

      queryString = block.getAttribute('highlight-lines');
      if (!queryString) return;

      var ranges = queryString.split(',');
      for (var j = 0, range; range = ranges[j++];) {
        var found = range.match(/^(\d+)\-(\d+)?$/);
        if (found) {
          // consider region as `{startlinenumber}-{endlinenumber}`, in which {endlinenumber} is optional
          var start = +found[1];
          var end = +found[2];
          if (isNaN(end) || end > lines.length) {
            end = lines.length;
          }
        } else {
          // consider region as a sigine line number
          if (isNaN(range)) continue;
          var start = +range;
          var end = start;
        }
        if (start <= 0 || end <= 0 || start > end || start > lines.length) {
          // skip current region if invalid
          continue;
        }
        lines[start - 1] = '<span class="line-highlight">' + lines[start - 1];
        lines[end - 1] = lines[end - 1] + '</span>';
      }

      block.innerHTML = lines.join('\n');
    });
  }
370807
public Section addSection(float indentation, String title, int numberDepth) {
        return addSection(indentation, new Paragraph(title), numberDepth);
    }
990770
def tableize_code (str, lang = '')
      table = '<div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers">'
      code = ''
      str.lines.each_with_index do |line,index|
        table += "<span class='line-number'>#{index+1}</span>\n"
        code  += "<span class='line'>#{line}</span>"
      end
      table += "</pre></td><td class='code'><pre><code class='#{lang}'>#{code}</code></pre></td></tr></table></div>"
    end
1300026
public void addSectionHandling( String name, EnumMap<SIT, EnumMap<CIT, Boolean>> sh ){
		sectionHandling.put( SectionType.USER_SECTION.toString() + name.toUpperCase(), sh);
	}
70798
function (out, args) {
            var sections = args.sections;
            for (var i = 0, l = sections.length; i < l; i++) {
                this.__$insertSection(null, sections[i]);
            }
        }
1343845
public function addSections($sections)
    {
        if (current($sections) instanceof Section) {
            foreach ($sections as $section) {
                $this->addSection($section);
            }
        } else {
            foreach ($sections as $key => $value) {
                $this->addSection($key, $value);
            }
        }
    }
780880
public boolean doesContainCodeSnippetForAnyLanguage(@Nonnull @MustNotContainNull String ... languageNames) {
    boolean result = false;
    if (!this.codeSnippets.isEmpty()){
      for(final String s : languageNames){
        if (this.codeSnippets.containsKey(s)){
          result = true;
          break;
        }
      }
    }
    return result;
  }
853110
function addInvisibles(grammar) {
		if (!grammar || grammar['tab']) {
			return;
		}

		// assign invisibles here to "mark" the grammar in case of self references
		for (var name in invisibles) {
			if (invisibles.hasOwnProperty(name)) {
				grammar[name] = invisibles[name];
			}
		}

		for (var name in grammar) {
			if (grammar.hasOwnProperty(name) && !invisibles[name]) {
				if (name === 'rest') {
					addInvisibles(grammar['rest']);
				} else {
					handleToken(grammar, name);
				}
			}
		}
	}
1195910
function(sections, pathToSpec) {
    var deferred = Q.defer();

    // Parsing spec with JSdom
    jsdom.env(
        'http://127.0.0.1:' + global.opts.core.server.port + pathToSpec + '?internal=true',
        ['http://127.0.0.1:' + global.opts.core.server.port + '/source/assets/js/modules/sectionsParser.js'],
        function (err, window) {
            if (err) {
                deferred.reject({
                    err: err,
                    msg: 'JSDOM error'
                });
                return;
            }

            var output = {};

            var SourceGetSections = window.SourceGetSections;

            var parser = new SourceGetSections();
            var allContents = parser.getSpecFull();

            if (sections) {
                output = parser.getSpecFull(sections);
            } else {
                output = allContents;
            }

            if (output) {
                deferred.resolve({
                    output: output,
                    allContents: allContents
                });
            } else {
                deferred.reject({
                    msg: 'Requested sections HTML not found'
                });
            }
        }
    );

    return deferred.promise;
}
268426
public static function removeSectionLanguages($sectionsFile)
    {
        if (!is_file($sectionsFile)) {
            throw new \InvalidArgumentException(sprintf(
                'Section file "%s" not found.',
                $sectionsFile
            ));
        }

        $sections = Yaml::parse($sectionsFile);

        foreach ($sections as $section => $sectionInfo) {
            $sections[$section]['languages'] = null;
        }

        file_put_contents($sectionsFile, Yaml::dump($sections));
    }
220761
function(editor, syntax, profile) {
			var info = editorUtils.outputInfo(editor, syntax, profile);
			if (!~cssSyntaxes.indexOf(info.syntax)) {
				return false;
			}
			
			// let's see if we are expanding gradient definition
			var caret = editor.getCaretPos();
			var content = info.content;
			var gradients = this.gradientsFromCSSProperty(content, caret);
			if (gradients) {
				if (!isValidCaretPosition(gradients, caret, info.syntax)) {
					return false;
				}

				var cssProperty = gradients.property;
				var cssRule = cssProperty.parent;
				var ruleStart = cssRule.options.offset || 0;
				var ruleEnd = ruleStart + cssRule.toString().length;
				
				// Handle special case:
				// user wrote gradient definition between existing CSS 
				// properties and did not finished it with semicolon.
				// In this case, we have semicolon right after gradient 
				// definition and re-parse rule again
				if (/[\n\r]/.test(cssProperty.value())) {
					// insert semicolon at the end of gradient definition
					var insertPos = cssProperty.valueRange(true).start + utils.last(gradients.gradients).matchedPart.end;
					content = utils.replaceSubstring(content, ';', insertPos);
					
					var _gradients = this.gradientsFromCSSProperty(content, caret);
					if (_gradients) {
						gradients = _gradients;
						cssProperty = gradients.property;
						cssRule = cssProperty.parent;
					}
				}
				
				// make sure current property has terminating semicolon
				cssProperty.end(';');
				
				// resolve CSS property name
				var resolvedName = resolvePropertyName(cssProperty.name(), syntax);
				if (resolvedName) {
					cssProperty.name(resolvedName);
				}
				
				pasteGradient(cssProperty, gradients.gradients);
				editor.replaceContent(cssRule.toString(), ruleStart, ruleEnd, true);
				return true;
			}
			
			return this.expandGradientOutsideValue(editor, syntax);
		}
992559
function (lang) {
		if (lang_data[lang] && lang_data[lang].success_callbacks && lang_data[lang].success_callbacks.length) {
			lang_data[lang].success_callbacks.forEach(function (f) {
				f(lang);
			});
		}
	}