Trying to fight procrastination I've got myself busy with a long delayed task — refactoring language definition in highlight.js to a new syntax. This turned out so well that I've also managed to resolve other tasks that were planned for version 6.0. So without further ado I'm hereby introducing a beta of a new major version and ask everyone interested to test it.
Links
For your testing pleasure:
- Project on GitHub. Sources, tools, tests.
- Full packed library. 90 kB, all languages.
- Packed version with only 12 popular languages. 26 kB, includes HTML/XML, Javascript, CSS, PHP, Ruby, Perl, Python, C++, C#, Java, SQL, Bash.
- Styles package. As a single archive for convenience.
Please go ahead install it, catch bugs and write reports to the list or to the bug tracker.
Syntax
The main change in this version is of concern to developers, not users. Language definition syntax has been streamlined, defaults became more rational and some attributes used previously to describe special cases have been dropped. Here's a short example.
Before:
defaultMode: {
contains: ['string'],
modes: [
{
className: 'string',
begin: '"', end: '"',
contains: ['escape']
},
{
className: 'escape', noMarkup: true,
begin: '\\\\.', end: hljs.IMMEDIATE_RE
}
]
}
After:
defaultMode: {
contains: [
{
className: 'string',
begin: '"', end: '"',
contains: [{begin: '\\\\.'}]
}
]
}
Here's what's changed:
- definition of modes themselves (
modes
) and definition of their hierarchy (contains
) are merged into one structure hljs.IMMEDIATE_RE
is now the default value for regexps- instead of silencing
className
withnoMarkup
it's now possible to just omitclassName
Overall the code looks nicer and is more readable. Though there are a couple of rough edges. For example current definition of Ruby contains ten variables for strings that are scattered all over the file :-).
Converting all language definitions into the new syntax was the most long and boring chore. I've decided to release this version as a beta because I'm almost sure that something might be broken even though internal tests are passed successfully. Special thanks go to Valerii Hiora for converting his own definition of Objective C!
Tools
Or rather "the tool" now. Two scripts that were used for packing and building are now merged into one that is more convenient to use both for production builds and during debugging.
Languages
The new version includes 4 new languages:
- 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
Total count of supported languages has now reached 40!
Also two existing languages — HTML and CSS — were significantly reworked. I've decided that two separate definitions for HTML and XML don't make much sense and merged them into one. Then I've got rid of big lists of keywords for HTML and CSS because their syntax is designed to be extensible and doesn't rely on specific keywords. Now all tag names and attributes are highlighted including non-standard ones.
And the best thing is that dropping those keywords along with switching to the new syntax allowed the new version to be smaller while having four completely new language definitions!
Infrastructure
Moving to GitHub has proven to be a good thing: there are more contributors to the project. Also GitHub is simply an outstanding code hosting service which makes migration to git — a new VCS for me — much less painful.
Opening of the discussion group wasn't an undeniable success however. Most of the time it's pretty quite and those threads that were carried out there might as well happen in private. Coming to think of it it's not really surprising since core highlighting code was written by a single author, was rewritten several times and currently there's nobody who really knows this code except me. Nonetheless I don't plan to shut down the group because it is not, after all, a burden and it's handy to have such a place ready if it suddenly becomes necessary.
To do
The plan is rather obvious: I want to wait a couple of weeks for bug reports, fix them (or, preferably, merge patches from the reporters) and then release the final version.
Also as I mentioned on Twitter I'd really love to see new styles based on the Solarized palettes. I won't be able to do this myself so I'm just repeating here the call. If you use and like the highlighter and have passion for details your contribution for the community will be most appreciated!