Skip to main content

A Django app to easyily integrate highlight.js syntax highlighter.

Project description

🎉 Welcome to django-highlightjs 🎉

Build Status Latest Version

Use Highlight.js in your Django templates, the Django way.

🚀 Installation

  1. Install using pip:

    pip install django-highlightjs
    

    Alternatively, you can download or clone this repo and call:

    pip install -e .
    
  2. Add to INSTALLED_APPS in your settings.py:

    'highlightjs',
    
  3. 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 = {
   # 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.11, 3.12 or 3.13
  • Django >= 5.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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_highlightjs-0.2.15.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_highlightjs-0.2.15-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file django_highlightjs-0.2.15.tar.gz.

File metadata

  • Download URL: django_highlightjs-0.2.15.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for django_highlightjs-0.2.15.tar.gz
Algorithm Hash digest
SHA256 7f7dd2e016181d6592723a5ee9698f13952bc5410a7bf24c19130a0616074ad3
MD5 3e45b548fc0091ecb875044d8bc18863
BLAKE2b-256 9794e42a3b9a9234197de50968ad8803a5aa611a85a73a54c480e9861d74fe0e

See more details on using hashes here.

File details

Details for the file django_highlightjs-0.2.15-py3-none-any.whl.

File metadata

  • Download URL: django_highlightjs-0.2.15-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for django_highlightjs-0.2.15-py3-none-any.whl
Algorithm Hash digest
SHA256 306cc82629d4a1102a9dfcb7468be87b15a21ef41ccbe41c33f55d9c5ad1195a
MD5 224ea471fb5de3076d16f5a4b3000e9c
BLAKE2b-256 89ee81bad3230729d6caf3a6d49f1a80a983f12ec008bca79144499883414876

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page