From 562aae86f3e290c319ae9c792e9fecd821666f33 Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sun, 25 Aug 2019 00:16:39 +0200 Subject: [PATCH] Code highlighting --- app.py | 2 ++ requirements.txt | 1 + templates/layout.html | 1 + templates/utils.html | 4 ++-- utils/highlight.py | 30 ++++++++++++++++++++++++++++++ utils/template_filters.py | 6 ++++++ 6 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 utils/highlight.py diff --git a/app.py b/app.py index bc16091..bf2f838 100644 --- a/app.py +++ b/app.py @@ -72,6 +72,7 @@ from core.shared import noindex from core.shared import paginated_query from utils.blacklist import is_blacklisted from utils.emojis import EMOJIS +from utils.highlight import HIGHLIGHT_CSS from utils.key import get_secret_key from utils.template_filters import filters @@ -153,6 +154,7 @@ def inject_config(): else 0, me=ME, base_url=config.BASE_URL, + highlight_css=HIGHLIGHT_CSS, ) diff --git a/requirements.txt b/requirements.txt index 3e81189..5c0a865 100644 --- a/requirements.txt +++ b/requirements.txt @@ -24,3 +24,4 @@ pyyaml pillow emoji-unicode html5lib +Pygments diff --git a/templates/layout.html b/templates/layout.html index a71eab7..be29498 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -21,6 +21,7 @@ width: 25px; height: 25px; } +{{ highlight_css }} {% block headers %}{% endblock %} diff --git a/templates/utils.html b/templates/utils.html index caeace5..10a2303 100644 --- a/templates/utils.html +++ b/templates/utils.html @@ -77,7 +77,7 @@ {% if obj | has_type(['Article', 'Page']) %} {{ obj.name }} {{ obj | url_or_id | get_url }} {% elif obj | has_type('Question') %} - {{ obj.content | clean | replace_custom_emojis(obj) | safe }} + {{ obj.content | clean | replace_custom_emojis(obj) | code_highlight | safe }}