Secondary Language Highlighting, CSS in web languages

Two improvements have recently been pushed to RSTA.  First, inline CSS is highlighted in HTML, PHP, and JSP files.  Previously, inline CSS was rendered as plain text; now it’s rendered just as if CSS highlighting were enabled.

Secondary Language Highlighting

CSS Highlighting in an HTML document

These days, TokenMakers for web-based languages are each actually highlighting several languages – JavaScript, CSS, HTML, and possibly JSP/PHP.  This means in documents with lots of inline scripts and styles, it’s not immediately obvious with a visual scan what you’re looking at with syntax highlighting alone.  Which brings me to the second new feature – secondary language highlighting.  When enabled, this allows TokenMakers to specify Tokens as belonging to specific “secondary” languages.  When secondary language highlighting is enabled, such Tokens are painted with a special background color.  This results in regions of code such as JavaScript and CSS blocks to be painted with a different background, as seen in the screenshot above.  It can be extra useful when viewing generated HTML with poor formatting:

Secondary Language Highlighting 2

Secondary Language Highlighting – JS and CSS in HTML

The bad news is, this feature comes at a fair performance penalty (since the background is painted for each individual Token, not for the entire region at once).  On good hardware (especially Windows machines) this shouldn’t really be a problem, but for this reason, this feature is disabled by default.  To enable and query it, use these methods in the RSyntaxTextArea class:

public boolean getHighlightSecondaryLanguages();
public void setHighlightSecondaryLanguages(boolean highlight);
public int getSecondaryLanguageCount();
public Color getSecondaryLanguageBackground(int index);
public void setSecondaryLanguageBackground(int index, Color color);

There are currently three secondary language backgrounds, which I’m assuming is a sufficient and practical number until someone proves otherwise.  :)  The Theme DTD and API have been updated so that themes specify the background colors for secondary languages as well.

One Response to “Secondary Language Highlighting, CSS in web languages”

  1. [...] Background color highlighting for “secondary” languages (such as CSS and JS in HTML, JSP, and PHP). [...]