Skip to content

Commit 152354d

Browse files
committed
Update scripts.html to get settings variables
1 parent 1b353bb commit 152354d

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

latexify/latexify/templates/latexify/scripts.html

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
{% load latexify %}
12
<script src="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.6.0/katex.min.js"></script>
23
<script>
3-
var math_latex_inline_elements = document.getElementsByClassName("django-latexify math inline");
4-
var math_latex_block_elements = document.getElementsByClassName("django-latexify math block");
4+
5+
var math_latex_inline_elements = document.getElementsByClassName('{% value_from_settings "LATEX_MATH_INLINE_CSS_CLASS" %}');
6+
var math_latex_block_elements = document.getElementsByClassName('{% value_from_settings "LATEX_MATH_BLOCK_CSS_CLASS" %}');
57
latex_render_math(math_latex_inline_elements, false);
68
latex_render_math(math_latex_block_elements, true);
79

latexify/latexify/templatetags/latexify.py

+19
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,22 @@ def latexify(text,
8282

8383
return {'latex_type': latex_type,
8484
'latex_text': mark_safe(text)}
85+
86+
87+
@register.tag
88+
def value_from_settings(parser, token):
89+
try:
90+
# split_contents() knows not to split quoted strings.
91+
tag_name, var = token.split_contents()
92+
except ValueError:
93+
raise template.TemplateSyntaxError, "%r tag requires a single argument" % token.contents.split()[0]
94+
return ValueFromSettings(var)
95+
96+
97+
class ValueFromSettings(template.Node):
98+
def __init__(self, var):
99+
self.arg = template.Variable(var)
100+
101+
def render(self, context):
102+
return getattr(latex_settings,
103+
re.sub(r'\W+', '', str(self.arg)))

0 commit comments

Comments
 (0)