BigW Consortium Gitlab

Commit 525c2a78 by Munken

Math works for inline syntax

parent 9ab1fe5e
......@@ -9,8 +9,53 @@
// <div class="js-syntax-highlight"></div>
//
(function() {
// CSS and JS for KaTeX
CSS_PATH = "<%= asset_path('katex.css') %>";
JS_PATH = "<%= asset_path('katex.js') %>";
// Only load once
var katexLoaded = false;
// Loop over all math elements and render math
var renderWithKaTeX = function (elements) {
elements.each(function () {
$(this).hide();
var mathNode = $( "<math>Test</math>" );
mathNode.insertAfter($(this));
katex.render($(this).text(), mathNode.get(0), { displayMode: false })
})
};
var handleMath = function () {
var mathElements = $('.code.math');
if (mathElements.length == 0) return;
if (katexLoaded) renderWithKaTeX(mathElements);
else {
// Request CSS file so it is in the cache
$.get(CSS_PATH, function(){
var css = $('<link>',
{rel:'stylesheet',
type:'text/css',
href: CSS_PATH
});
css.appendTo('head');
// Load KaTeX js
$.getScript(JS_PATH, function() {
katexLoaded = true;
renderWithKaTeX(mathElements); // Run KaTeX
})
});
}
};
$.fn.syntaxHighlight = function() {
var $children;
handleMath();
if ($(this).hasClass('js-syntax-highlight')) {
// Given the element itself, apply highlighting
return $(this).addClass(gon.user_color_scheme);
......
......@@ -20,8 +20,6 @@ module Banzai
closing
end
puts doc
doc
end
end
......
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment