MCPcopy Create free account
hub / github.com/sql-js/sql.js / highlightBlock

Function highlightBlock

documentation/javascript/application.js:629–678  ·  view source on GitHub ↗
(block, tabReplace, useBR)

Source from the content-addressed store, hash-verified

627 two optional parameters for fixMarkup.
628 */
629 function highlightBlock(block, tabReplace, useBR) {
630 var text = blockText(block, useBR);
631 var language = blockLanguage(block);
632 var result, pre;
633 if (language == 'no-highlight')
634 return;
635 if (language) {
636 result = highlight(language, text);
637 } else {
638 result = highlightAuto(text);
639 language = result.language;
640 }
641 var original = nodeStream(block);
642 if (original.length) {
643 pre = document.createElement('pre');
644 pre.innerHTML = result.value;
645 result.value = mergeStreams(original, nodeStream(pre), text);
646 }
647 result.value = fixMarkup(result.value, tabReplace, useBR);
648
649 var class_name = block.className;
650 if (!class_name.match('(\\s|^)(language-)?' + language + '(\\s|$)')) {
651 class_name = class_name ? (class_name + ' ' + language) : language;
652 }
653 if (/MSIE [678]/.test(navigator.userAgent) && block.tagName == 'CODE' && block.parentNode.tagName == 'PRE') {
654 // This is for backwards compatibility only. IE needs this strange
655 // hack becasue it cannot just cleanly replace <code> block contents.
656 pre = block.parentNode;
657 var container = document.createElement('div');
658 container.innerHTML = '<pre><code>' + result.value + '</code></pre>';
659 block = container.firstChild.firstChild;
660 container.firstChild.className = pre.className;
661 pre.parentNode.replaceChild(container.firstChild, pre);
662 } else {
663 block.innerHTML = result.value;
664 }
665 block.className = class_name;
666 block.result = {
667 language: language,
668 kw: result.keyword_count,
669 re: result.relevance
670 };
671 if (result.second_best) {
672 block.second_best = {
673 language: result.second_best.language,
674 kw: result.second_best.keyword_count,
675 re: result.second_best.relevance
676 };
677 }
678 }
679
680 /*
681 Applies highlighting to all <pre><code>..</code></pre> blocks on a page.

Callers 1

initHighlightingFunction · 0.85

Calls 7

blockTextFunction · 0.85
blockLanguageFunction · 0.85
highlightFunction · 0.85
highlightAutoFunction · 0.85
nodeStreamFunction · 0.85
mergeStreamsFunction · 0.85
fixMarkupFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…