SyntaxHighlighter 3.0.83

Fork Me On GitHub
whats new?
SyntaxHighlighter is an open source Java Script client side code syntax highlighter.
donate download installation autoloader configuration @syntaxhighlight

API

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.

args
Object: { left: /RegExp/, right: /RegExp/ } Where left regular expression matches opening tag indicating beginning of the script code block, and right regular 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.

NameTypeDescription
allFunctionStatic function which process all elements on the page and performs syntax highlighting.
HighlighterClassThe base class for a brush.
regexLibObjectCommonly 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:

NameTypeDescription
getKeywordsFunctionConverts space separated keywords into usable regular expression to match these keywords.
forHtmlScriptFunctionSets up the brush for html-script functionality.