Closed AlmostBuddist closed 7 months ago
For example, here I cannot color the “Button” function, since it is marked as plain
I would also like to be able to color brackets separately from all categories, dividing them into round, curly and square, but they are added to the general category of punctuation marks, which is why periods and commas will be colored, and so on.
Variables are also marked as plain...
I would also like to color the properties after the dots separately somehow
When listing parameters, I would also like to colorize the variables (like x and y here)
I apologize for my English, I'm bad at it, I hope I explained the problem clearly, I would like to get at least some answer
To add more tokens, you can simply modify the Python grammar. Since prism-react-renderer
exports its Prism instance, you can easily do this.
Below I'm adding most of what you mentioned:
import { Prism } from 'prism-react-renderer';
Prism.languages.insertBefore('python', 'punctuation', {
'bracket': /[()]/,
'square-bracket': /[[\]]/,
'curly-bracket': /[{}]/,
// Properties after dots
'property-access': {
pattern: /(\.)\w+/,
lookbehind: true
},
// These can match things that aren't variables
// So you might not want to add these two
'capitalized-variable': /[A-Z]\w+/,
'variable': /\w+/
});
You can name these tokens whatever you want as long as it doesn't collide with any of python's existing tokens.
I'd suggest you to read Prism's documentation on extending grammars.
I use this library for displays Python code, and it is truly one of the best libraries of its kind. But in most cases there are too few tokens, and I can’t find how to add them or set more rules for them. I would like to know if there is any mechanism for this or if you can add more tokens?