mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
DEV: Add support for aliases in HighlightJS languages (#20380)
We were only supporting the main name of each HighlightJS language. So, by default, you could not use `js` or `jsx` to highlight Javascript, given they are aliases for `javascript`. This PR adds a list of aliases as a constant to core (built via a rake task), and then checks against the `highlighted_languages` site settings plus the list of aliases when processing a code block.
This commit is contained in:
@ -182,6 +182,32 @@ task "javascript:update_constants" => :environment do
|
||||
export const replacements = #{Emoji.unicode_replacements_json};
|
||||
JS
|
||||
|
||||
langs = []
|
||||
Dir
|
||||
.glob("vendor/assets/javascripts/highlightjs/languages/*.min.js")
|
||||
.each { |f| langs << File.basename(f, ".min.js") }
|
||||
bundle = HighlightJs.bundle(langs)
|
||||
|
||||
ctx = MiniRacer::Context.new
|
||||
hljs_aliases = ctx.eval(<<~JS)
|
||||
#{bundle}
|
||||
|
||||
let aliases = {};
|
||||
hljs.listLanguages().forEach((lang) => {
|
||||
if (hljs.getLanguage(lang).aliases) {
|
||||
aliases[lang] = hljs.getLanguage(lang).aliases;
|
||||
}
|
||||
});
|
||||
|
||||
aliases;
|
||||
JS
|
||||
|
||||
write_template("pretty-text/addon/highlightjs-aliases.js", task_name, <<~JS)
|
||||
export const HLJS_ALIASES = #{hljs_aliases.to_json};
|
||||
JS
|
||||
|
||||
ctx.dispose
|
||||
|
||||
write_template("pretty-text/addon/emoji/version.js", task_name, <<~JS)
|
||||
export const IMAGE_VERSION = "#{Emoji::EMOJI_VERSION}";
|
||||
JS
|
||||
|
Reference in New Issue
Block a user