When assigning a language to code blocks, I often use js to mean javascript . This is not recognised by the markdown engine(?) these forums use, so I am forced to go back and replace it with javascript . Having js as an alias would help a lot, especially as it is valid in other markdown places (like GitHub).
It’s also fairly unambiguous, as JavaScript is almost always shortened to JS when the name will be used frequently.
Pretty sure the syntax is specified by highlight.js, not markdown. Per How to use highlight.js you need to specify the language, which the library calls javascript, not js.
FWIW, I’ve made the same mistake with C++. I thought it would be c++, not cpp
Thanks for the pointer. I followed the link, and it says
The list of supported language classes is available in the class reference
The class reference it links to has a table of supported languages, and recognised keywords to select each one. I believe the “bottleneck” is happening on the discourse side, where it’s only passing a limited subset of language keywords to Highlight.JS.
In fact, it would be great if all the supported keywords were allowed, as some look quite interesting.
FYI, it has js for JavaScript, and c++ for C++. So I think this is definitely worth looking into.
Ooh, interesting. Perhaps we only pull the first alias for each language? An engineer would know more.
It is intentional that we do not. Including all languages affected performance. Admins can configure the highlighted languages on their site via the highlighted languages site setting. I’ve included the languages that are enabled here on Meta for you below:
You’ll need to wait for one of the engineers to see this (we track issues here, they’re disabled on Github) Keep in mind it’s late Friday (or even Saturday) for most of the team, so this may not be seen until Monday.
I don’t think the auto highlighting is working then. Even on this site, observe the following
No language name:
let x = 10;
function root(n) {
return Math.sqrt(n);
}
console.log(root(x));
javascript as language name:
let x = 10;
function root(n) {
return Math.sqrt(n);
}
console.log(root(x));
There is a difference in appearance, indicating a different set of rules is being applied (even though both are identical JavaScript). And it’s not just these two language that would benefit from allowing synonyms; there are quite a few that offer alternative naming.
It appears to be due to some rules trying to undo certain highlighting on Javascript. It’s different because the top is marked as hljs javascript versus the second which is lang-javascript hljs.
I originally posted this on the Atom forums, and was directed here. Atom package development is heavily JS orientated, but also has a lot of CoffeeScript (that’s in the process of being phased out).
Oh why not suggest they make the change to default code lang to javascript? That is the vast majority of code pasted in anyway (and you can override per snippet where needed)
Also they could cut down on the languages supported to make auto detection more reliable.
One minor issue with making js a shortcut for javascript is that I would assume you would also want cs to be shore for coffeescript but that would clash with c sharp.
I believe coffee is the normal shortcut for CoffeeScript (probably for that reason). Additionally, the Highlight.JS docs I linked to still consider cs to be C#.
I don’t know anything about the internals here, and didn’t understand the workaround that was supplied above (I assume any maintainer would though), but I would have thought just adding js and c++ to the list of languages passed to Highlight.JS would work. No special handling should be needed, as the docs list them as recognised aliases.