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:
Prism.highlight('var foo = true;', Prism.languages.javascript, 'javascript');
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?
Description
Change the signature from:
function highlight(text: string, grammar: Grammar, language: string) { ... }
to:
interface HighlightOptions { grammar?: Grammar; } function highlight(text: string, language: string, options?: HighlightOptions) { ... }
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?
@LeaVerou @mAAdhaTTah @Golmote @JaKXz
kissge and fischeversenker
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4