A Django app to easyily integrate highlight.js syntax highlighter.
Project description
🎉 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 yoursettings.py
:'highlightjs',
-
In your templates, load the
highlightjs
library and use thehighlightjs_*
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 = {
# The URL to the jQuery JavaScript file
'jquery_url': '//code.jquery.com/jquery.min.js',
# The highlight.js base URL
'base_url': '//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/highlight.min.js',
# The complete URL to the highlight.js CSS file
'css_url': '//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/styles/{0}.min.css',
# Include jQuery with highlight.js JavaScript (affects django-highlightjs template tags)
'include_jquery': False,
# The default used style.
'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, or 3.12
- 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.
📜 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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django_highlightjs-0.2.13.tar.gz
.
File metadata
- Download URL: django_highlightjs-0.2.13.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.11.10 Linux/6.8.0-1014-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 185b40fe38c2879aececb9936b5f66d9289edecb0aab81d445ed7a2b0f223861 |
|
MD5 | c6df82519a0a234f4a9ca3df8cd3fc26 |
|
BLAKE2b-256 | 96c3daf39967d2fd959327638f1b7ab80fd574be38f8312155bfb2ec28d51181 |
File details
Details for the file django_highlightjs-0.2.13-py3-none-any.whl
.
File metadata
- Download URL: django_highlightjs-0.2.13-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.11.10 Linux/6.8.0-1014-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad9e9640b1946cfa85ffdd2437b83d90adc7f199999f8574296adc018bcb50ac |
|
MD5 | 24db828e023107037e0f1a8d647b2269 |
|
BLAKE2b-256 | a66a9f4cea451b15428908a0865be755a1a2da5b64100652d6e23a4a273ae172 |