insertBefore
constinsertBefore: (grammar,before,insert) =>void
Defined in: prism/utils/language.d.ts:54
Inserts tokens before another token in the given grammar.
This helper method makes it easy to modify existing grammars. For example, the markup language definition defines highlighting for CSS embedded in HTML through <style> elements. To do this, it needs to modify languages.markup and add the appropriate tokens. However, languages.markup is a regular JavaScript object literal, so if you do this:
markup.style = { // token};then the style token will be added (and processed) at the end. insertBefore allows you to insert tokens before existing tokens. For the markup example above, you would use it like this:
insertBefore(markup, 'cdata', { 'style': { // token }});Special cases
Section titled “Special cases”If the grammars of grammar and insert have tokens with the same name, the tokens in grammar’s grammar will be ignored.
This behavior can be used to insert tokens after before:
insertBefore(markup, 'comment', { 'comment': markup.comment, // tokens after 'comment'});Parameters
Section titled “Parameters”grammar
Section titled “grammar”The grammar to be modified.
before
Section titled “before”The key to insert before.
insert
Section titled “insert”An object containing the key-value pairs to be inserted.
Returns
Section titled “Returns”void