extend
const
extend: (id
,reDef?
) =>Grammar
Defined in: prism/utils/language.d.ts:87
Creates a deep copy of the language with the given id and appends the given tokens.
If a token in reDef
also appears in the copied language, then the existing token in the copied language
will be overwritten at its original position.
Best practices
Section titled “Best practices”Since the position of overwriting tokens (token in reDef
that overwrite tokens in the copied language)
doesn’t matter, they can technically be in any order. However, this can be confusing to others that trying to
understand the language definition because, normally, the order of tokens matters in Prism grammars.
Therefore, it is encouraged to order overwriting tokens according to the positions of the overwritten tokens. Furthermore, all non-overwriting tokens should be placed after the overwriting ones.
Parameters
Section titled “Parameters”string
The id of the language to extend.
reDef?
Section titled “reDef?”The new tokens to append.
Returns
Section titled “Returns”The new language created.
Example
Section titled “Example”languages['css-with-colors'] = extend('css', { // languages.css already has a 'comment' token, so this token will overwrite CSS' 'comment' token // at its original position 'comment': { ... }, // CSS doesn't have a 'color' token, so this token will be appended 'color': /\b(?:red|green|blue)\b/});