Inserts tokens before another token in the given grammar.
Usage
This helper method makes it easy to modify existing grammars. For example, the CSS language definition
not only defines CSS highlighting for CSS documents, but also needs to define highlighting for CSS embedded
in HTML through <style> elements. To do this, it needs to modify Prism.languages.markup and add the
appropriate tokens. However, Prism.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 CSS example above, you would use it like this:
Inserts tokens before another token in the given grammar.
Usage
This helper method makes it easy to modify existing grammars. For example, the CSS language definition not only defines CSS highlighting for CSS documents, but also needs to define highlighting for CSS embedded in HTML through
<style>
elements. To do this, it needs to modifyPrism.languages.markup
and add the appropriate tokens. However,Prism.languages.markup
is a regular JavaScript object literal, so if you do this:then the
style
token will be added (and processed) at the end.insertBefore
allows you to insert tokens before existing tokens. For the CSS example above, you would use it like this:Special cases
If the grammars of
grammar
andinsert
have tokens with the same name, the tokens ingrammar
’s grammar will be ignored.This behavior can be used to insert tokens after
before
: