Multi Highlighter
TSynMultiSyn (unit SynEdit.Highlighter.Multi) combines several highlighters in the same document, for example HTML with embedded CSS and JavaScript, or Pascal with SQL inside the strings.
How it works
The component has a default highlighter for the text outside the schemes, and a collection of schemes. A scheme is a region of the text, that starts with a given expression, ends with another one and is highlighted with its own highlighter.
Property of TSynMultiSyn | Description |
|---|---|
Schemes | The collection of the schemes. |
DefaultHighlighter | The highlighter of the text outside the schemes. |
DefaultLanguageName | The language name of the whole combination. |
OnCustomRange | Event to extend the ranges computed by the highlighters. |
Property of a scheme (TScheme) | Description |
|---|---|
StartExpr | Regular expression that starts the scheme. |
EndExpr | Regular expression that ends the scheme. |
Highlighter | The highlighter used inside the scheme. |
CaseSensitive | Case sensitive matching of the expressions. |
MarkerAttri | The attributes of the start and end markers. |
SchemeName | The name of the scheme. |
OnCheckStartMarker, OnCheckEndMarker | Events to decide in code whether a marker is valid. |
Example
HTML pages with scripts:
- Drop a
TSynMultiSyn, aTSynHTMLSynand aTSynJScriptSyn. - Set
DefaultHighlighterto the HTML highlighter. - Add a scheme with
StartExpr=<script[^>]*>,EndExpr=</script>andHighlighter= the JavaScript highlighter. - Assign the
TSynMultiSynto theHighlighterproperty of the editor.
The same technique allows the links of the comments to be recognized, combining a language with TSynURISyn for TSynURIOpener.
