Thursday, 9 October 2014

Coming soon - QlikView Syntax Highlighting for the Web

I thought I'd let you all in on another little project I've been tinkering with on the side. I have had a long standing problem when blogging about QlikView. Most of my posts contain snippets of QlikView script or expression code which can be very hard to read if it is not syntax highlighted in at least an approximation of how it is highlighted within QlikView. I considered using images taken from screen grabs of the code in QlikView, but this means readers can't copy and paste the code into their QlikView projects making it less than ideal. And so I am left with the time consuming task of having to manually highlight code snippets in my posts, and this means less time for new posts.

//Define the table name
SET vMyTable = 'MyTable1';

//Load in the table of data
$(vMyTable)_Temp:
LOAD
    A,
    B,
    text(C) & ' a string' AS C
RESIDENT $(vMyTable);


Knowing that there are some very good automatic syntax highlighters for other languages out there, I started to explore whether it is possible to adapt one of them to solve this problem. After looking at quite a few I settled on Highlight.js, because of its capabilities, it's extensive list of currently supported languages and the fact that it is open source.

Borrowing on the work I did on the QlikView syntax highlighting for Notepad++ and UltraEdit, and a thanks to a few nights struggling to sleep, I have been slowly working on a custom build of Highlight to create QlikView Syntax Highlighting for the Web. There is still plenty of work to do but the above block of code is the first on this site (and for that matter any website) that has been automatically syntax highlighted using this new creation.

As you can see, it provides a reasonable approximation of the highlighting provided by QlikView and is roughly equivalent to the highlighting in Notepad++ and UltraEdit (in fact it is slightly better). It currently only supports QlikView script and has the following capabilities:
  • Highlighting of all current (v11.20) functions
  • Highlighting of all current (v11.20) keywords and statements
  • Highlighting of line comments (//) and block comments (/* */ and REM ; )
  • Highlighting of variable definitions (SET and LET)
  • Highlighting the usage of variable within dollar-sign expansion $( )
The Highlight.js core is much more flexible than the highlighting engines in either Notepad++ or UltraEdit and so, in theory at least, it should be possible to significantly improve upon these capabilities in the future. A very early version has gone out to a handful of people to test and I am currently working on a few points which I think are important for its first official release. Assuming all goes to plan I intend to release a beta version soon.

To help make it as useful as possible to fellow QlikView bloggers, I intend to package it in 2 ways. The first is as a plugin for Wordpress, which is the most commonly used blogging platform. Having it as a proper Wordpress plugin means installing it on a Wordpress based site takes only a few seconds and doesn't involve changing any of the existing site files. It also means the highlighting can be triggered using a Wordpress shortcode. There will also be a version for manual inclusion in all other websites.

I've added the project to branch.qlik.com so that you can follow its progress and contribute should you wish. And obviously I'll be posting more here over the coming weeks about how things are progressing. Watch this space!

No comments:

Post a comment