mirror of
https://github.com/discourse/discourse.git
synced 2025-02-05 13:41:02 +08:00
16 lines
436 B
JavaScript
16 lines
436 B
JavaScript
/*global hljs:true */
|
|
|
|
import loadScript from 'discourse/lib/load-script';
|
|
|
|
export default function highlightSyntax($elem) {
|
|
const selector = Discourse.SiteSettings.autohighlight_all_code ? 'pre code' : 'pre code[class]',
|
|
path = Discourse.HighlightJSPath;
|
|
|
|
if (!path) { return; }
|
|
|
|
$(selector, $elem).each(function(i, e) {
|
|
$(e).removeClass('lang-auto');
|
|
loadScript(path).then(() => hljs.highlightBlock(e));
|
|
});
|
|
}
|