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

Closed
thebaer opened this issue Jun 17, 2019 · 2 comments
Closed

C syntax highlighting doesn't work #124

thebaer opened this issue Jun 17, 2019 · 2 comments
Milestone

Comments

@thebaer
Copy link
Member

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

Solution

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

This comment has been minimized.

Copy link
Collaborator

@mrvdb mrvdb commented Jun 19, 2019

For the https://qua.name 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))) {
           jss.push(lurl);
         }
       }
@thebaer

This comment has been minimized.

Copy link
Member Author

@thebaer 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 thebaer closed this in c2d7c2c Jun 27, 2019
thebaer added a commit that referenced this issue Jun 27, 2019
Fix #124 according to the snippet by @mrvdb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.