debian-mirror-gitlab/app/assets/javascripts/syntax_highlight.js

27 lines
793 B
JavaScript
Raw Normal View History

2017-08-17 22:00:37 +05:30
/* eslint-disable func-names, space-before-function-paren, consistent-return, no-var, no-else-return, prefer-arrow-callback, max-len */
2018-05-09 12:01:36 +05:30
import $ from 'jquery';
2016-09-29 09:46:39 +05:30
// 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-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
export default function syntaxHighlight(el) {
if ($(el).hasClass('js-syntax-highlight')) {
2017-09-10 17:25:29 +05:30
// Given the element itself, apply highlighting
2018-03-17 18:26:18 +05:30
return $(el).addClass(gon.user_color_scheme);
2017-09-10 17:25:29 +05:30
} else {
// Given a parent element, recurse to any of its applicable children
2018-03-17 18:26:18 +05:30
const $children = $(el).find('.js-syntax-highlight');
2017-09-10 17:25:29 +05:30
if ($children.length) {
2018-03-17 18:26:18 +05:30
return syntaxHighlight($children);
2016-09-13 17:45:13 +05:30
}
2017-09-10 17:25:29 +05:30
}
2018-03-17 18:26:18 +05:30
}