Highlight.js highlights syntax in code examples on blogs, forums and in fact on any web pages. It's very easy to use because it works automatically: finds blocks of code, detects a language, highlights it.
This is not only convenient but also allows highlighting for code examples marked up with writing syntaxes like Markdown where there is no way to specify HTML class easily.
The library knows 46 languages and is bundled with 18 style themes.
Developers and designers are welcome to take part in development.
version 6.2
News
-
07.04.2012
Version 6.2
A lot of things happened in highlight.js since the last version! We've got nine new contributors, the discussion group came alive, and the main branch on GitHub now counts more than 350 followers. Here are most significant results coming from all this activity:
- 5 (five!) new languages: Rust, ActionScript, CoffeeScript, MatLab and experimental support for markdown. Thanks go to Andrey Vlasovskikh, Alexander Myadzel, Dmytrii Nagirniak, Oleg Efimov, Denis Bardadym and John Crepezzi.
- 2 new style themes: Monokai by Luigi Maselli and stylistic imitation of another well-known highlighter Google Code Prettify by Aahan Krish.
- A vast number of correctness fixes and code refactorings, mostly made by Oleg Efimov and Evgeny Stepanischev.
-
23.09.2011
Version 6.1 — Solarized
Jeremy Hull has implemented my dream feature — a port of Solarized style theme famous for being based on the intricate color theory to achieve correct contrast and color perception. It is now available for highlight.js in both variants — light and dark.
This version also adds a new original style Arta. Its author pumbur maintains a heavily modified fork of highlight.js on GitHub.
-
21.05.2011
Version 6.0
New major version of the highlighter has been built on a significantly refactored syntax. Due to this it's even smaller than the previous one while supporting more languages!
New languages are:
- Haskell by Jeremy Hull
- Erlang in two varieties — module and REPL — made collectively by Nikolay Zakharov, Dmitry Kovega and Sergey Ignatov
- Objective C by Valerii Hiora
- Vala by Antono Vasiljev
- Go by Stephan Kountso
Also this version is marginally faster and fixes a number of small long-standing bugs.
Developer overview of the new language syntax is available in a blog post about recent beta release.
P.S. New version is not yet available on a Yandex' CDN, so for now you have to download your own copy.
-
13.10.2010
Version 5.14
Fixed bugs in HTML/XML detection and relevance introduced in previous refactoring.
Also test.html now shows the second best result of language detection by relevance.
-
05.10.2010
Version 5.13
Past weekend began with a couple of simple additions for existing languages but ended up in a big code refactoring bringing along nice improvements for language developers.
For users
- Description of C++ has got new keywords from the upcoming C++ 0x standard.
- Description of HTML has got new tags from HTML 5.
- CSS-styles have been unified to use consistent padding and also have lost pop-outs with names of detected languages.
- Igor Kalnitsky has sent two new language descriptions: CMake и VHDL.
This makes total number of languages supported by highlight.js to reach 35.
Bug fixes:
- Custom classes on
<pre>tags are not being overridden anymore - More correct highlighting of code blocks inside non-
<pre>containers: highlighter now doesn't insist on replacing them with its own container and just replaces the contents. - Small fixes in browser compatibility and heuristics.
For developers
The most significant change is the ability to include language submodes right under
containsinstead of defining explicit named submodes in the main array:contains: [ 'string', 'number', {begin: '\\n', end: hljs.IMMEDIATE_RE} ]This is useful for auxiliary modes needed only in one place to define parsing. Note that such modes often don't have
classNameand hence won't generate a separate<span>in the resulting markup. This is similar in effect tonoMarkup: true. All existing languages have been refactored accordingly.Test file test.html has at last become a real test. Now it not only puts the detected language name under the code snippet but also tests if it matches the expected one. Test summary is displayed right above all language snippets.