question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`language-js` also results in class `javascript` being applied

See original GitHub issue

Repurposing this issue for the larger question/problem that it has brought up as mentioned in the comments below at:

https://github.com/highlightjs/highlight.js/issues/3023#issuecomment-787105999

Summary:

  • language-js will also apply the javascript class
  • language-javascript will NOT apply the javascript class
  • some themes require un-prefixed class names to work properly (ie they apply per language themes)

Describe the issue When I add the “language-php” class to the code element, the coloring is okay, but it adds an extra php tag. If I don’t give a class, it adds the php class and there is no problem.

Which language seems to have the issue? Only php, i haven’t seen such problem in other languages

Are you using highlight or highlightAuto? highlightAll

Sample Code to Reproduce You can take a look at the php block. Other languages ​​seem to be fine. Xd

Expected behavior When we add the “language-php” class to the code element, it should not add the extra php tag.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:15 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
joshgoebelcommented, Mar 18, 2021

@Hirse CCing you since you’ve done some theme work.

0reactions
joshgoebelcommented, Mar 19, 2021

Part of the problem is I’m not sure there is any spec here at all. hljs-[name] would be the safest choice from a “do not conflict with other class names” perspective. But then we have a problem if a new language would ever overlap with a highlighting class… so now you’re back to hljs-language-[name]… a bit of a mouthful, but precise enough.

but it might be nice to have the language available as a CSS class for third-party themes.

One can also easily do this with a one-line plugin… should we perhaps just let those who wish to have such things do it themselves?

Example:

https://github.com/highlightjs/highlight.js/blob/main/docs/plugin-recipes.rst#data-language

CC @allejo


So I’m kind of leaning towards:

  • hljs-language-[grammar name] precise and hopefully future proof.
  • Simply do not add a class by default at all, refer people to one line plugin recipe.

Don’t feel I have a strong preference. Either would be a breaking change so this needs to be decided before v11.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript Classes – How They Work with Use Case Example
In this blog post I'll walk you through a real life example which uses the concept of classes in Javascript. I think it's...
Read more >
JavaScript language overview - MDN Web Docs
JavaScript is a multi-paradigm, dynamic language with types and operators, ... many structures from those languages apply to JavaScript as well.
Read more >
Does JavaScript have classes? - Stack Overflow
Technically, the statement "JavaScript has no classes" is correct. Although JavaScript is object-oriented language, it isn't a class-based language—it's a ...
Read more >
As a JS Developer, This Is What Keeps Me Up at Night - Toptal
A class constructor creates an instance of the class. A constructor in JavaScript is just a plain old function that returns an object....
Read more >
Understanding Classes in JavaScript | DigitalOcean
A JavaScript class is a type of function. Classes are declared with the class keyword. We will use function expression syntax to initialize ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found