Skip to content
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

Javascript not always recognized #2910

Closed
step135 opened this issue Dec 6, 2020 · 7 comments
Closed

Javascript not always recognized #2910

step135 opened this issue Dec 6, 2020 · 7 comments
Labels
auto-detect Issue with auto detection of language type cantfix / wontfix Impossible to fix

Comments

@step135
Copy link

step135 commented Dec 6, 2020

Example:

var f=45
new OptimizeCSSPlugin({
cssProcessorOptions: config.build.productionSourceMap
? { safe: true, map: { inline: false } }
: { safe: true }
})
@step135 step135 added bug help welcome Could use help from community language labels Dec 6, 2020
@joshgoebel
Copy link
Member

joshgoebel commented Dec 6, 2020

Auto detection is best effort and not guaranteed. The problem is that is not a large enough sample to accurately determine the language.

For best results specify the language manually.

@joshgoebel joshgoebel added auto-detect Issue with auto detection of language type cantfix / wontfix Impossible to fix and removed bug help welcome Could use help from community language labels Dec 6, 2020
@step135
Copy link
Author

step135 commented Dec 9, 2020

Should your reaction be understood that you don't care about this feature anymore?

@joshgoebel
Copy link
Member

Not at all. Read CHANGES.md. We make improvements to auto-detect regularly. It's a key differentiating feature, but it is not magic. At best it's accurate 80-90% of the time when given a large enough snippets of text (and when the languages used for auto-detect are scoped narrowly). Using only a few languages will have better results than using the default web build, but even that will have better results than just loading the whole library (and all languages) via Node, etc.

What you are seeing here (with this small JS snippet) is merely the limits of the existing auto-detect system - not a "bug" (ie there is nothing immediately to "fix"), which is what my original response tried to state clearly and directly.

If every issue like this was left open we'd just have a forum full of "hey auto-detect doesn't work on my small snippet".

Context:
#1213

@joshgoebel
Copy link
Member

For many use cases where it's hard or impossible to manually identify the code snippet auto-detect can be quite useful even when making a "best guess"... and sometimes that doesn't work well at all... that's par for the course.

If you have experience with such things and think you could help improve them, we're all ears, but it's a non-trivial problem. Also auto-detect is not our -primary- use case - that is highlighting.

@joshgoebel
Copy link
Member

joshgoebel commented Dec 10, 2020

It's also possible there may be room for a docfix here (to clarify that auto-detect is not magic), though this issue doesn't come up so commonly anymore.

CC @allejo @egor-rogov

@allejo
Copy link
Member

allejo commented Dec 13, 2020

I do have a warning in highlight.php about autodetection not being magic. I don't think there'd be any harm in making that clear in highlight.js

@joshgoebel
Copy link
Member

I'd be fine with some verbiage along those lines somewhere in the readme. :) @step135 Would that have helped you though? I always wonder about just adding things to the README how many people actually read it. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-detect Issue with auto detection of language type cantfix / wontfix Impossible to fix
Projects
None yet
Development

No branches or pull requests

3 participants