You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this example grammar, the markup templating hooks for PHP cannot be run meaning that none of the markup in which the PHP code is embedded will be highlighted.
Description
So let's add 2 new hooks which are run by Prism.tokenize instead. Since inside grammars are also executed by it, it's an easy solution. The will be equivalent to before-tokenize and after-tokenize. Prism.tokenize will then look like this:
functiontokenize(text,grammar){varenv={ text, grammar };// names are still undecidedPrism.hooks.run('new-before-tokenize',env);text=env.text;grammar=env.grammar;varstrarr=[text];// handle .rest in grammar_.matchGrammar(text,strarr,grammar,0,0,false);env.tokens=strarr;Prism.hooks.run('new-after-tokenize',env);returnenv.tokens;}
Moving the existing before-tokenize and after-tokenize into Prism.tokenize is not possible because the function doesn't know the name of the grammar and considering inside grammars, it shouldn't.
Alternatives
Because the use-case of the new hooks are all grammar specific (they are NOT intended to be used by plugins), we could instead make them two non-enumerable functions in the grammar itself.
For both solutions to actually solve the problem motivating them, markup templating has to be modified. Richt now, MT identifies languages by their name and not by their grammar (this also makes aliases impossible but that's another issue).
On the positive side, this will also simplify some code because now, Prism.tokenize is all you need to tokenize with a grammar. No more tokenizeWithHooks.
The text was updated successfully, but these errors were encountered:
Motivation
Right now, the
before-tokenize
andafter-tokenize
hooks are called byPrism.highlight
.This is a problem because this means that these hooks cannot be run for embedded languages like PHP:
In this example grammar, the markup templating hooks for PHP cannot be run meaning that none of the markup in which the PHP code is embedded will be highlighted.
Description
So let's add 2 new hooks which are run by
Prism.tokenize
instead. Sinceinside
grammars are also executed by it, it's an easy solution. The will be equivalent tobefore-tokenize
andafter-tokenize
.Prism.tokenize
will then look like this:Moving the existing
before-tokenize
andafter-tokenize
intoPrism.tokenize
is not possible because the function doesn't know the name of the grammar and consideringinside
grammars, it shouldn't.Alternatives
Because the use-case of the new hooks are all grammar specific (they are NOT intended to be used by plugins), we could instead make them two non-enumerable functions in the grammar itself.
Closing thoughts
For both solutions to actually solve the problem motivating them, markup templating has to be modified. Richt now, MT identifies languages by their name and not by their grammar (this also makes aliases impossible but that's another issue).
On the positive side, this will also simplify some code because now,
Prism.tokenize
is all you need to tokenize with a grammar. No moretokenizeWithHooks
.The text was updated successfully, but these errors were encountered: