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.

11
  • Does it work on CSS? The Google Prettify highlighter has always had trouble recognizing CSS. Commented Sep 21, 2020 at 23:49
  • @user289905 It works only for languages specified with lang-XXX. Shouldn't be required for CSS, though, because that's already eager-loaded by default. Commented Sep 22, 2020 at 8:02
  • When I run this I just end up with a whole bunch of console warnings and no visible effect: Could not find the language '_____', did you forget to load/include a language module?, fill in the blank with none, assembly, diff, elixir, and bf.
    – zcoop98
    Commented Sep 22, 2020 at 22:54
  • The concept is surely nice however, I really like the idea of being able to run a script user side that would highlight more languages.
    – zcoop98
    Commented Sep 22, 2020 at 22:55
  • @zcoop98 Those warnings are generated when hljs does its initial pass, not when the userscript runs. I've amended it to run on the load event for the original hljs script (which is itself loaded dynamically), but this still doesn't suppress the warnings. Can you confirm you're seeing no color at all on these code blocks after running the script? It's a little difficult to see at the moment, especially for the Elixir example, due to the hljs color scheme. Commented Sep 23, 2020 at 9:12
  • 1
    @LionelRowe I can see colors now!
    – zcoop98
    Commented Sep 23, 2020 at 15:01
  • 1
    Fixed to work with the latest update - the eagerly loaded run now highlights unknown but specified languages with what I assume is a best-guess attempt? Anyway, v0.4 of the user-script will now override these. Commented Sep 25, 2020 at 20:02
  • 1
    @LionelRowe This is awesome. Don't think you can suppress the warnings since you probably have no way to load and change anything BEFORE Highlight.js makes it's first pass... but they aren't really causing any harm either. Commented Oct 18, 2020 at 2:38
  • @LionelRowe Why is MutationObserver necessary? Commented Oct 28, 2020 at 3:46
  • @JoshGoebel At least when I made this, the hljs script was not present at the time DOMContentLoaded was fired, necessitating the MutationObserver. I left the 3 conditions at the bottom in case the means of loading was changed. Commented Oct 28, 2020 at 7:54
  • 1
    @LionelRowe Here is a proof of concept Chrome extension: github.com/joshgoebel/se_highlightjs :-) Nice thing about an extension is you can bundle the files, no need for any CDN or external fetches at all. Commented Oct 29, 2020 at 0:15