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

26 lines
675 B
JavaScript
Raw Normal View History

2020-05-24 23:13:21 +05:30
/* eslint-disable consistent-return */
2017-08-17 22:00:37 +05:30
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);
2020-05-24 23:13:21 +05:30
}
// 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-09-10 17:25:29 +05:30
}
2018-03-17 18:26:18 +05:30
}