MCPcopy
hub / github.com/GitbookIO/gitbook / highlightCode

Function highlightCode

lib/output/modifiers/highlightCode.js:41–56  ·  view source on GitHub ↗

Highlight all code elements @param {Function(lang, body) -> String} highlight @param {HTMLDom} $ @return {Promise}

(highlight, $)

Source from the content-addressed store, hash-verified

39 @return {Promise}
40*/
41function highlightCode(highlight, $) {
42 return editHTMLElement($, 'code', function($code) {
43 var classNames = ($code.attr('class') || '').split(' ');
44 var lang = getLanguageForClass(classNames);
45 var source = $code.text();
46
47 return Promise(highlight(lang, source))
48 .then(function(r) {
49 if (is.string(r.html)) {
50 $code.html(r.html);
51 } else {
52 $code.text(r.text);
53 }
54 });
55 });
56}
57
58module.exports = highlightCode;

Callers 1

highlightCode.jsFile · 0.85

Calls 2

editHTMLElementFunction · 0.85
getLanguageForClassFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…