🎉 Welcome to django-highlightjs 🎉

Use Highlight.js in your Django templates, the Django way.
🚀 Installation
-
Install using pip:
pip install django-highlightjs
Alternatively, you can download or clone this repo and call:
pip install -e .
-
Add to INSTALLED_APPS in your settings.py:
'highlightjs',
-
In your templates, load the highlightjs library and use the highlightjs_* tags.
⚙️ Settings
The django-highlightjs has some pre-configured settings.
They can be modified by adding a dict variable called HIGHLIGHTJS in your settings.py and customizing the values you want.
The HIGHLIGHTJS dict variable contains these settings and defaults:
HIGHLIGHTJS = {
'jquery_url': '//code.jquery.com/jquery.min.js',
'base_url': '//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/highlight.min.js',
'css_url': '//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/styles/{0}.min.css',
'include_jquery': False,
'style': 'monokai_sublime',
}
Usage in your settings.py:
HIGHLIGHTJS = {
'style': 'github',
}
All other styles are available at highlight.js styles.
📝 Example template
{% load highlightjs %}
<html>
<head>
<link href="{% highlightjs_css_url %}" rel='stylesheet' type='text/css'>
</head>
<body>
{# Highlight Syntax using Highlightjs #}
{% highlightjs_this code_to_highlight %}
{% highlightjs_this code_to_highlight 'python' %}
{% highlightjs_javascript jquery=1 %}
</body>
</html>
🛠️ Requirements
- Python 3.10, 3.11, 3.12 or 3.13
- Django >= 4.2
Contributions and pull requests for other Django and Python versions are welcome.
🐞 Bugs and requests
If you have found a bug or if you have a request for additional functionality, please use the issue tracker on GitHub.
GitHub Issues
📜 License
You can use this under the MIT license. See the LICENSE file for details.
👤 Author
My name is Mounir Messelmeni, you can reach me at messelmeni.mounir@gmail.com.