highlight.js
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Highlight.js is an open-source JavaScript library that offers syntax highlighting for web applications. It's written in JavaScript, and is designed to be used both in a browser and on the server. The main feature of this JavaScript utility is syntax highlighting in over 180 languages, covering most popular programming languages. Despite its broad language coverage, Highlight.js is framework-agnostic and doesn't depend on any other libraries, making it a versatile tool for web developers.
To use highlight.js in your web application, you need to include the library and one of the themes in your HTML file. Then, you call the highlightAll
method from the hljs
object. This method will find and highlight code inside <pre><code>
tags, trying to automatically detect the language. Here is an example:
<link rel="stylesheet" href="/path/to/highlight.js/styles/default.min.css">
<script src="/path/to/highlight.js"></script>
<script>hljs.highlightAll();</script>
Specific languages can be manually specified using the class attribute:
<pre><code class="language-html">...</code></pre>
In case you want to use highlight.js on the server, you can load the library and then use the highlightAuto
method:
const hljs = require('highlight.js');
const highlightedHTML = hljs.highlightAuto('<h1>Hello, world!</h1>').value;
For a smaller footprint, load only selected list of languages:
const hljs = require('highlight.js/lib/core');
hljs.registerLanguage('xml', require('highlight.js/lib/languages/xml'));
To highlight code in a specific language, highlight
method is utilized:
const highlightedHTML = hljs.highlight('<h1>Hello, world!</h1>', {language: 'xml'}).value
The official highlight.js documentation is available on the Highlight.js Read the Docs page. The document includes the library's API, usage guides, a detailed list of supported languages, theme guidelines, and more. You can also find additional information on their official website at https://highlight.js.org/. More technical details regarding the library's design, build process and compatibility requirements can be found in the library's GitHub repository: git://github.com/highlightjs/highlight.js.git.