SyntaxHighlighter.Highlighter.prototype.forHtmlScript(args)
SyntaxHighlighter 2.0 introduced ability to mix any brush with HTML. For example, this allows to display JavaScript or PHP in the context of HTML page. To allow a brush to use html-script functionality, it needs to be prepared by calling this.forHtmlScript(...) from the constructor.
argsObject: { left: /RegExp/, right: /RegExp/ }Whereleftregular expression matches opening tag indicating beginning of the script code block, andrightregular expression matches closing tag. Whatever’s in between the two will be highlighted using the actual brush. Everything outside will be treated as HTML.
Example
SyntaxHighlighter.brushes.JScript = function()
{
...
this.forHtmlScript(SyntaxHighlighter.regexLib.scriptScriptTags);
};
SyntaxHighlighter API
SyntaxHighlighter is the top level object and contains a number of functionality and predefined variables.
| Name | Type | Description |
|---|---|---|
all | Function | Static function which process all elements on the page and performs syntax highlighting. |
Highlighter | Class | The base class for a brush. |
regexLib | Object | Commonly used regular expressions. |
SyntaxHighlighter.Highlighter
This is the main class that performs all the highlighting work and it’s the base class for developing custom brushes. Each brush extends this class and adds its own custom lexicon and rules. Here are the properties and methods of interest:
| Name | Type | Description |
|---|---|---|
getKeywords | Function | Converts space separated keywords into usable regular expression to match these keywords. |
forHtmlScript | Function | Sets up the brush for html-script functionality. |