-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhance definitions in TypeScript component #1522
Conversation
Thank you for this PR! But you seem to have forgotten to add the minified files. Could you please commit them as well? |
Sorry, I've used GitHub editor to edit the file in browser. |
readonly
keyword to TypeScript component
If you want to complete the list of builtins and keywords you could also add the |
I also think that the syntax coloring of VS Code is just gorgeous. But you don't have to change the core for that. All you need is a little hook like this: Prism.hooks.add('after-tokenize', function (env) {
if (env.language !== 'typescript') {
return;
}
for (var i = 0; i < env.tokens.length; i++) {
var token = env.tokens[i];
if (typeof token === 'string')
continue;
if (token.type === 'keyword' && /^(?:return|if|else|other special keywords)$/.test(token.content)) {
var specialKeywordAlias = 'specialKeyword';
if (!token.alias)
token.alias = [specialKeywordAlias];
else if (typeof token.alias === 'string')
token.alias = [token.alias, specialKeywordAlias];
else
token.alias.push(specialKeywordAlias);
}
}
}); Add this hook before you do the highlighting and all keywords matching the regular expression will get an additional CSS class which can be used to change the color of certain keywords. (This ought to work. I haven't thoroughly tested it though.) |
@RunDevelopment Maybe I will make a separate PR with this feature in the future 😉 |
@19majkel94 Maybe you should open an issue for that first. This feature will not only change the feel of Prism (if we were to also change the themes) but it will also be quite hard to maintain with my quick and dirty solution. A better way to achieve this would be to split the keyword lists into two and to mark special keywords with an alias. If we were to do this (and also were to change the themes), we should probably add this for a bunch of languages to keep the feel of Prism consistent. I think? |
Can we get tests for the new keywords? |
Can we get contribution guide with the info about how to write tests for the new keywords? |
Captured in #1533. You should be able to check out the other |
@mAAdhaTTah The tests has been updated 🎉 |
module | ||
declare | ||
constructor | ||
enum |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why were these removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not removed, just sorted alphabetically. I've added the missing cases too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see. enum
appears twice on the list, so I didn't see it added.
Thank you for the contribution! |
No description provided.