Class: RegexHighlighter

RegexHighlighter

new RegexHighlighter()

A class for the Regex Highlighter
Source:

Classes

Match

Methods

insertSyntaxHighlighting(regexObject, string, returnClassNameopt, duplicateFunctionopt)

This function inserts the span tags into the string and returns a new string which can be added to the page or printed to console. This is the main function for where all of the sub functions are called. As well as where the main duplicateFunction is defined if one is not passed in.
Parameters:
Name Type Attributes Description
regexObject Object This is the object which contains all of the regex information. It can be loaded from a file, see JSON examples for how to create these.
string string This is the text that needs to be converted to its highlighted form.
returnClassName string <optional>
This is the class name that will be given to span tags in order to identify the output matches.
duplicateFunction function <optional>
This is the function which will be used to remove any duplicate matches from the highlighting.
Source:

insertSyntaxHighlightingByClass(regexObject, classNameopt)

Loads elements from the document via a className like the loadSyntaxHighlightingByClass but this function will use a regexObject directly from code, instead of loading one from a directory. If no className is given to load the elements, then it will use the default of 'regex-color'.
Parameters:
Name Type Attributes Description
regexObject string This is the object that will be used to highlight the text page elements need to be highlighted.
className string <optional>
This is the className that will be used to identify what elements on the page need to be highlighted
Source:

loadSyntaxHighlightingByClass(classNameopt, languagesFolderPathopt)

The main function to add regex-highlighting to any element on the page. The elements will be loaded by a class supplied to the function, then they will have their innerHTML highlighted by inserting span tags with the the default class of 'regex-color'. The regex languages will be searched for in the specified languagesFolderPath variable, if no path is given, then the default path will be './languages/'.
Parameters:
Name Type Attributes Description
className string <optional>
The className that will be used to identify which page elements need to be highlighted.
languagesFolderPath string <optional>
This is the path to the languages folder, so that any languages that can be used, will be found
Source:

(inner) ajaxGET(url, callbackopt, bundleopt)

Retrieves files and data via a HTTP GET call using the XMLHttpRequest class. This function has support for a callback function when it is finished as well as passing a bundle object back to the callback function when everything is complete. This function is asynchronous!
Parameters:
Name Type Attributes Description
url string the url of the resource
callback function <optional>
A callback to be made when the resource has been retrieved.
bundle Object <optional>
A bundle object to be passed to the callback
Source:

(inner) assembleNewStringFromMatchArray(string, array)

Produces a string which contains the new highlighting, by wrapping matches in the passed array in a span tag with the corresponding class. In order to make sure this functions correctly, it uses an offset and a pre-built match array. When actually wrapping a match with a span, the method wrapTextWithSpan is used.
Parameters:
Name Type Description
string string The string which will be highlighted via the match array
array Array.<Match> The array which contains all the match information
Source:

(inner) defaultDuplicateFunction(a, b)

Default duplicate function for the insertSyntaxHighlighting function
Parameters:
Name Type Description
a Match This is the left regex match
b Match This is the right regex match
Source:

(inner) getMatchesArrayFromRegex(regexObject, string, returnClassNameopt)

This function will return all of the matches that an object which contains different regex patterns will match with a string
Parameters:
Name Type Attributes Description
regexObject Object This is the object which contains all of the regex information. It can be loaded from a file, see JSON examples for how to create these.
string string This is the text that needs to be converted to its highlighted form
returnClassName string <optional>
This is the class name that will be given to the span tags in order to identify the output matches.
Source:

(inner) removeDuplicateObjectsFromArray(array, shouldRemove)

Remove duplicate objects from the array using a function passed into this function. The array should contain Regex match objects and the shouldRemove function should work in a similar way to a compare function in most imperative languages. This means that <0 will remove the item on the left, >0 will remove the item on the right. 0 will not remove anything
Parameters:
Name Type Description
array Array.<Match> The array which will have its duplicate items removed from
shouldRemove function A callback function to decide what will be removed
Source:

(inner) sortArrayByObjectsIndex(array)

A function to sort the values of the passed in array, first by their indicies then by their precedence.
Parameters:
Name Type Description
array Array.<Match> Array of regex match objects
Source:

(inner) wrapTextWithSpan(text, classesopt, startopt, endopt)

Wraps a given piece of text with a span tag that has a class.
Parameters:
Name Type Attributes Description
text string The text as a whole
classes string <optional>
The classes to give the wrapping
start number <optional>
The start point of the wrapping
end number <optional>
The end point of the wrapping
Source: