Skip to content

Commit

Permalink
merge: branch '111-keyerror-at-riskpredictorlist-bic' into 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
rmnldwg committed Dec 5, 2023
2 parents fd03a26 + e70a79f commit 8c61c85
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
4 changes: 4 additions & 0 deletions lyprox/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
<meta charset="UTF-8">
{% block head %}{% endblock %}

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex/dist/katex.min.css" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/katex/dist/katex.min.js" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/katex/dist/contrib/mathtex-script-type.min.js" defer></script>

<!-- Stylesheets -->
<link rel="stylesheet" type="text/css" href="{% static 'usz.css' %}">
<link href="{% static 'fontawesomefree/css/all.min.css' %}" rel="stylesheet" type="text/css">
Expand Down
17 changes: 13 additions & 4 deletions lyprox/templatetags/customtags.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,21 @@
import yaml
from django import template
from django.template.loader import render_to_string
from django.utils.html import format_html
from django.utils.safestring import mark_safe
from mdx_math import MathExtension

register = template.Library()
logger = logging.getLogger(__name__)


class MyMathExtension(MathExtension):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.config.update({
"enable_dollar_delimiter": [True, "Enable single-dollar delimiter"],
})


@register.filter(name="index")
def index(indexable, i):
return indexable[int(f"{i}".lower())]
Expand Down Expand Up @@ -42,7 +51,7 @@ def percent(indexable, i):
return f"{100 * indexable[i] / total:.0f}"

def custom_markdown(text):
return md.markdown(text, extensions=["footnotes", "tables"])
return md.markdown(text, extensions=["footnotes", "tables", MyMathExtension()])

@register.simple_tag(name="include_md", takes_context=True)
def include_md(context, template_name):
Expand All @@ -52,11 +61,11 @@ def include_md(context, template_name):
template = render_to_string(template_name, context=context_dict)

html_string = custom_markdown(template)
return format_html(html_string)
return mark_safe(html_string)

@register.simple_tag(name="render_md")
def render_md(raw):
return format_html(custom_markdown(raw))
return mark_safe(custom_markdown(raw))

@register.simple_tag(name="render_json")
def render_json(raw):
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ dependencies = [
"lyscripts ~= 0.6.6",
"PyGithub ~= 1.58",
"dateparser ~= 1.1",
"python-markdown-math ~= 0.8",
]

[project.urls]
Expand Down

0 comments on commit 8c61c85

Please sign in to comment.