Highlightjs offers “auto highlighting” out of the box. It’d be nice if this functionality could be exposed to Discourse through an admin pref (eg. “Auto highlight preformatted code”). I understand this won’t be relevant for all forums but for some forums (such as the one I manage) it is highly preferable.
we are using the custom
Can you show us an example of where and when it doesn’t work but it does with the library outside of discourse? Then I’d gladly debug it, otherwise I’d say the request needs to go to highlightjs …
So far all the code that was inserted using the “Preformatted text” button in the editor has appeared without highlighting on our forums.
An example snippet that I had to manually edit to add the tripple quotes and language definition:
var sm = ko.views.manager.currentView.scimoz; // Get character length: var msg = "Length: " + sm.getTextRange(0, sm.currentPos).length; // Get byte length: //var msg = "Length: " + sm.currentPos; // Use statusbar to show where you are: ko.statusBar.AddMessage(msg, "find", 5000, true);
Seems to not be working here either? Of course I can manually add the tripple quotes and language definition but the point is that this should happen automatically when using the “Preformatted text” button.
Thanks, I’ll look into it. Maybe it’s something we do before we give it to highlightjs …
I don’t think a system setting is needed for this. I don’t see why it shouldn’t always kick in. Made a pull-request fixing your issue:
This is incorrect – we don’t want preformatted text to be syntax highlighted by default.
If are posting code, use a code fence.
This should be behind a site setting at a bare minimum – most communities do not care about source code at all, but will find uses for fixed-width font areas…
Right that’s what I figured. I’d still like it to be behind a setting though so that for my community (and other communities like it) it can default to code highlighting, as this is highly preferable given the subject of the community that I manage.
As long as it is behind a site setting that is fine @lightyear. Default off.
Superseeded. Now with SiteSettings:
I’d still argue that syntactically speaking the viewer shall be allowed to assume that anything inside
<pre> <code>...</code> </pre> to be code. I’d say this is a bug in the renderer (compatible markdown) spitting out code-block where there shall not be one.
Update: of yeah, of course. Default is ‘off’ – the normal behaviour.
Is there a general rule on which languages are supported by Discourse?
Highlight.js shipped with Discourse recognises only a small subset of all supported languages.
I see that highlighting of Go code was added just recently. Personally, I miss TeX, Haskell, Lua, Groovy and Erlang.
Is it feasible to include highlight,js build with more languages by default?
I understand that for most of communities most of uncommon languages are irrelevant and shipping smaller library helps with performance. But how can I add missing language to my instance?
What would be the best way to solve this?
As a quick hack I added missing languages with this small addition to