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
Motivation
Right now, Prism.highlight takes the parameters text, grammar, and language is that exact order. This is suboptimal because grammar and language are redundant. Is can plainly be seen in the example given in the docs:
Why do I have to give it Prism.languages.javascript? I already told the function the language.
The redundancy also makes it possible to use the function incorrectly. I.e. if grammar doesn't have the value Prism.languages[language], then what does the language parameter even mean?
Edit: As suggested by @LeaVerou, the grammar parameter gets moved into a dictionary of optional options. The grammar sued for highlighting will be evaluated as options.grammar ?? Prism.languages[language]. No functionality will be lost, but the minimal example will be a lot simpler:
Prism.highlight('var foo = true;','javascript');
What do you think? This will make Prism a little easier to use, but it's also a considerable breaking change (obviously v2), maybe even too much of a breaking change?
If we're going to be making breaking changes like that, we should probably move any optional options to a dictionary.
Also, we need to make sure one can highlight text with an "anonymous" grammar, i.e. by just providing a grammar object that is not on Prism.languages (or would that not work today?).
It's probably overkill right now, but it'll make it easy to add new stuff in the future. I like it. I'll update the issue.
just providing a grammar object that is not on Prism.languages (or would that not work today?).
Well, the language parameter is still required because it is passed to plugins via the hook environment. However, our plugins just need some language id/name. From my understanding, they don't assume/require that env.grammar == Prism.languages[env.language], so everything should work fine.
Of course, what plugins are allowed to assume about env.grammar and env.language is also an interesting question.
Motivation
Right now,
Prism.highlight
takes the parameterstext
,grammar
, andlanguage
is that exact order. This is suboptimal becausegrammar
andlanguage
are redundant. Is can plainly be seen in the example given in the docs:Why do I have to give it
Prism.languages.javascript
? I already told the function the language.The redundancy also makes it possible to use the function incorrectly. I.e. if
grammar
doesn't have the valuePrism.languages[language]
, then what does thelanguage
parameter even mean?Description
Change the signature from:
to:
Edit: As suggested by @LeaVerou, the
grammar
parameter gets moved into a dictionary of optional options. The grammar sued for highlighting will be evaluated asoptions.grammar ?? Prism.languages[language]
. No functionality will be lost, but the minimal example will be a lot simpler:What do you think? This will make Prism a little easier to use, but it's also a considerable breaking change (obviously v2), maybe even too much of a breaking change?
@LeaVerou @mAAdhaTTah @Golmote @JaKXz
The text was updated successfully, but these errors were encountered: