PHPackages                             drupal-package/highlightjs - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. drupal-package/highlightjs

ActiveDrupal-library

drupal-package/highlightjs
==========================

Allows to clone the highlightjs/highlight.js repository

06.5k↓18.2%JavaScript

Since Nov 26Pushed 5y ago1 watchersCompare

[ Source](https://github.com/drupal-package/highlightjs)[ Packagist](https://packagist.org/packages/drupal-package/highlightjs)[ RSS](/packages/drupal-package-highlightjs/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Highlight.js
============

[](#highlightjs)

[![latest version](https://camo.githubusercontent.com/d343418c1b72ad68d067d1a4777c593604e44ed3732f084db7c35a339cc6a06a/68747470733a2f2f62616467656e2e6e65742f6e706d2f762f686967686c696768742e6a733f6c6162656c3d6c6174657374)](https://www.npmjs.com/package/highlight.js)[![beta](https://camo.githubusercontent.com/9d9d5e43acaff44bda854d075cbe421063d94fb91a4f9cdbb7f1008dcd5adcc5/68747470733a2f2f62616467656e2e6e65742f6e706d2f762f686967686c696768742e6a732f62657461)](https://www.npmjs.com/package/highlight.js)[![slack](https://camo.githubusercontent.com/f746665a40c788bb888a6e246d18228b81bc1a6b4b457df65c15c8abd4884e64/68747470733a2f2f62616467656e2e6e65742f62616467652f69636f6e2f736c61636b3f69636f6e3d736c61636b266c6162656c26636f6c6f723d70696e6b)](https://join.slack.com/t/highlightjs/shared_invite/zt-jatdlkw4-h3LdjU5rC23t7aQ6zqoxzw)[![license](https://camo.githubusercontent.com/1905671c2d6af601fbd5e8578eef74e01f4079026d96b5fb0d4b82c7c4ca594c/68747470733a2f2f62616467656e2e6e65742f6769746875622f6c6963656e73652f686967686c696768746a732f686967686c696768742e6a733f636f6c6f723d6379616e)](https://github.com/highlightjs/highlight.js/blob/master/LICENSE)[![install size](https://camo.githubusercontent.com/8dc48677c075e1b3aea51978ab8c1ffdbf05cdf6e1c0e1bef64191b1c81b595c/68747470733a2f2f62616467656e2e6e65742f7061636b61676570686f6269612f696e7374616c6c2f686967686c696768742e6a733f6c6162656c3d6e706d2b696e7374616c6c)](https://packagephobia.now.sh/result?p=highlight.js)[![minified](https://camo.githubusercontent.com/cbe9009b8536e6eadb7ca2db1edd6ce74848e3d07ef61952c20ee73b3ad31544/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73697a652f686967686c696768746a732f63646e2d72656c656173652f6275696c642f686967686c696768742e6d696e2e6a733f6c6162656c3d6d696e6966696564)](https://camo.githubusercontent.com/cbe9009b8536e6eadb7ca2db1edd6ce74848e3d07ef61952c20ee73b3ad31544/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73697a652f686967686c696768746a732f63646e2d72656c656173652f6275696c642f686967686c696768742e6d696e2e6a733f6c6162656c3d6d696e6966696564)[![NPM downloads weekly](https://camo.githubusercontent.com/9fd1f9dc5721f86ba14f5d8409db869ba567eb08a5599be83fa17dac5d6f5535/68747470733a2f2f62616467656e2e6e65742f6e706d2f64772f686967686c696768742e6a733f6c6162656c3d6e706d2b646f776e6c6f61647326636f6c6f723d707572706c65)](https://www.npmjs.com/package/highlight.js)[![jsDelivr CDN downloads](https://camo.githubusercontent.com/359aeb9563b3459119181ad7e5a92b86156a20cac3c999af3d697a7619b519b1/68747470733a2f2f62616467656e2e6e65742f6a7364656c6976722f686974732f67682f686967686c696768746a732f63646e2d72656c656173653f6c6162656c3d6a7344656c6976722b43444e26636f6c6f723d707572706c65)](https://www.jsdelivr.com/package/gh/highlightjs/cdn-release)[![dev deps](https://camo.githubusercontent.com/ecbc3044277f00096caeccc3d0fda15e3226387a4921c567dc125a1ab1672445/68747470733a2f2f62616467656e2e6e65742f64617669642f6465762f686967686c696768746a732f686967686c696768742e6a733f6c6162656c3d6465762b64657073)](https://camo.githubusercontent.com/ecbc3044277f00096caeccc3d0fda15e3226387a4921c567dc125a1ab1672445/68747470733a2f2f62616467656e2e6e65742f64617669642f6465762f686967686c696768746a732f686967686c696768742e6a733f6c6162656c3d6465762b64657073)[![code quality](https://camo.githubusercontent.com/9ec84d5fa5dddaa253fb898ea8eb504e9d501d72eed80a7a6a5ae0d979e5d7bc/68747470733a2f2f62616467656e2e6e65742f6c67746d2f67726164652f672f686967686c696768746a732f686967686c696768742e6a732f6a73)](https://lgtm.com/projects/g/highlightjs/highlight.js/?mode=list)

[![build and CI status](https://camo.githubusercontent.com/e295adf51c4e4692ca7785cb1e790e87ec04c7e2112c300f7807543e935044f0/68747470733a2f2f62616467656e2e6e65742f6769746875622f636865636b732f686967686c696768746a732f686967686c696768742e6a733f6c6162656c3d6275696c64)](https://github.com/highlightjs/highlight.js/actions?query=workflow%3A%22Node.js+CI%22)[![open issues](https://camo.githubusercontent.com/18c04bfb3e2caa9572c715f9a9505c7c9b493c30b6659308945be9755794fc28/68747470733a2f2f62616467656e2e6e65742f6769746875622f6f70656e2d6973737565732f686967686c696768746a732f686967686c696768742e6a733f6c6162656c3d697373756573266c6162656c436f6c6f723d6f72616e676526636f6c6f723d633431)](https://github.com/highlightjs/highlight.js/issues)[![help welcome issues](https://camo.githubusercontent.com/376a6bf44611907dc9fab8e47e3841134f2beed761060744d546fdf4bd248891/68747470733a2f2f62616467656e2e6e65742f6769746875622f6c6162656c2d6973737565732f686967686c696768746a732f686967686c696768742e6a732f68656c7025323077656c636f6d652f6f70656e3f6c6162656c436f6c6f723d33393326636f6c6f723d366336)](https://github.com/highlightjs/highlight.js/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+welcome%22)[![beginner friendly issues](https://camo.githubusercontent.com/2af43085a6732e2a92a4f39401c657f0c6da38cee11c0b0dd5b9fee069e6f1d0/68747470733a2f2f62616467656e2e6e65742f6769746875622f6c6162656c2d6973737565732f686967686c696768746a732f686967686c696768742e6a732f626567696e6e6572253230667269656e646c792f6f70656e3f6c6162656c436f6c6f723d36363926636f6c6f723d393963)](https://github.com/highlightjs/highlight.js/issues?q=is%3Aopen+is%3Aissue+label%3A%22beginner+friendly%22)[![vulnerabilities](https://camo.githubusercontent.com/6ecac02c7143a9bf688922dd149ddaf6d0ade8029e959105cb6c2aa0440c4bda/68747470733a2f2f62616467656e2e6e65742f736e796b2f686967686c696768746a732f686967686c696768742e6a73)](https://snyk.io/test/github/highlightjs/highlight.js?targetFile=package.json)

Highlight.js is a syntax highlighter written in JavaScript. It works in the browser as well as on the server. It works with pretty much any markup, doesn’t depend on any framework, and has automatic language detection.

#### Upgrading to Version 10

[](#upgrading-to-version-10)

Version 10 is one of the biggest releases in quite some time. If you're upgrading from version 9, there are some breaking changes and things you may want to double check first.

Please read [VERSION\_10\_UPGRADE.md](https://github.com/highlightjs/highlight.js/blob/master/VERSION_10_UPGRADE.md) for high-level summary of breaking changes and any actions you may need to take. See [VERSION\_10\_BREAKING\_CHANGES.md](https://github.com/highlightjs/highlight.js/blob/master/VERSION_10_BREAKING_CHANGES.md) for a more detailed list and [CHANGES.md](https://github.com/highlightjs/highlight.js/blob/master/CHANGES.md) to learn what else is new.

##### Support for older versions

[](#support-for-older-versions)

Please see [SECURITY.md](https://github.com/highlightjs/highlight.js/blob/master/SECURITY.md) for support information.

Getting Started
---------------

[](#getting-started)

The bare minimum for using highlight.js on a web page is linking to the library along with one of the styles and calling [`initHighlightingOnLoad`](http://highlightjs.readthedocs.io/en/latest/api.html#inithighlightingonload):

```

hljs.initHighlightingOnLoad();
```

This will find and highlight code inside of `` tags; it tries to detect the language automatically. If automatic detection doesn’t work for you, you can specify the language in the `class` attribute:

```
...
```

Classes may also be prefixed with either `language-` or `lang-`.

```
...
```

### Plaintext and Disabling Highlighting

[](#plaintext-and-disabling-highlighting)

To style arbitrary text like code, but without any highlighting, use the `plaintext` class:

```
...
```

To disable highlighting of a tag completely, use the `nohighlight` class:

```
...
```

### Supported Languages

[](#supported-languages)

Highlight.js supports over 180 different languages in the core library. There are also 3rd party language plugins available for additional languages. You can find the full list of supported languages in [SUPPORTED\_LANGUAGES.md](https://github.com/highlightjs/highlight.js/blob/master/SUPPORTED_LANGUAGES.md).

Custom Initialization
---------------------

[](#custom-initialization)

When you need a bit more control over the initialization of highlight.js, you can use the [`highlightBlock`](http://highlightjs.readthedocs.io/en/latest/api.html#highlightblock-block) and [`configure`](http://highlightjs.readthedocs.io/en/latest/api.html#configure-options)functions. This allows you to control *what* to highlight and *when*.

Here’s an equivalent way to calling [`initHighlightingOnLoad`](http://highlightjs.readthedocs.io/en/latest/api.html#inithighlightingonload) using vanilla JS:

```
document.addEventListener('DOMContentLoaded', (event) => {
  document.querySelectorAll('pre code').forEach((block) => {
    hljs.highlightBlock(block);
  });
});
```

You can use any tags instead of `` to mark up your code. If you don't use a container that preserves line breaks you will need to configure highlight.js to use the `` tag:

```
hljs.configure({useBR: true});

document.querySelectorAll('div.code').forEach((block) => {
  hljs.highlightBlock(block);
});
```

For other options refer to the documentation for [`configure`](http://highlightjs.readthedocs.io/en/latest/api.html#configure-options).

Using with Vue.js
-----------------

[](#using-with-vuejs)

Simply register the plugin with Vue:

```
Vue.use(hljs.vuePlugin);
```

And you'll be provided with a `highlightjs` component for use in your templates:

```

```

Web Workers
-----------

[](#web-workers)

You can run highlighting inside a web worker to avoid freezing the browser window while dealing with very big chunks of code.

In your main script:

```
addEventListener('load', () => {
  const code = document.querySelector('#code');
  const worker = new Worker('worker.js');
  worker.onmessage = (event) => { code.innerHTML = event.data; }
  worker.postMessage(code.textContent);
});
```

In worker.js:

```
onmessage = (event) => {
  importScripts('/highlight.min.js');
  const result = self.hljs.highlightAuto(event.data);
  postMessage(result.value);
};
```

Node.js
-------

[](#nodejs)

You can use highlight.js with node to highlight content before sending it to the browser. Make sure to use the `.value` property to get the formatted html. For more info about the returned object refer to the api docs

```
// require the highlight.js library, including all languages
const hljs = require('./highlight.js');
const highlightedCode = hljs.highlightAuto('Hello World!').value
```

Or for a smaller footprint... load just the languages you need.

```
const hljs = require("highlight.js/lib/core");  // require only the core library
// separately require languages
hljs.registerLanguage('xml', require('highlight.js/lib/languages/xml'));

const highlightedCode = hljs.highlight('xml', 'Hello World!').value
```

ES6 Modules
-----------

[](#es6-modules)

First, you'll likely install via `npm` or `yarn` -- see [Getting the Library](#getting-the-library) below.

In your application:

```
import hljs from 'highlight.js';
```

The default import imports all languages. Therefore it is likely to be more efficient to import only the library and the languages you need:

```
import hljs from 'highlight.js/lib/core';
import javascript from 'highlight.js/lib/languages/javascript';
hljs.registerLanguage('javascript', javascript);
```

To set the syntax highlighting style, if your build tool processes CSS from your JavaScript entry point, you can also import the stylesheet directly as modules:

```
import hljs from 'highlight.js/lib/core';
import 'highlight.js/styles/github.css';
```

Getting the Library
-------------------

[](#getting-the-library)

You can get highlight.js as a hosted, or custom-build, browser script or as a server module. Right out of the box the browser script supports both AMD and CommonJS, so if you wish you can use RequireJS or Browserify without having to build from source. The server module also works perfectly fine with Browserify, but there is the option to use a build specific to browsers rather than something meant for a server.

**Do not link to GitHub directly.** The library is not supposed to work straight from the source, it requires building. If none of the pre-packaged options work for you refer to the [building documentation](http://highlightjs.readthedocs.io/en/latest/building-testing.html).

**On Almond.** You need to use the optimizer to give the module a name. For example:

```
r.js -o name=hljs paths.hljs=/path/to/highlight out=highlight.js
```

### CDN Hosted

[](#cdn-hosted)

A prebuilt version of highlight.js bundled with many common languages is hosted by the following CDNs:

**cdnjs** ([link](https://cdnjs.com/libraries/highlight.js))

```

```

**jsdelivr** ([link](https://www.jsdelivr.com/package/gh/highlightjs/cdn-release))

```

```

**unpkg** ([link](https://unpkg.com/browse/@highlightjs/cdn-assets/))

```

```

**Note:** *The CDN-hosted `highlight.min.js` package doesn't bundle every language.* It would be very large. You can find our list "common" languages that we bundle by default on our [download page](https://highlightjs.org/download/).

### Self Hosting

[](#self-hosting)

The [download page](https://highlightjs.org/download/) can quickly generate a custom bundle including only the languages you need.

Alternatively, you can build a browser package from [source](#source):

```
node tools/build.js -t browser :common

```

See our [building documentation](http://highlightjs.readthedocs.io/en/latest/building-testing.html) for more information.

**Note:** Building from source should always result in the smallest size builds. The website download page is optimized for speed, not size.

#### Prebuilt CDN assets

[](#prebuilt-cdn-assets)

You can also download and self-host the same assets we serve up via our own CDNs. We publish those builds to the [cdn-release](https://github.com/highlightjs/cdn-release) GitHub repository. You can easily pull individual files off the CDN endpoints with `curl`, etc; if say you only needed `highlight.min.js` and a single CSS file.

There is also an npm package [@highlightjs/cdn-assets](https://www.npmjs.com/package/@highlightjs/cdn-assets) if pulling the assets in via `npm` or `yarn` would be easier for your build process.

### NPM / Node.js server module

[](#npm--nodejs-server-module)

Highlight.js can also be used on the server. The package with all supported languages can be installed from NPM or Yarn:

```
npm install highlight.js
# or
yarn add highlight.js
```

Alternatively, you can build it from [source](#source):

```
node tools/build.js -t node
```

See our [building documentation](http://highlightjs.readthedocs.io/en/latest/building-testing.html) for more information.

### Source

[](#source)

[Current source](https://github.com/highlightjs/) is always available on GitHub.

License
-------

[](#license)

Highlight.js is released under the BSD License. See [LICENSE](https://github.com/highlightjs/highlight.js/blob/master/LICENSE) file for details.

Links
-----

[](#links)

The official site for the library is at .

Further in-depth documentation for the API and other topics is at .

Authors and contributors are listed in the [AUTHORS.txt](https://github.com/highlightjs/highlight.js/blob/master/AUTHORS.txt) file.

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity31

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/9693971?v=4)[Arnaud Bach](/maintainers/Nono95230)[@Nono95230](https://github.com/Nono95230)

---

Top Contributors

[![Nono95230](https://avatars.githubusercontent.com/u/9693971?v=4)](https://github.com/Nono95230 "Nono95230 (1 commits)")

### Embed Badge

![Health badge](/badges/drupal-package-highlightjs/health.svg)

```
[![Health](https://phpackages.com/badges/drupal-package-highlightjs/health.svg)](https://phpackages.com/packages/drupal-package-highlightjs)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
