Skip to content

Commit

Permalink
Add TeX rendering to CodeHelp response view. Fixes #6.
Browse files Browse the repository at this point in the history
  • Loading branch information
liffiton committed Nov 10, 2024
1 parent b4abb45 commit 243e923
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/codehelp/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
- Do not write a corrected or updated version of the student's code. You must not write code for the student.
- Use Markdown formatting, including ` for inline code.
- Use TeX syntax for mathematical formulas, wrapping them in \\(...\\) or \\[...\\] as appropriate.
- Do not write a heading for the response.
- Do not write any example code blocks.
- If the student wrote in a language other than English, always respond in the student's own language.
Expand Down
9 changes: 8 additions & 1 deletion src/codehelp/templates/help_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@
{% extends "base.html" %}
{% from "recent_queries.html" import recent_queries %}

{% block extrahead %}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" integrity="sha384-nB0miv6/jRmo5UMMR1wu3Gz6NLsoTkbqJghGIsx//Rlm+ZU03BU6SQNC66uf4l5+" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js" integrity="sha384-7zkQWkzuo3B5mTepMUcHkMB5jZaolc2xDwL6VFqjFALcbeS9Ggm/Yr2r3Dy4lfFg" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/auto-render.min.js" integrity="sha384-43gviWU0YVjaDtb/GhzOouOXtZMP/7XUzwPTstBeZFe/+rCMvRwr4yROQP43s0Xk" crossorigin="anonymous"
onload="renderMathInElement(document.querySelector('#codehelp_response'));"></script>
{% endblock %}

{% block body %}
<div class="columns is-desktop is-gapless">
<div class="column is-three-quarters-desktop">
<section class="section">
<section class="section" id="codehelp_response">
{% if query %}

<div class="container">
Expand Down
3 changes: 2 additions & 1 deletion src/gened/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ def fmt_response_txt(value: str) -> str:
return markupsafe.Markup(html_string)

# Jinja filter for converting Markdown to HTML
markdown_processor = MarkdownIt("js-default") # https://markdown-it-py.readthedocs.io/en/latest/security.html
markdown_processor = MarkdownIt("js-default") # js-default: https://markdown-it-py.readthedocs.io/en/latest/security.html
markdown_processor.inline.ruler.disable(['escape']) # disable escaping so that \(, \[, etc. come through for TeX math

@app.template_filter('markdown')
def markdown_filter(value: str) -> str:
Expand Down

0 comments on commit 243e923

Please sign in to comment.