Example Code

HTML and CSS Syntax Highlighter

Code and Documents

Attachment

Overview

This example demonstrates how to syntax highlight HTML and CSS strings using native LabVIEW controls (No ActiveX or .NET). While highlighting in LabVIEW is not difficult, formatting native LabVIEW strings are notoriously slow (compared to referenced based languages). With a few optimizations I was able to get the redraw rate below 100ms for a ~20kB file (Minimal typing lag).

Example

Unzip and run the SyntaxHiLite.vi example. Press the 'HTML' or 'CSS' buttons to generate example strings. While typing the example is optimized to only update the highlighting after a tag is close (i.e. '<..>' or '{..}'). This helps reduce redraw lag. HTML strings highlight tags, attributes and comments while CSS strings highlight styles and comments.


HTML.pngCSS.png

Block Diagram

The SyntaxHiLite String.vi optimizes string value change and key down events to determine when to update the display.

HTML_BD.png

Requirements

- LabVIEW 2013 or later

Author

Ryan Pacini

Certified LabVIEW Architect | RyLabs.com

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Contributors