Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
geekygirlsarah authored Oct 5, 2024
2 parents a9745cb + f3f6408 commit c6b3763
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check-docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Docker Compose Build
run: docker-compose build
run: docker compose build
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)
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ bleach==6.1.0
colorama==0.4.6
dill==0.3.7
dj-database-url==2.1.0
Django==4.2.14
Django==4.2.15
django-markdownify==0.9.3
django-on-heroku==1.1.2
gunicorn==22.0.0
Expand Down
13 changes: 12 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,14 @@ 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:
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 +332,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

0 comments on commit c6b3763

Please sign in to comment.