FIX: highlightjs 10 requires some languages to be loaded before others (#10584)

FIX: highlightjs 10 requires some languages to be loaded before others (#10584)

cs is also not present in 10 and relies only on csharp file, but for cs alias to work csharp has to be loaded.

diff --git a/app/controllers/highlight_js_controller.rb b/app/controllers/highlight_js_controller.rb
index 583ba86..768c4e7 100644
--- a/app/controllers/highlight_js_controller.rb
+++ b/app/controllers/highlight_js_controller.rb
@@ -18,7 +18,20 @@ class HighlightJsController < ApplicationController
       # note, this can be slightly optimised by caching the bundled file, it cuts down on N reads
       # our nginx config caches this so in practical terms it does not really matter and keeps
       # code simpler
-      highlight_js = HighlightJs.bundle(SiteSetting.highlighted_languages.split("|"))
+      languages = SiteSetting.highlighted_languages.split('|')
+
+      # TODO: some languages require to be loaded before others
+      # this limitation should be fixed in highlight js 11, remove it when available
+      prepended_languages = ['csharp', 'c', 'c-like']
+      prepended_languages.each do |lang|
+        if languages.include?(lang)
+          languages.insert(0, languages.delete(lang))
+        else
+          languages.insert(0, lang)
+        end
+      end
+
+      highlight_js = HighlightJs.bundle(languages)
 
       response.headers["Last-Modified"] = 10.years.ago.httpdate
       response.headers["Content-Length"] = highlight_js.bytesize.to_s
diff --git a/vendor/assets/javascripts/highlightjs/highlight-test-bundle.min.js b/vendor/assets/javascripts/highlightjs/highlight-test-bundle.min.js
index 34fb0a6..1a7b5a9 100644
--- a/vendor/assets/javascripts/highlightjs/highlight-test-bundle.min.js
+++ b/vendor/assets/javascripts/highlightjs/highlight-test-bundle.min.js
@@ -1,5 +1,9 @@
-/*! highlight.js v9.18.1 | BSD3 License | git.io/hljslicense */

[... diff too long, it was truncated ...]

GitHub sha: de038c0e

1 Like

This commit appears in #10584 which was approved by eviltrout. It was merged by jjaffeux.