Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C syntax highlighting doesn't work #124

thebaer opened this issue Jun 17, 2019 · 2 comments

C syntax highlighting doesn't work #124

thebaer opened this issue Jun 17, 2019 · 2 comments


Copy link

thebaer commented Jun 17, 2019

Describe the bug

We're using a stripped-down version of the highlight.js library that doesn't include the needed code to do C syntax highlighting, and the right library isn't being dynamically loaded.

Notice that there is no c.min.js file in static/js/highlightjs/, so a WriteFreely post like this attempts to load it, but fails.


Instead of loading c.min.js when we encounter a code block labeled as c, we should load cpp.min.js. It lists c as an alias (among others, which we should probably do the same for):

aliases: ['c', 'cc', 'h', 'c++', 'h++', 'hpp', 'hh', 'hxx', 'cxx'],

(from cpp.js)

Application configuration

  • Single mode or Multi-user mode? either
  • Database? any
  • Open registration? any
  • Federation enabled? any

Version or last commit: v0.9.1

@thebaer thebaer added this to the 0.10 milestone Jun 17, 2019
Copy link

mrvdb commented Jun 19, 2019

For the instance I have local quick patch in place just for this:

diff --git a/templates/include/post-render.tmpl b/templates/include/post-render.tmpl
index b0e8582..6b5f6a7 100644
--- a/templates/include/post-render.tmpl
+++ b/templates/include/post-render.tmpl
@@ -9,10 +9,20 @@
     // Set langs to the langs that are included by default (for now: 'common set' on CDN)
     var langs = [];
+    // Custom aliasmap
+    var aliasmap = {
+      'elisp' :'lisp','emacs-lisp': 'lisp',
+      'sh' :  'bash'};
     // Given a set of nodes, run highlighting on them
     function highlight(nodes) {
       for (i=0; i < nodes.length; i++) {
-          hljs.highlightBlock(nodes[i]);
+       lang = nodes[i].className.replace('language-','');
+       if (aliasmap[lang]) {
+         lo = hljs.getLanguage(aliasmap[lang]);
+         hljs.registerLanguage(lang, function() {return lo;});
+        }
+        hljs.highlightBlock(nodes[i]);
@@ -46,12 +56,16 @@
       // Check what we need to load
       for (i=0; i < lb.length; i++) {
         lang = lb[i].className.replace('language-','');
+       // Support a couple specific aliases
+       if(aliasmap[lang]) lang = aliasmap[lang];
         lurl = hlbaseUri + "highlightjs/" + lang + ".min.js";
         if (!(langs.includes(lang) || jss.includes(lurl))) {

Copy link
Member Author

thebaer commented Jun 19, 2019

Oh awesome. Would you mind opening a pull request with that patch? And either including the C aliases or leaving that for us to tackle?

thebaer added a commit that referenced this issue Jun 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

No branches or pull requests

2 participants