api-reference.md
March 1, 2018 ยท View on GitHub
SyntaxHighlighterGrammar Methods
For node:
SyntaxHighlighterGrammar = require('build/syntaxhighlighter_grammar.js');
For browser:
<script src="build/syntaxhighlighter_grammar.js"></script>
Method: clone
cloned_grammar = SyntaxHighlighterGrammar.clone( grammar [, deep=true] );
Clone (deep) a grammar
Utility to clone objects efficiently
Method: extend
extended_grammar = SyntaxHighlighterGrammar.extend( grammar, basegrammar1 [, basegrammar2, ..] );
Extend a grammar with basegrammar1, basegrammar2, etc..
This way arbitrary dialects and variations can be handled more easily
Method: pre_process
pre_processed_grammar = SyntaxHighlighterGrammar.pre_process( grammar );
This is used internally by the SyntaxHighlighterGrammar Class parse method
In order to pre-process a JSON grammar (in-place) to transform any shorthand configurations to full object configurations and provide defaults.
It also parses PEG/BNF (syntax) notations into full (syntax) configuration objects, so merging with other grammars can be easier if needed.
Method: parse
parsed_grammar = SyntaxHighlighterGrammar.parse( grammar );
This is used internally by the SyntaxHighlighterGrammar Class
In order to parse a JSON grammar to a form suitable to be used by the syntax-highlighter.
However user can use this method to cache a parsedgrammar to be used later.
Already parsed grammars are NOT re-parsed when passed through the parse method again
Method: getMode
mode = SyntaxHighlighterGrammar.getMode( grammar, SyntaxHighlighter );
This is the main method which transforms a JSON grammar into a syntax-highlighter brush for SyntaxHighlighter.
Parser Class: Parser
Parser = SyntaxHighlighterGrammar.Parser;
The Parser Class used to instantiate a highlight brush parser, is available.
The getMode method will instantiate this parser class, which can be overriden/extended if needed, as needed.
In general there is no need to override/extend the parser, unless you definately need to.