Syntax.js - Documentation - Public Functions

Below is a list of all the public API functions that can be called from a Syntax.js service.

Download Now

v2.5.0 - 29th Mar 2024
Functions

Highlighting:

highlightAll():

Finds all new code elements and renders them.
Fires: onRenderComplete
Returns: Object - The Syntax.js class instance.

highlightElement( elementOrId ):

Renders a specific DOM element.
Fires: onRenderComplete
Parameter: name: Object - The element ID, or the element itself.
Returns: Object - The Syntax.js class instance.

getElementsHighlighted():

Returns the elements that have been detected and rendered.
Returns: Object[] - An array containing the rendered DOM elements.

getCode( elementId ):

Returns the code inside a specific element (without rendering colors).
Parameter: elementId: string - The element ID.
Returns: string - The code in the element.

Destroying:

destroy( elementId ):

Reverts a Syntax element back to its original state (without render attributes).
Parameter: elementId: string - The ID of the DOM element to destroy.
Returns: Object - The Syntax.js class instance.

destroyAll():

Reverts all rendered Syntax elements back to their original state (without render attributes).
Returns: Object - The Syntax.js class instance.

Languages:

addLanguage( name, languageDetails, [triggerRender] ):

Adds a new language that can be rendered.
Fires: onRenderComplete
Parameter: name: string - The name of the language.
Parameter: languageDetails: Object - The language details (refer to "Language" documentation for properties).
Parameter: [triggerRender]: boolean - States if new language DOM elements available should be rendered.
Returns: boolean - States if the language has been added.

removeLanguage( name ):

Removes a language that can be rendered.
Parameter: name: string - The name of the language.
Returns: boolean - States if the language has been removed.

getLanguage( name ):

Returns the language details (by name) that can be rendered.
Parameter: name: string - The name of the language.
Returns: Object - The language details.

getLanguages():

Returns all the languages that can be rendered.
Returns: Object - The object that contains the languages.

Language Aliases:

addAlias( alias, language, [triggerRender] ):

Adds a new language alias.
Fires: onRenderComplete
Parameter: alias: string - The name of the alias.
Parameter: language: string - The name of the language.
Parameter: [triggerRender]: boolean - States if new language alias DOM elements available should be rendered.
Returns: boolean - States if the alias has been added.

removeAlias( alias ):

Removes a language alias.
Parameter: alias: string - The name of the alias.
Returns: boolean - States if the alias has been removed.

getAlias( alias ):

Returns a language alias.
Parameter: alias: string - The name of the alias.
Returns: Object - The name of the language.

getAliases():

Returns all the language aliases.
Returns: Object - The object that contains the aliases.

Configuration:

setConfiguration( newOptions ):

Sets the specific configuration options that should be used.
Parameter: newOptions: Options - All the configuration options that should be set (refer to "Configuration Options" documentation for properties).
Returns: Object - The Syntax.js class instance.

Additional Data:

getVersion():

Returns the version of Syntax.js.
Returns: string - The version number.