highlight.js
highlight.js copied to clipboard
(Javascript) A non keyword gets highlighted
Describe the issue The first word of a statement that is capitalized is getting highlighted when the language is set to Javascript. I have only tested it with this language.
For example, no syntax to highlight --> does not get hlghlighted. No syntax to highlight --> The word 'No' gets highlighted.
Which language seems to have the issue? Javascript.
Are you using highlight
or highlightAuto
?
No. I am using highlightAll.
** NOTE: I am able to see the same behavior on the demo site too.
Steps to re-produce:
- https://highlightjs.org/demo
- Select language as javascript
- Enter the above 2 statements one by one in the Code section of the page.
- Check the result on the right hand side.
Expected behavior Since the word is not a keyword it should not get highlighted.
@riteshpanchal I'm interested in fixing on this bug. Can you assign to me?
Please assign this issue to me. I have already solved this issue. I am very much excited to make my first contribution.
Describe the issue The first word of a statement that is capitalized is getting highlighted when the language is set to Javascript. I have only tested it with this language.
For example, no syntax to highlight --> does not get hlghlighted. No syntax to highlight --> The word 'No' gets highlighted.
Which language seems to have the issue? Javascript.
Are you using
highlight
orhighlightAuto
? No. I am using highlightAll.** NOTE: I am able to see the same behavior on the demo site too.
Steps to re-produce:
- https://highlightjs.org/demo
- Select language as javascript
- Enter the above 2 statements one by one in the Code section of the page.
- Check the result on the right hand side.
Expected behavior Since the word is not a keyword it should not get highlighted.
All the words which are starting with capital letters are being highlighted not just the first one. This is not a bug maybe, this is feature that all the words with capital letters will be highlighted ....
Describe the issue The first word of a statement that is capitalized is getting highlighted when the language is set to Javascript. I have only tested it with this language. For example, no syntax to highlight --> does not get hlghlighted. No syntax to highlight --> The word 'No' gets highlighted. Which language seems to have the issue? Javascript. Are you using
highlight
orhighlightAuto
? No. I am using highlightAll. ** NOTE: I am able to see the same behavior on the demo site too. Steps to re-produce:
- https://highlightjs.org/demo
- Select language as javascript
- Enter the above 2 statements one by one in the Code section of the page.
- Check the result on the right hand side.
Expected behavior Since the word is not a keyword it should not get highlighted.
All the words which are starting with capital letters are being highlighted not just the first one. This is not a bug maybe, this is feature that all the words with capital letters will be highlighted ....
@luv2027 -- Can you please elaborate in what scenarios this is considered valid?
@riteshpanchal I'm interested in fixing on this bug. Can you assign to me?
I don't have access to assign this issue to anybody. Maybe the contributors have to assign it.
@cobtributer please assign this to me
We're always happy to see a PR for an issue, it doesn't need to first be assigned.
Describe the issue The first word of a statement that is capitalized is getting highlighted when the language is set to Javascript. I have only tested it with this language. For example, no syntax to highlight --> does not get hlghlighted. No syntax to highlight --> The word 'No' gets highlighted. Which language seems to have the issue? Javascript. Are you using
highlight
orhighlightAuto
? No. I am using highlightAll. ** NOTE: I am able to see the same behavior on the demo site too. Steps to re-produce:
- https://highlightjs.org/demo
- Select language as javascript
- Enter the above 2 statements one by one in the Code section of the page.
- Check the result on the right hand side.
Expected behavior Since the word is not a keyword it should not get highlighted.
All the words which are starting with capital letters are being highlighted not just the first one. This is not a bug maybe, this is feature that all the words with capital letters will be highlighted ....
@luv2027 -- Can you please elaborate in what scenarios this is considered valid?
I'm not luv2027 but I'm guessing it's trying to predict that all words that are uppercased might be a name for a Class
what do you think?
Oh my bad for not reading this fully. No
is CamelCase, which is convention for classes in JavaScript. So highlighting it is the intended behavior. If you want a constant use NO
, a variable use no
. Yes, our highlighter has opinions about some very common coding conventions.
I agree that class names should be CamelCase. Wouldn't the parser take into consideration the "token" in order to determine if the word succeeding the token needs to be in particular case ?
no syntax to highlight --> does not get hlghlighted. No syntax to highlight --> The word 'No' gets highlighted.
These are NOT valid Javascript examples, so we do not care how poorly they are highlighted if you choose to highlight them as JavaScript. Please first provide actual Javascript examples.
Wouldn't the parser take into consideration the "token" in order to determine if the word succeeding the token needs to be in particular case ?
In some cases... but we are not a full parser and not interested in trying to be. That's a much harder problem... classes are just objects in JS and you can use them almost anywhere... we might do a bit more of this [context awareness] once version 12 comes out and we're allowed to used backwards looking regex... but generally we try and pattern match text - not fully parse code.
CamelCasing is a very STRONG JS convention...
These are NOT valid Javascript examples, so we do not care how poorly they are highlighted if you choose to highlight them as JavaScript. Please first provide actual Javascript examples.
@joshgoebel
Here is the Demo: Demo
var no = 5;
var No = 6;
This code highlights a normal variable as class.
There are two ways in javascript to create a class:
- Using the class keyword:
class ClassName {
// Class code goes here
}
class Person {
constructor(name, age) {
this.name = name;
this.age = age;
}
greet() {
console.log(`Hello, my name is ${this.name} and I am ${this.age} years old.`);
}
}
- Using the constructor function:
function ClassName(constructorArgs) {
// Class properties and methods go here
}
function Person(name, age) {
this.name = name;
this.age = age;
this.greet = function() {
console.log(`Hello, my name is ${this.name} and I am ${this.age} years old.`);
};
}
function Person(name, age) {
this.name = name;
this.age = age;
}
Person.prototype.greet = function() {
console.log(`Hello, my name is ${this.name} and I am ${this.age} years old.`);
};
And i think "variant" mode will help here. Anything I am missing??
Using the constructor function:
Of which var Klass = function() {}
is perfectly valid I believe. I think you'll want to read the second part of my response which adds color to the first.
Closing as wontfix. Our detection of both CamelCase classes and SCREAM_CASE constants is intentional.