2018-06-16 09:20:30 -04:00
|
|
|
/* eslint-disable consistent-return, no-else-return */
|
2016-12-14 00:26:26 -05:00
|
|
|
|
2018-03-09 15:18:59 -05:00
|
|
|
import $ from 'jquery';
|
|
|
|
|
2016-07-26 23:32:10 -04: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-08 19:15:08 -05:00
|
|
|
|
2017-12-13 04:26:44 -05:00
|
|
|
export default function syntaxHighlight(el) {
|
|
|
|
if ($(el).hasClass('js-syntax-highlight')) {
|
2017-07-05 13:20:41 -04:00
|
|
|
// Given the element itself, apply highlighting
|
2017-12-13 04:26:44 -05:00
|
|
|
return $(el).addClass(gon.user_color_scheme);
|
2017-07-05 13:20:41 -04:00
|
|
|
} else {
|
|
|
|
// Given a parent element, recurse to any of its applicable children
|
2017-12-13 04:26:44 -05:00
|
|
|
const $children = $(el).find('.js-syntax-highlight');
|
2017-07-05 13:20:41 -04:00
|
|
|
if ($children.length) {
|
2017-12-13 04:26:44 -05:00
|
|
|
return syntaxHighlight($children);
|
2016-07-24 16:45:11 -04:00
|
|
|
}
|
2017-07-05 13:20:41 -04:00
|
|
|
}
|
2017-12-13 04:26:44 -05:00
|
|
|
}
|