2020-04-30 00:09:37 +00:00
|
|
|
/* eslint-disable consistent-return */
|
2016-12-14 05:26:26 +00:00
|
|
|
|
2018-03-09 20:18:59 +00:00
|
|
|
import $ from 'jquery';
|
|
|
|
|
2016-07-27 03:32:10 +00:00
|
|
|
// Syntax Highlighter
|
|
|
|
//
|
|
|
|
// Applies a syntax highlighting color scheme CSS class to any element with the
|
|
|
|
// `js-syntax-highlight` class
|
|
|
|
//
|
|
|
|
// ### Example Markup
|
|
|
|
//
|
|
|
|
// <div class="js-syntax-highlight"></div>
|
|
|
|
//
|
2016-12-09 00:15:08 +00:00
|
|
|
|
2017-12-13 09:26:44 +00:00
|
|
|
export default function syntaxHighlight(el) {
|
|
|
|
if ($(el).hasClass('js-syntax-highlight')) {
|
2017-07-05 17:20:41 +00:00
|
|
|
// Given the element itself, apply highlighting
|
2017-12-13 09:26:44 +00:00
|
|
|
return $(el).addClass(gon.user_color_scheme);
|
2020-04-30 00:09:37 +00:00
|
|
|
}
|
|
|
|
// Given a parent element, recurse to any of its applicable children
|
|
|
|
const $children = $(el).find('.js-syntax-highlight');
|
|
|
|
if ($children.length) {
|
|
|
|
return syntaxHighlight($children);
|
2017-07-05 17:20:41 +00:00
|
|
|
}
|
2017-12-13 09:26:44 +00:00
|
|
|
}
|