gitlab-org--gitlab-foss/app/assets/javascripts/syntax_highlight.js

26 lines
675 B
JavaScript
Raw Normal View History

/* eslint-disable consistent-return */
import $ from 'jquery';
// 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>
//
2017-12-13 04:26:44 -05:00
export default function syntaxHighlight(el) {
if ($(el).hasClass('js-syntax-highlight')) {
// Given the element itself, apply highlighting
2017-12-13 04:26:44 -05:00
return $(el).addClass(gon.user_color_scheme);
}
// 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-12-13 04:26:44 -05:00
}