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.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.

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.14.tar.gz (4.9 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.14-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_highlightjs-0.2.14.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.11.11 Linux/6.8.0-1021-azure

File hashes

Hashes for django_highlightjs-0.2.14.tar.gz
Algorithm Hash digest
SHA256 61d2075e79ef12562855f3b6ef13283556fdf3de6ff0304b03a71548f3849d5c
MD5 2e548ecbaa53638a92d57ae5ee5cf779
BLAKE2b-256 a872ebda76a78ed2d067bb1b772aff11928e77afd20d47cc1d72fe524cf47a81

See more details on using hashes here.

File details

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

File metadata

  • Download URL: django_highlightjs-0.2.14-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.11.11 Linux/6.8.0-1021-azure

File hashes

Hashes for django_highlightjs-0.2.14-py3-none-any.whl
Algorithm Hash digest
SHA256 9249bfba2acba58c5ba819d17aca246aa1084887b83f793a89ab3154672c3ff0
MD5 5884360f59eba9022c4c0af187f0d24e
BLAKE2b-256 846a06bbe90e60e67bb5ada91ec1655832f899f78407771a46a5518d1961c568

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