Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing issue #746 #751

Merged
merged 2 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions codethesaurus/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,9 @@
}
}

SIMILAR_LEXERS = {
"clips": "prolog",
}

# Configure Django App for Heroku.
django_on_heroku.settings(locals(), test_runner=False, databases=False, staticfiles=True, logging=True)
14 changes: 13 additions & 1 deletion web/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
from pygments import highlight
from pygments.formatters.html import HtmlFormatter
from pygments.lexers import get_lexer_by_name
from pygments.util import ClassNotFound
from django.conf import settings

from web.models import (
Language,
Expand Down Expand Up @@ -307,6 +309,15 @@ def error_handler_500_server_error(request):
response = render(request, 'error500.html')
return HttpResponseServerError(response)

#get lexer
def get_highlighter(language):
SIMILAR_LEXERS = settings.SIMILAR_LEXERS
try:
lexer = get_lexer_by_name(language, startinline=True)
except ClassNotFound:

ayaan-qadri marked this conversation as resolved.
Show resolved Hide resolved
lexer = get_lexer_by_name(SIMILAR_LEXERS.get(language, "text"), startinline=True)
return lexer

# Helper functions
def format_code_for_display(concept_key, lang):
Expand All @@ -322,9 +333,10 @@ def format_code_for_display(concept_key, lang):
if lang.concept_unknown(concept_key) or lang.concept_code(concept_key) is None:
return "Unknown"
if lang.concept_implemented(concept_key):
lexer = get_highlighter(lang.key)
return highlight(
lang.concept_code(concept_key),
get_lexer_by_name(lang.key, startinline=True),
lexer,
HtmlFormatter()
)
return None
Expand Down
Loading