Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

7
  • This may be a nooby question, but why can't we choose which highlighter we want for the question? Sometimes highlight.js is better, and sometimes Prettify is better. Why can't we just choose which one instead of having SO choose it for us?
    – 10 Rep
    Commented Sep 30, 2020 at 16:55
  • 6
    Highlighters require a significant amount of code. Allowing both would somewhat increase overall bundle size (which is an issue for those with bad connections). It'd also add another layer of programming (adding toggling options, and adding / removing the different highlighters' formatting dynamically) and would introduce potential confusion to the already-complicated process of how to ask and answer good questions. IMO, using a single well-maintained library instead makes things much simpler. Commented Sep 30, 2020 at 17:04
  • 4
    Aside from language detection, I think a lot of the issues we're having with highlight.js are simply manifestations of users being resistant to change, as most of us are. I'm hopeful it'll grow on us. Commented Sep 30, 2020 at 17:05
  • I'm happy to add this smarter support to my Chrome extension if someone wants to figure out the FULL tag -> hint table for me (ie, the list of which tags auto-hint to which languages)... it's probably not that hard (a script snippet could probably do it with fetch in the browser console, etc?). github.com/joshgoebel/se_highlightjs/issues/3 Commented Oct 29, 2020 at 12:15
  • result relevance is unexpectedly low; perhaps question is mistagged Ah I just looked at what you are doing more closely... that's interesting. I was imagining that the tags auto-hints (xml, java, html in your first example) would simply be used as a boost or force multiplier (rather than exclusively). So we'd analyze everything as usual but then the html, java, and xml scores would get say a 50% boost (to boost them above any noise). Though I suppose you could still use either strategy after-the-fact, just with a small amount of extra CPU burn. Commented Oct 29, 2020 at 19:32
  • @CertainPerformance If you have any thoughts I'd love to hear them. github.com/highlightjs/highlight.js/issues/2768 This is what I was thinking of for an auto-detect/classification plugin API. There is no way to do exactly what you're doing here (saving a few CPU cycles), but you could accomplish the exact same result with analysis in a after callback... Logic: Did any of the auto-hinted languages score > 3? If so, return just those results, else: return the all results. Your idea would shrink to several lines of very simple JS. Commented Oct 29, 2020 at 19:48
  • 1