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.
This commit is contained in:
Joffrey JAFFEUX
2020-09-02 21:32:57 +02:00
committed by GitHub
parent 6a837c32e4
commit de038c0eab
4 changed files with 24 additions and 8 deletions

View File

@ -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