Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 6 additions & 17 deletions mathics_django/web/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,6 @@
}


def safe_html_string(value):
"""
Escape characters in the
"""
# TODO: check why the escaped characters are converted back to valid
# HTML code and processed.
return value # mark_safe(escape_html(value))


def format_output(evaluation, expr, html_tag_format=None):
"""
Handle unformatted output using the *specific* capabilities \
Expand Down Expand Up @@ -69,17 +60,16 @@ def format_output(evaluation, expr, html_tag_format=None):
# In particular for FullForm and InputForm output, we don't want
# MathML, we want
# plain-ol' text so we can cut and paste that.
expr_type = expr.get_head_name()
if expr_type in FORM_TO_HTML_TAG_FORMAT:
expr_head = expr.get_head_name()
if expr_head in FORM_TO_HTML_TAG_FORMAT:
# For these forms, we strip off the outer "Form" part
html_tag_format = FORM_TO_HTML_TAG_FORMAT[expr_type]
html_tag_format = FORM_TO_HTML_TAG_FORMAT[expr_head]

# This part is similar to mathics.core.evaluation.format_output().
if html_tag_format == "text":
boxed = format_element(expr, evaluation, SymbolOutputForm)
result = f'"{boxed.to_text()}"'
return f'"{boxed.to_text()}"'

return safe_html_string(result)
elif html_tag_format == "xml":
boxed = format_element(expr, evaluation, SymbolStandardForm)
if (
Expand All @@ -93,12 +83,11 @@ def format_output(evaluation, expr, html_tag_format=None):
return box_value[1:-1]

# This can happen.
result = (
return (
'<math display="block">'
f"{boxed.to_mathml(evaluation=evaluation)}"
"</math>"
)
return safe_html_string(result)
elif html_tag_format == "LaTeX":
boxed = format_element(expr, evaluation, SymbolTeXForm)
if hasattr(boxed, "head") and boxed.head is SymbolInterpretationBox:
Expand All @@ -117,6 +106,6 @@ def format_output(evaluation, expr, html_tag_format=None):
result = boxed.to_text()
else:
result = boxed.to_tex(evaluation=evaluation)
return safe_html_string(result)
return result

raise ValueError
File renamed without changes.
6 changes: 4 additions & 2 deletions mathics_django/web/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from mathics.core.evaluation import Message, Result
from mathics.settings import TIMEOUT, default_pymathics_modules

from mathics_django.web.forms import LoginForm, SaveForm
from mathics_django.web.html_forms import LoginForm, SaveForm
from mathics_django.web.models import Query, Worksheet, get_session_evaluation

html_formatter = HtmlFormatter(noclasses=True)
Expand All @@ -42,7 +42,9 @@
class JsonResponse(HttpResponse):
def __init__(self, result={}):
response = json.dumps(result)
super(JsonResponse, self).__init__(response, content_type=JSON_CONTENT_TYPE)
super(JsonResponse, self).__init__(
response.encode("UTF-8"), content_type=JSON_CONTENT_TYPE
)


def delete(request):
Expand Down
Loading