I'm having trouble using jQuery to retrieve a HTML string retuned by Django. In a Django template I have the line
{{ generated_files.exercise_instructions.content | safe}}
which when expanded contains the string 2. Määritä luvun <span class="inline-math"> -6 </span> vastaluku.
, as shown in the picture below:
I would like to be able to use KaTeX to render the contents of the span element as math, but
$(".inline-math").each(
function(i, element) {
console.log("Rivimatikkaa: " + element.innerHTML);
katex.render(element.innerHTML,element);
}
);
does nothing towards this end. The span element of class inline-math
is not detected by jQuery, as the console.log(element.innerHTML)
does nothing, nor is the math rendered.
My question therefore is, how do I detect a string, that contains LaTeX returned by Django, in order to render it as math using KaTeX?
P.S.
As an interesting sidenote, here are pictures of the page source with and without the safe
filter in the Django tag.
Notice the extra ampersands. That is the only difference, however. The string is not interpreted as HTML in either case.