Skip to content

Latest commit

 

History

History
88 lines (48 loc) · 2.1 KB

api-reference.md

File metadata and controls

88 lines (48 loc) · 2.1 KB

HighlightJSGrammar Methods

For node:

HighlightJSGrammar = require('build/highlightjs_grammar.js');

For browser:

<script src="build/highlightjs_grammar.js"></script>

Method: clone

cloned_grammar = HighlightJSGrammar.clone( grammar [, deep=true] );

Clone (deep) a grammar

Utility to clone objects efficiently

Method: extend

extended_grammar = HighlightJSGrammar.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 = HighlightJSGrammar.pre_process( grammar );

This is used internally by the HighlightJSGrammar 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 = HighlightJSGrammar.parse( grammar );

This is used internally by the HighlightJSGrammar 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 = HighlightJSGrammar.getMode( grammar, hljs );

This is the main method which transforms a JSON grammar into a syntax-highlighter language for HighlightJS (hljs).

Parser Class: Parser

Parser = HighlightJSGrammar.Parser;

The Parser Class used to instantiate a highlight 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.