-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Description
Table of some specific suggestions:
| Name | Description |
|---|---|
| title.class | A class name |
| title.function | A function name |
| title.namespace | A namespace name |
| comment.block | A block comment |
| meta.shebang | A shebang line for a script file |
Is your request related to a specific problem you're having?
Yes, I'd like to have a way to label/highlight names of a given type outside of their original context.
For example:
class Cat extends Pet { ... Turns into <class><title>Cat</title><keyword>extends</keyword><title>Pet</title>. And if we wanted to style it a certain way we could target .hljs-class .hljs-title. Although Pet is semantically different here and that's not indicated at all.
The same is true for functions:
function cleanMyRoom() {}Turns into <function><title>cleanMyRoom</title... and hence could be targeted by a theme with .hljs-function .hljs-title... but now we have the usage of these things outside of their definition:
var kitty = new Cat();
Cat.prototype.pet = function() { ... }In both cases [re: Cat] we can easily figure out this is a "class" object and we could apply title to it... but is it a class? a namespace? a function name? We've lost all context.
And for functions:
let launchTheRockets = () => { ...Technically launchTheRockets is a name/title here (and we could easily detect that and highlight)... but it's not the function itself (which is () => {...}... so again we have a name without context... and we're forced to fall back to the generic title.
And this problem get worse for languages that also have namespaces that could also be syntactically inferred... all we have is title and perhaps context at the definition site - although we have no namespace class...
The solution you'd prefer / feature you'd like to see added...
I think we may need to consider some new classes, or expanding existing ones with sub classes:
- Alternative 1: New classes
class_name,function_name,namespace_name - Alternative 2: Expand existing classes with subclass:
title.function,title.class,title.namespace...
The way alternative 2 would unfolding during rendering CSS might look something like:
<span class="hljs-title hljs-title-function">launchTheRockets</span>IE, the existing "broader" class is preserved. This would require no changes to any existing styles, while allowing new themes (or upgrades) to target items with more specificity. I'm a little more attached to system 2 as it seems more easily "backwards compatible".
Any alternative solutions you considered...
Nope, I outlined my two thoughts above.
Additional context...
I spent some time reviewing how Prism handles this and it has a lot more named options for tracking what "kind of thing" a given identifier might be:
constantclass-namefunction-name(though most grammars usefunction)namespace
This allows it to make some really nice distinctions when highlighting (like treating classes differently than function name, etc).